You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

Feature compatible only with Saga 1.3+ responses

PyQPL allows you to work with responses from Saga, enabling you to convert LexItems into synonyms, QPL keywords, and more complex query structures. By leveraging the capabilities of Saga, including the ability to maintain, configure, and tune dictionaries for entity extraction, PyQPL with Saga provides a powerful tool for creating  queries with mutable syntax and enhanced capabilities.


Saga QPL Options

The SagaQPLOptions allow you to specify tags to be transformed into QPL (Query Processing Language) structures in Saga. These options enable features such as synonym expansion, QPL keyword replacement, and complex QPL structures using saga_special_cases.
FieldTypeRequiredDefaultDescriptionExamples

implicit_operator

Literal['or', 'and']

(error)

or

Default operator to use when the relationship, between 2 operands is ambiguous

Applicable only to the parser



"or", "and"

fields

List[str] OR Dict[str, float]

OR List[QPLField] OR str

(tick)



Fields to be use when match term, phrases, spans, ...


In the string formats you can add the boots by adding ^ and the amount to boots, e.g. ^2 or ^0.5

As string:

"field"

As a List:

["field1", "field2^2", "field3^3"]

As a Dictionary:

{"field1": 1, "field2" : 2, "field3": 3.0}

as a List of QPLFields:

[{"name":"field1", "boost": 1}, {"name":"field2", "boost": 2}, {"name":"field3", "boost": 3}]

date_fields

List[str] OR Dict[str, float]

OR List[QPLField] OR str

(error)

[ ]

Fields to be use when date ranges, if no range queries are 


In the string formats you can add the boots by adding ^ and the amount to boots, e.g. ^2 or ^0.5

As string:

"field"

As a List:

["field1", "field2^2", "field3^3"]

As a Dictionary:

{"field1": 1, "field2" : 2, "field3": 3.0}

as a List of QPLFields:

[{"name":"field1", "boost": 1}, {"name":"field2", "boost": 2}, {"name":"field3", "boost": 3}]

range_fields

List[str] OR Dict[str, float]

OR List[QPLField] OR str

(error)

[ ]

Fields to be use when ranges


In the string formats you can add the boots by adding ^ and the amount to boots, e.g. ^2 or ^0.5

As string:

"field"

As a List:

["field1", "field2^2", "field3^3"]

As a Dictionary:

{"field1": 1, "field2" : 2, "field3": 3.0}

as a List of QPLFields:

[{"name":"field1", "boost": 1}, {"name":"field2", "boost": 2}, {"name":"field3", "boost": 3}]

date_format

str

(error)


Date format used to convert date values in the query. 

The format to use must be compatible with the engine specific query




timezone

str

(error)


Coordinated Universal Time (UTC) offset or IANA time zone used to convert date values in the query to UTC.

The timezone to use must be compatible with the engine specific query




slop_near

number

(error)

10

Slop value used for the NEAR operator


slop_before

number

(error)

2

Slop value used for the BEFORE operator


slop_adj

number

(error)

0

Slop value used for the ADJ operator


slop_span_not

number

(error)

0

Slop value used for the SPAN NOT operator


wildcard

bool

(error)

False

Use wildcard operators

Applicable only to the parser




grammar

File Path Or str

(error)


File path to the grammar or the actual raw grammar in string, in case you need to parse text to QPL with custom operators. QPL parser uses a Lalr parser implemented with Lark library, for more information check https://lark-parser.readthedocs.io/en/latest/grammar.html#


We recommend that before starting to make a new grammar, consult with the development team

Applicable only to the parser



For more detail on how to build a grammar please check Grammar Composition from the Lark documentation

custom_operators

Dict[str, Operand]

(error)

{}

Dictionary with the name type of the custom operator as keys, and the class with their logic as values. All classes must inherit from Operator

Applicable only to the parser



A more detailed use of the custom operators can be found on Custom Operator page



synonyms_call

Func[]

(error)


Function returning requested synonyms for the specified string

Applicable only to the parser



A more detailed use of the synonym expansion can be found on Synonym Expansion page



saga_keywords

List[str]

(error)

[]

Saga tags to be normalize as QPL keywords. The display of the tag will use to replace the tag.
Example: "This {tag} here", where {tag}'s display is OR, will be normalized to "This OR here".


saga_synonyms

List[str]

(error)

[]

Saga tags marked as synonyms, For each entity in the matched tag, the list of patterns within the entity, will be used as the synonyms to replace the matched text.


saga_synonyms_boost

float

(error)

0.8

Boots to be used on each synonym added to the query.


saga_special_case

Dict[str, Callable[LexItem, str]

(error)

{}

Dictionary with tags as per keys, where each key has a function assigned, which will receive a LexItem and transformed it into a suitable query statement.


Keyword Replacement

The keyword replacement


  • No labels