owlapy.parser.DLSyntaxParser

class owlapy.parser.DLSyntaxParser(namespace: Optional[Union[str, owlapy.namespaces.Namespaces]] = None, grammar=None)[source]

Bases: parsimonious.nodes.NodeVisitor, owlapy.io.OWLObjectParser

Description Logic Syntax parser to parse strings to OWLClassExpressions

Create a new Description Logic Syntax parser. Names (entities) can be given as full IRIs enclosed in < and >

or as simple strings, in that case the namespace attribute of the parser has to be set to resolve them. Prefixes are currently not supported, except for datatypes.

Parameters:
  • namespace – Namespace to resolve names that were given without one

  • grammar – Grammar (defaults to DL_GRAMMAR)

Methods

generic_visit

Default visitor method

lift_child

Lift the sole child of node up to replace the node.

match

Parse and visit some text with this Visitor’s default grammar, but don’t insist on parsing all the way to the end.

parse

Parse some text with this Visitor’s default grammar and return the result of visiting it.

parse_expression

Parse a string to an OWL Object

visit

Walk a parse tree, transforming it into another representation.

visit_abbreviated_iri

visit_boolean_literal

visit_cardinality_res

visit_class_expression

visit_class_iri

visit_data_cardinality_res

visit_data_intersection

visit_data_parentheses

visit_data_primary

visit_data_property_iri

visit_data_some_only_res

visit_data_union

visit_data_value_res

visit_datatype

visit_datatype_iri

visit_datatype_restriction

visit_date_literal

visit_datetime_literal

visit_decimal_literal

visit_duration_literal

visit_facet

visit_facet_restriction

visit_facet_restrictions

visit_float_literal

visit_full_iri

visit_has_self

visit_individual_iri

visit_individual_list

visit_integer_literal

visit_intersection

visit_iri

visit_literal

visit_literal_list

visit_non_negative_integer

visit_object_property

visit_object_property_iri

visit_parentheses

visit_primary

visit_quoted_string

visit_simple_iri

visit_some_only_res

visit_string_literal_language

visit_string_literal_no_language

visit_typed_literal

visit_union

visit_value_res

Attributes

grammar

the one recommended for use with this visitor.

slots

unwrapped_exceptions

Classes of exceptions you actually intend to raise during visitation and which should propagate out of the visitor.

generic_visit(node, children)[source]

Default visitor method

Parameters:
  • node – The node we’re visiting

  • visited_children – The results of visiting the children of that node, in a list

I’m not sure there’s an implementation of this that makes sense across all (or even most) use cases, so we leave it to subclasses to implement for now.

grammar = None

the one recommended for use with this visitor. If you populate this, you will be able to call NodeVisitor.parse() as a shortcut.

Type:

The default grammar

lift_child(node, children)

Lift the sole child of node up to replace the node.

match(text, pos=0)

Parse and visit some text with this Visitor’s default grammar, but don’t insist on parsing all the way to the end.

SomeVisitor().match('some_string') is a shortcut for SomeVisitor().visit(some_grammar.match('some_string')).

ns: Optional[Union[str, owlapy.namespaces.Namespaces]]
parse(text, pos=0)

Parse some text with this Visitor’s default grammar and return the result of visiting it.

SomeVisitor().parse('some_string') is a shortcut for SomeVisitor().visit(some_grammar.parse('some_string')).

parse_expression(expression_str: str)owlapy.model.OWLClassExpression[source]

Parse a string to an OWL Object

Parameters:

expression_str – string

Returns:

The OWL Object which is represented by the string

slots = ('ns', 'grammar')
unwrapped_exceptions = ()

Classes of exceptions you actually intend to raise during visitation and which should propagate out of the visitor. These will not be wrapped in a VisitationError when they arise.

visit(node)

Walk a parse tree, transforming it into another representation.

Recursively descend a parse tree, dispatching to the method named after the rule in the Grammar that produced each node. If, for example, a rule was…

bold = '<b>'

…the visit_bold() method would be called. It is your responsibility to subclass NodeVisitor and implement those methods.

visit_abbreviated_iri(node, children)[source]
visit_boolean_literal(node, children)owlapy.model.OWLLiteral[source]
visit_cardinality_res(node, children)owlapy.model.OWLObjectCardinalityRestriction[source]
visit_class_expression(node, children)owlapy.model.OWLClassExpression[source]
visit_class_iri(node, children)owlapy.model.OWLClass[source]
visit_data_cardinality_res(node, children)owlapy.model.OWLDataCardinalityRestriction[source]
visit_data_intersection(node, visited_children)[source]
visit_data_parentheses(node, children)owlapy.model.OWLDataRange[source]
visit_data_primary(node, children)owlapy.model.OWLDataRange[source]
visit_data_property_iri(node, children)owlapy.model.OWLDataProperty[source]
visit_data_some_only_res(node, children)owlapy.model.OWLQuantifiedDataRestriction[source]
visit_data_union(node, visited_children)[source]
visit_data_value_res(node, children)owlapy.model.OWLDataHasValue[source]
visit_datatype(node, children)owlapy.model.OWLDatatype[source]
visit_datatype_iri(node, children)str[source]
visit_datatype_restriction(node, children)owlapy.model.OWLDatatypeRestriction[source]
visit_date_literal(node, children)owlapy.model.OWLLiteral[source]
visit_datetime_literal(node, children)owlapy.model.OWLLiteral[source]
visit_decimal_literal(node, children)owlapy.model.OWLLiteral[source]
visit_duration_literal(node, children)owlapy.model.OWLLiteral[source]
visit_facet(node, children)owlapy.vocab.OWLFacet[source]
visit_facet_restriction(node, children)owlapy.model.OWLFacetRestriction[source]
visit_facet_restrictions(node, visited_children)[source]
visit_float_literal(node, children)owlapy.model.OWLLiteral[source]
visit_full_iri(node, children)owlapy.model.IRI[source]
visit_has_self(node, children)owlapy.model.OWLObjectHasSelf[source]
visit_individual_iri(node, children)owlapy.model.OWLNamedIndividual[source]
visit_individual_list(node, visited_children)[source]
visit_integer_literal(node, children)owlapy.model.OWLLiteral[source]
visit_intersection(node, visited_children)[source]
visit_iri(node, children)owlapy.model.IRI[source]
visit_literal(node, children)owlapy.model.OWLLiteral[source]
visit_literal_list(node, visited_children)[source]
visit_non_negative_integer(node, children)int[source]
visit_object_property(node, children)owlapy.model.OWLObjectPropertyExpression[source]
visit_object_property_iri(node, children)owlapy.model.OWLObjectProperty[source]
visit_parentheses(node, children)owlapy.model.OWLClassExpression[source]
visit_primary(node, children)owlapy.model.OWLClassExpression[source]
visit_quoted_string(node, children)str[source]
visit_simple_iri(node, children)owlapy.model.IRI[source]
visit_some_only_res(node, children)owlapy.model.OWLQuantifiedObjectRestriction[source]
visit_string_literal_language(node, children)[source]
visit_string_literal_no_language(node, children)owlapy.model.OWLLiteral[source]
visit_typed_literal(node, children)owlapy.model.OWLLiteral[source]
visit_union(node, visited_children)[source]
visit_value_res(node, children)owlapy.model.OWLObjectHasValue[source]