fcsql.parser
- fcsql.parser.OCCURS_UNBOUNDED = -1
Atom occurrence if not bound.
- class fcsql.parser.QueryNodeType(value)[source]
Node types of FCS-QL expression tree nodes.
- QUERY_SEGMENT = 'QuerySegment'
Segment query.
- QUERY_GROUP = 'QueryGroup'
Group query.
- QUERY_SEQUENCE = 'QuerySequence'
Sequence query.
- QUERY_DISJUNCTION = 'QueryDisjunction'
Or query.
- QUERY_WITH_WITHIN = 'QueryWithWithin'
Query with within part.
- EXPRESSION = 'Expression'
Simple expression.
- EXPRESSION_WILDCARD = 'Wildcard'
Wildcard expression.
- EXPRESSION_GROUP = 'Group'
Group expression.
- EXPRESSION_OR = 'Or'
Or expression.
- EXPRESSION_AND = 'And'
And expression.
- EXPRESSION_NOT = 'Not'
Not expression.
- SIMPLE_WITHIN = 'SimpleWithin'
Simple within part.
- class fcsql.parser.Operator(value)[source]
FCS-QL operators.
- EQUALS = 'Eq'
EQUALS operator.
- NOT_EQUALS = 'Ne'
NOT-EQUALS operator.
- class fcsql.parser.RegexFlag(value)[source]
FCS-QL expression tree regex flags.
- CASE_INSENSITIVE = 'case-insensitive'
Case insensitive.
- CASE_SENSITIVE = 'case-sensitive'
Case sensitive.
- LITERAL_MATCHING = 'literal-matching'
match exactly (= literally)
- IGNORE_DIACRITICS = 'ignore-diacritics'
Ignore all diacritics.
- class fcsql.parser.SimpleWithinScope(value)[source]
The within scope.
- SENTENCE = 'Sentence'
sentence scope (small)
- UTTERANCE = 'Utterance'
utterance scope (small)
- PARAGRAPH = 'Paragraph'
paragraph scope (medium)
- TURN = 'Turn'
turn scope (medium)
- TEXT = 'Text'
text scope (large)
- SESSION = 'Session'
session scope (large)
- class fcsql.parser.QueryVisitor[source]
Interface implementing a Visitor pattern for FCS-QL expression trees.
Default method implementations do nothing.
- class fcsql.parser.QueryNode(node_type: QueryNodeType, children: List[QueryNode] | None = None, child: QueryNode | None = None)[source]
Base class for FCS-QL expression tree nodes.
[Constructor]
- Parameters:
node_type – the type of the node
children – the children of this node or
None
. Defaults to None.child – the child of this node or
None
. Defaults to None.
- node_type
The node type of this node.
- children
The children of this node.
- has_node_type(node_type: QueryNodeType) bool [source]
Check, if node if of given type.
- Parameters:
node_type – type to check against
- Returns:
bool –
True
if node is of given type,False
otherwise- Raises:
TypeError – if node_type is
None
- property child_count: int
Get the number of children of this node.
- Returns:
int – the number of children of this node
- get_child(idx: int, clazz: Type[_T] | None = None) QueryNode | None [source]
Get a child node of specified type by index.
When supplied with
clazz
parameter, only child nodes of the requested type are counted.- Parameters:
idx – the index of the child node (if clazz provided, only consideres child nodes of requested type)
clazz – the type to nodes to be considered, optional
- Returns:
QueryNode – the child node of this node or
None
if not child was found (e.g. type mismatch or index out of bounds)
- get_first_child(clazz: Type[_T] | None = None) QueryNode | None [source]
Get this first child node.
- Parameters:
clazz – the type to nodes to be considered
- Returns:
QueryNode – the first child node of this node or
None
- get_last_child(clazz: Type[_T] | None = None) QueryNode | None [source]
Get this last child node.
- Parameters:
clazz – the type to nodes to be considered
- Returns:
QueryNode – the last child node of this node or
None
- abstract accept(visitor: QueryVisitor) None [source]
- class fcsql.parser.Expression(qualifier: str | None, identifier: str, operator: Operator, regex: str, regex_flags: Set[RegexFlag] | None)[source]
A FCS-QL expression tree SIMPLE expression node.
[Constructor]
- Parameters:
qualifier – the layer identifier qualifier or
None
identifier – the layer identifier
operator – the operator
regex – the regular expression
regex_flags – the regular expression flags or
None
- qualifier
The Layer Type Identifier qualifier.
None
if not used in this expression.
- identifier
The layer identifier.
- operator
The operator.
- regex
The regex value.
- regex_flags
The regex flags set.
None
if no flags were used in this expression.
- has_layer_identifier(identifier: str) bool [source]
Check if the expression used a given Layer Type Identifier.
- Parameters:
identifier – the Layer Type Identifier to check against
- Returns:
bool –
True
if this identifier was used,False
otherwise- Raises:
TypeError – if identifier is
None
- is_layer_qualifier_empty() bool [source]
Check if the Layer Type Identifier qualifier is empty.
- Returns:
bool –
True
if no Layer Type Identifier qualifier was set,False
otherwise
- has_layer_qualifier(qualifier: str) bool [source]
Check if the expression used a given qualifier for the Layer Type Identifier.
- Parameters:
qualifier – the qualifier to check against
- Returns:
bool –
True
if this identifier was used,False
otherwise- Raises:
TypeError – if qualifier is
None
- has_operator(operator: Operator) bool [source]
Check if expression used a given operator.
- Parameters:
operator – the operator to check
- Returns:
bool –
True
if the given operator was used,False
otherwise- Raises:
TypeError – if operator is
None
- is_regex_flags_empty() bool [source]
Check if a regex flag set is empty.
- Returns:
bool –
True
if no regex flags where set,False
otherwise
- has_regex_flag(flag: RegexFlag) bool [source]
Check if a regex flag is set.
- Parameters:
flag – the flag to be checked
- Returns:
bool –
True
if the flag is set,False
otherwise- Raises:
TypeError – if flag is
None
- accept(visitor: QueryVisitor) None [source]
- class fcsql.parser.ExpressionWildcard(children: List[QueryNode] | None = None, child: QueryNode | None = None)[source]
A FCS-QL expression tree WILDCARD expression node.
[Constructor]
- Parameters:
node_type – the type of the node
children – the children of this node or
None
. Defaults to None.child – the child of this node or
None
. Defaults to None.
- accept(visitor: QueryVisitor) None [source]
- class fcsql.parser.ExpressionGroup(child: QueryNode)[source]
A FCS-QL expression tree GROUP expression node.
[Constructor]
- Parameters:
child – the group content
- accept(visitor: QueryVisitor) None [source]
- class fcsql.parser.ExpressionNot(child: QueryNode)[source]
A FCS-QL expression tree NOT expression node.
[Constructor]
- Parameters:
child – the child expression
- accept(visitor: QueryVisitor) None [source]
- class fcsql.parser.ExpressionAnd(children: List[QueryNode])[source]
A FCS-QL expression tree AND expression node.
[Constructor]
- Parameters:
children – child elements covered by AND expression.
- property operands: List[QueryNode]
Get the AND expression operands.
- Returns:
List[QueryNode] – a list of expressions
- accept(visitor: QueryVisitor) None [source]
- class fcsql.parser.ExpressionOr(children: List[QueryNode])[source]
A FCS-QL expression tree OR expression node.
[Constructor]
- Parameters:
children – child elements covered by OR expression.
- property operands: List[QueryNode]
Get the OR expression operands.
- Returns:
List[QueryNode] – a list of expressions
- accept(visitor: QueryVisitor) None [source]
- class fcsql.parser.QueryDisjunction(children: List[QueryNode])[source]
A FCS-QL expression tree QR query.
[Constructor]
- Parameters:
children – the children
- accept(visitor: QueryVisitor) None [source]
- class fcsql.parser.QuerySequence(children: List[QueryNode])[source]
A FCS-QL expression tree query sequence node.
[Constructor]
- Parameters:
children – the children for this node
- accept(visitor: QueryVisitor) None [source]
- class fcsql.parser.QueryWithWithin(query: QueryNode, within: QueryNode | None)[source]
FCS-QL expression tree QUERY-WITH-WITHIN node.
[Constructor]
- Parameters:
query – the query node
within – the within node
- get_within() QueryNode | None [source]
Get the within clause (= search context)
- Returns:
QueryNode – the witin clause
- accept(visitor: QueryVisitor) None [source]
- class fcsql.parser.QuerySegment(expression: QueryNode, min_occurs: int, max_occurs: int)[source]
A FCS-QL expression tree query segment node.
[Constructor]
- Parameters:
expression – the expression
min_occurs – the minimum occurrence
max_occurs – the maximum occurrence
- min_occurs
The minimum occurrence of this segment.
- max_occurs
The maximum occurrence of this segment.
- get_expression() QueryNode [source]
Get the expression for this segment.
- Returns:
QueryNode – the expression
- accept(visitor: QueryVisitor) None [source]
- class fcsql.parser.QueryGroup(child: QueryNode, min_occurs: int, max_occurs: int)[source]
A FCS-QL expression tree GROUP query node.
[Constructor]
- Parameters:
child – the child
min_occurs – the minimum occurrence
max_occurs – the maximum occurrence
- min_occurs
The minimum occurrence of group content.
- max_occurs
The maximum occurrence of group content.
- get_content() QueryNode [source]
Get the group content.
- Returns:
QueryNode – the content of the GROUP query
- accept(visitor: QueryVisitor) None [source]
- class fcsql.parser.SimpleWithin(scope: SimpleWithinScope)[source]
A FCS-QL expression tree SIMPLE WITHIN query node.
[Constructor]
- Parameters:
node_type – the type of the node
children – the children of this node or
None
. Defaults to None.child – the child of this node or
None
. Defaults to None.
- scope
The simple within scope.
- accept(visitor: QueryVisitor) None [source]
- fcsql.parser.DEFAULT_UNICODE_NORMALIZATION_FORM = 'NFC'
Default unicode normalization form.
See also: unicodedata.normalize
- class fcsql.parser.ExpressionTreeBuilder(parser: QueryParser)[source]
- class fcsql.parser.QueryParser(default_identifier: str = 'text', default_operator: Operator = Operator.EQUALS, unicode_normalization_form: str | None = 'NFC')[source]
A FCS-QL query parser that produces FCS-QL expression trees.
[Constructor]
- Parameters:
default_identifier – the default identifier to be used for simple expressions. Defaults to DEFAULT_IDENTIFIER.
default_operator – the default operator. Defaults to DEFAULT_OPERATOR.
unicode_normalization_form – the Unicode normalization form to be used or
None
to not perform normlization. Defaults to DEFAULT_UNICODE_NORMALIZATION_FORM.
- parse(query: str) QueryNode [source]
Parse query.
- Parameters:
query – the raw FCS-QL query
- Raises:
QueryParserException – if an error occurred
- Returns:
QueryNode – a FCS-QL expression tree