API Document
Basic graph pattern
add_fact
add_fact(self, s, p, o, p_prefix)
Add a <s, p, o, prefix> triple to the query.
Parameters:
s(str): the subject of the triple
p(str): the predicate of the triple
o(str): the object of the triple
p_prefix(str): the prefix of predicate
example:
Question:
What is the manufacturer of 2T Stalker
Program:
a=PyQL()
a.add_fact('Q222823', 'P176', 'x0' ,'wdt')SPARQL:
add_quantity
add_quantity(entity, prop, tag,time=False)
This function is used to acquire the value of a quantity property.
Parameters:
entity(str): the entity
prop(str): the quantity property you need to get
tag(str): An identifier used to name variables. Ultimately the variable with the property value of this quantity property is the tag.
time(int/boolean/str): The constraint of time.
int: Limit the time to this year.
boolean: True means need to acquire the time,False means not need to acquire the time.
str: use the function to_date to set the entire yyyy-mm-dd
example:
Question:
What is the GDP of French economy in the year 2007
Program:
SPARQL:
add_quantity_by_qualifier
add_quantity_by_qualifier(self,entity,main_prop,main_obj,qualifier_prop,tag)
Acquire the value of a quantity property which acts as a qualifier.
For example, the entity iPhone 12 has a property 'made from material' of which the value can be steel, glass and so on. The property mass is the qualifier for each material.
Parameters:
entity(str): the entity, such as iPhone12
main_prop(str): the property of the statement, such as made from material
main_obj(str): the value of the main_prop, such as steel.
qualifier_prop(str): the quantity property which acts as a qualifier. For example, mass.
tag(str): An identifier used to name variables. Ultimately the variable with the property value of this quantity property is the tag.
example:
Question:
What is the duration of Soyuz MS-21's time on the moon
Program:
SPARQL:
add_quantity_with_qualifier
add_quantity_with_qualifier(self,entity,main_prop,qualifier_prop,qualifier_obj,tag)
Acquire the value of a quantity property with a qualifire limiting other peoperties
For example, the computer performance of Nvidia GeForce RTX 3090 has 4 statements which are limited by the qualifier uses. Their qualifier values are single-precision floating-point format, half-precision floating-point format, double-precision floating-point format and half-precision floating-point format seperately.
Parameters:
entity(str): the entity, such as Nvidia GeForce RTX 3090
main_prop(str): the quantity property of the statement, such as computer performance
qualifier_prop(str): the property which acts as a qualifier, such as uses
qualifier_obj(str): the value of qualifier property, such as single-precision floating-point format.
tag(str): An identifier used to name variables. Ultimately the variable with the property value of this quantity property is the tag.
example:
Question:
What is the solubility of Dihydrogen disulfide in water
Program:
SPARQL:
add_type_constrain
add_type_constrain(self, type_id, new_var)
add a type constraint to a variable
Parameters:
type_id(str): ID of the type
new_var(str): the entity to be constrained
example:
Question: Get all the Pan Am Games.
Program:
SPARQL:
add_filter
add_filter(self, compare_obj1, operator, compare_obj2)
Given two comarison variables and an operator, add a filter.
Parameters:
compare_obj1(str): comparison variable 1
operator(str): operator
compare_obj2(str): comparison variable 2
example:
Question:
Get all the Pan Am Games held after 2001 (not including 2001).
Program:
SPARQL:
add_bind
add_bind(self, equation, var_name)
add a bind expression to assign the result of the expression equation to the variable var_name.
Parameters:
equation(str): The expression to be binded. Bracket is not necessary. It will be added automatically.
var_name(str): The expression will be assigned to this variable.
example:
Question:
What is the number of deaths and injuried individuals in Atlanta spa shootings?
Program:
SPARQL:
add_assignment
add_assignment(self,var_list,new_var)
add a values clause to generate a new variable new var of which the value includes all entities in var_list.
Parameters:
equation(list): an entities list, such as ['Q123', 'Q186']
new_var(str): the new variable
example:
Question:
Among BMW N57 and Renault E-Type engine, who has the highest compression ratio?
Program:
SPARQL:
add_sub_query
add_sub_query(self,*sub_query)
add a sub query to the sparql of this PyQL instance
Parameters:
sub_query(PyQL): the PyQL instance which needs to be added as a sub_query
example:
Question:
By how much is the average lowest air pressure of a category 5 hurricane lower than that of a category 3 hurricane?
Program:
SPARQL:
Aggreggation
add_max
add_max(self, max_obj, return_obj='*',offset=0,limit=1)
Calculate the maximum value of max_obj
Parameters:
max_obj(str): the variable of which the maximum value needs to be counted
return_obj(str): the variable to return. It can be *
offset(str): the number in offset. For example, to get the second biggest one, set offset=2
limit(str): the number in limit. For example, to get the three biggest one, set limit=3, offset=0
example:
Question:
Among BMW N57 and Renault E-Type engine, who has the highest compression ratio?
Program:
SPARQL:
add_min
add_min(self, min_obj, return_obj='*',offset=0,limit=1)
Calculate the minimum value of min_obj
Parameters:
max_obj(str): the variable of which the minimum value needs to be counted
return_obj(str): the variable to return. It can be *
offset(str): the number in offset. For example, to get the second smallest one, set offset=2
limit(str): the number in limit. For example, to get the three smallest one, set limit=3, offset=0
example:
Question: Among BMW N57 and Renault E-Type engine, who has the lowest compression ratio?
Program:
SPARQL:
add_avg
add_avg(self,avg_var, new_var, group_obj=None)
calculate the average value of variable avg_var. The parameter new_var is the variable of the calculated average value.
Parameters:
avg_var(str): the variable which needs to be averaged
new_var(str): the variable of the calculated average value
group_obj(str): the variable which needs to be put in a group by
example:
Question:
Among BMW N57 and Renault E-Type engine, what is the average compression ratio?
Program:
SPARQL:
add_sum
add_sum(self,sum_var, new_var, group_obj=None)
calculate the sum of the variable sum_var. The parameter new_var is the variable of the calculated sum value.
Parameters:
sum_var(str): the variable which needs to be summed
new_var(str): the variable of the calculated sum value
group_obj(str): the variable which needs to be put in a group by
example:
Question:
What are the female population of all the communes of France in 2017?
Program:
SPARQL:
add_count
add_count(self,count_obj,new_var, group_obj=None)
calculate the average value of variable count_obj. The parameter new_var is the variable of the calculated average value. It can only be used in the final step of a complete query or subquery. After use, either the entire query ends or it is treated as a subquery.
Parameters:
count_obj(str): the variable which needs to be counted
new_var(str): the variable of the calculated counting value
group_obj(str): the variable which needs to be put in a group by
example:
Question:
What is the number of all the communes of France?
Program:
SPARQL:
add_rank
add_rank(self, rank_var, var_list,new_var)
calculate the rank of rank_var's value among var_list
Parameters:
rank_var(str): the variable of which the rank needs to be calculated
var_list(str): the rank is calculated in this list which includes rank_var
new_var(str): the variable of the rank result
example:
Question:
What is Italy's population ranking among all the sovereign states in 2020?
Program:
SPARQL:
Boolean
add_compare
add_compare(self, obj1, op, obj2)
Determine whether obj1 and obj2 satisfies the size relationship represented by op. It can only be used in the final step of a complete query.
Parameters:
obj1(str): comparison variable 1
op(str): operator
obj2(str): comparison variable 2
example:
Question:
Is Italy's population more than France's population in 2020?
Program:
SPARQL:
Other
add_time
add_time(self, entity, new_var)
Get the point of time property of entity. It adds a triple <entity, wdt:P585, new_var>
Parameters:
entity(str): The entity whose point of time is needed.
new_var(str): The variable which represents the point of time value of the entity
example:
Question:
Get all the Pan Am Games held after 2001 (not including 2001).
Program:
SPARQL:
add_start_time
add_start_time(self, entity,new_var)
Get the start time property of entity. It adds a triple <entity, wdt:P580, new_var>
Parameters:
entity(str): The entity whose start time is needed.
new_var(str): The variable which represents the start time value of the entity
example:
Question:
What is the start time of Efficacy and Safety Study of Mongersen (GED-0301) for the Treatment of Subjects With Active Crohn's Disease?
Program:
SPARQL:
add_end_time
add_end_time(self, entity, new_var)
Get the end time property of entity. It adds a triple <entity, wdt:P582, new_var>
Parameters:
entity(str): The entity whose end time is needed.
new_var(str): The variable which represents the end time value of the entity
example:
Question:
What is the start time of Efficacy and Safety Study of Mongersen (GED-0301) for the Treatment of Subjects With Active Crohn's Disease?
Program:
SPARQL:
set_answer
set_answer(self,answer='*')
Set the return value of the final query. It can only be used at last.
Parameters:
answer(str): The return value of this query.
example:
Question:
What is the start time of Efficacy and Safety Study of Mongersen (GED-0301) for the Treatment of Subjects With Active Crohn's Disease?
Program:
SPARQL:
Arithmetic
These functions are used inside an add_bind. They are not member functions of PyQL class.
add
add(*para_list)
It creates an addition expression which adds up every element in para_list.
example:
Question:
What is the number of deaths and injuried individuals in Atlanta spa shootings?
Program:
SPARQL:
sub
sub(para1, para2)
It creates an subtraction expression of para1 subtacting para2.
example:
Question:
How much more is France's population than Italy's population in 2020?
Program:
SPARQL:
mul
mul(*para_list)
It creates an multiplication expression which multiplies every element in para_list.
example:
Question:
What is a half of the population of France in 2020?
Program:
SPARQL:
div
div(para1, para2)
It creates an division expression of para1 dividing para2.
example:
Question:
How many times the population of France is that of Italy in 2020?
Program:
SPARQL:
abs
abs(para)
It creates an expression which is abs(para)
example:
Question:
What is the difference between Italy's population and France's population in 2020?
Program:
SPARQL:
Last updated