> For the complete documentation index, see [llms.txt](https://shanshan-huang-1.gitbook.io/pyql-wen-dang/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://shanshan-huang-1.gitbook.io/pyql-wen-dang/introduction-of-pyql.md).

# Introduction of PyQL

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: $${c\_{1},c\_{2}, ..., c\_{n}}$$, where $$c\_{i}$$ either initializes a PyQL object or calls a function on the object.&#x20;

```python
# initializes a PyQL object
a=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 x2
a.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.

<figure><img src="/files/wiLwaHWA1zAQb9KxbaJg" alt=""><figcaption></figcaption></figure>
