> 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>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://shanshan-huang-1.gitbook.io/pyql-wen-dang/introduction-of-pyql.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
