owlapy.converter

Format converter.

Module Contents

Classes

VariablesMapping

Helper class for owl-to-sparql conversion.

Owl2SparqlConverter

Convert owl (owlapy model class expressions) to SPARQL.

Functions

peek(x)

Peek the last element of an array.

owl_expression_to_sparql(→ str)

Convert an OWL Class Expression (https://www.w3.org/TR/owl2-syntax/#Class_Expressions) into a SPARQL query

Attributes

converter

owlapy.converter.peek(x)[source]

Peek the last element of an array.

Returns:

The last element arr[-1].

class owlapy.converter.VariablesMapping[source]

Helper class for owl-to-sparql conversion.

__slots__ = ('class_cnt', 'prop_cnt', 'ind_cnt', 'dict')
get_variable(e: owlapy.owl_object.OWLEntity) str[source]
new_individual_variable() str[source]
new_property_variable() str[source]
__contains__(item: owlapy.owl_object.OWLEntity) bool[source]
__getitem__(item: owlapy.owl_object.OWLEntity) str[source]
class owlapy.converter.Owl2SparqlConverter[source]

Convert owl (owlapy model class expressions) to SPARQL.

property modal_depth
property current_variable
__slots__ = ('ce', 'sparql', 'variables', 'parent', 'parent_var', 'properties', 'variable_entities', 'cnt',...
ce: owlapy.class_expression.OWLClassExpression
sparql: List[str]
variables: List[str]
parent: List[owlapy.class_expression.OWLClassExpression]
parent_var: List[str]
variable_entities: Set[owlapy.owl_object.OWLEntity]
properties: Dict[int, List[owlapy.owl_object.OWLEntity]]
mapping: VariablesMapping
grouping_vars: Dict[owlapy.class_expression.OWLClassExpression, Set[str]]
having_conditions: Dict[owlapy.class_expression.OWLClassExpression, Set[str]]
cnt: int
for_all_de_morgan: bool
named_individuals: bool
convert(root_variable: str, ce: owlapy.class_expression.OWLClassExpression, for_all_de_morgan: bool = True, named_individuals: bool = False)[source]

Used to convert owl class expression to SPARQL syntax.

Parameters:
  • root_variable (str) – Root variable name that will be used in SPARQL query.

  • ce (OWLClassExpression) – The owl class expression to convert.

  • named_individuals (bool) – If ‘True’ return only entities that are instances of owl:NamedIndividual.

Returns:

The SPARQL query.

Return type:

list[str]

abstract render(e)[source]
stack_variable(var)[source]
stack_parent(parent: owlapy.class_expression.OWLClassExpression)[source]
abstract process(ce: owlapy.class_expression.OWLClassExpression)[source]
forAll(ce: owlapy.class_expression.OWLObjectAllValuesFrom)[source]
forAllDeMorgan(ce: owlapy.class_expression.OWLObjectAllValuesFrom)[source]
new_count_var() str[source]
append_triple(subject, predicate, object_)[source]
append(frag)[source]
triple(subject, predicate, object_)[source]
as_query(root_variable: str, ce: owlapy.class_expression.OWLClassExpression, for_all_de_morgan: bool = True, count: bool = False, values: Iterable[owlapy.owl_individual.OWLNamedIndividual] | None = None, named_individuals: bool = False) str[source]
owlapy.converter.converter
owlapy.converter.owl_expression_to_sparql(expression: owlapy.class_expression.OWLClassExpression = None, root_variable: str = '?x', values: Iterable[owlapy.owl_individual.OWLNamedIndividual] | None = None, for_all_de_morgan: bool = True, named_individuals: bool = False) str[source]

Convert an OWL Class Expression (https://www.w3.org/TR/owl2-syntax/#Class_Expressions) into a SPARQL query root variable: the variable that will be projected expression: the class expression to be transformed to a SPARQL query

values: positive or negative examples from a class expression problem. Unclear for_all_de_morgan: if set to True, the SPARQL mapping will use the mapping containing the nested FILTER NOT EXISTS patterns for the universal quantifier (¬(∃r.¬C)), instead of the counting query named_individuals: if set to True, the generated SPARQL query will return only entities that are instances of owl:NamedIndividual