PyQL (Pythonic Query Language for SPARQL), a logical form written in Python as a reasoning step representation for numerical reasoning question(NRQ).
PyQL encapsulates various SPARQL syntax elements, such as Basic Graph Patterns, Assignments, Filters, Aggregations, and Subqueries.
A PyQL is a sequence of commands: {c1,c2,...,cn}, where ci either initializes a PyQL object or calls a function on the object.
# initializes a PyQL objecta=PyQL()# call a function to add type constrain a.add_type_constrain('Q7325635', 'x1')# get the value of a quantity property of x1. This value will be saved in x2.a.add_quantity('x1','P4176','x2')# filter the value of x2a.add_filter('x2','>',6000)# get the value of a quantity property of x1. This value will be saved in x3.a.add_quantity('x1','P2052','x3')# get the average value among all the values of variable x3. The average value will be saved in x4.a.add_avg('x3','x4')
When write a PyQL, you need to first initialize a PyQL object and sequentially add functions to construct the whole query.
Each function represents a reasoning step such as stating the relation between two entities or computing the average.
A valid PyQL can directly generate an executable SPARQL query.