diff --git a/README.md b/README.md index e8b7401..89d2b22 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ teacher_that_hasChild_male = OWLObjectIntersectionOf([hasChild_male, teacher]) # You can render and print owl class expressions in description logics syntax (and vice-versa) print(owl_expression_to_dl(teacher_that_hasChild_male)) # (∃ hasChild.male) ⊓ teacher -print(owl_expression_to_sparql("?x", teacher_that_hasChild_male)) +print(owl_expression_to_sparql(teacher_that_hasChild_male)) # SELECT DISTINCT ?x WHERE { ?x ?s_1 . ?s_1 a . ?x a . } } ``` diff --git a/docs/usage/usage_examples.md b/docs/usage/usage_examples.md index 531b249..41413dc 100644 --- a/docs/usage/usage_examples.md +++ b/docs/usage/usage_examples.md @@ -101,7 +101,7 @@ from owlapy import owl_expression_to_sparql, owl_expression_to_dl, owl_expressio print(owl_expression_to_dl(ce)) # Result: male ⊓ (≥ 1 hasChild.person) -print(owl_expression_to_sparql(expression=ce)) +print(owl_expression_to_sparql(ce)) # Result: SELECT DISTINCT ?x WHERE { ?x a . { SELECT ?x WHERE { ?x ?s_1 . ?s_1 a . } GROUP BY ?x HAVING ( COUNT ( ?s_1 ) >= 1 ) } } print(owl_expression_to_manchester(ce)) diff --git a/owlapy/class_expression/restriction.py b/owlapy/class_expression/restriction.py index 6488181..04e7a4b 100644 --- a/owlapy/class_expression/restriction.py +++ b/owlapy/class_expression/restriction.py @@ -461,6 +461,7 @@ class OWLQuantifiedDataRestriction(OWLQuantifiedRestriction[OWLDataRange], _filler: OWLDataRange def __init__(self, filler: OWLDataRange): + assert isinstance(filler, OWLDataRange), "filler must be an OWLDataRange" self._filler = filler def get_filler(self) -> OWLDataRange: @@ -478,6 +479,7 @@ class OWLDataCardinalityRestriction(OWLCardinalityRestriction[OWLDataRange], @abstractmethod def __init__(self, cardinality: int, property: OWLDataPropertyExpression, filler: OWLDataRange): + assert isinstance(filler, OWLDataRange), "filler must be an OWLDataRange" super().__init__(cardinality, filler) self._property = property diff --git a/owlapy/converter.py b/owlapy/converter.py index 3751db5..c83dbe5 100644 --- a/owlapy/converter.py +++ b/owlapy/converter.py @@ -498,7 +498,7 @@ def _(self, ce: OWLDataAllValuesFrom): def _(self, ce: OWLDataHasValue): property_expression = ce.get_property() value = ce.get_filler() - assert isinstance(value, OWLDataProperty) + assert isinstance(value, OWLLiteral) self.append_triple(self.current_variable, property_expression, value) @process.register @@ -587,10 +587,10 @@ def as_query(self, converter = Owl2SparqlConverter() -def owl_expression_to_sparql(root_variable: str = "?x", - expression: OWLClassExpression = None, +def owl_expression_to_sparql(expression: OWLClassExpression = None, + root_variable: str = "?x", values: Optional[Iterable[OWLNamedIndividual]] = None, - named_individuals: bool = False)->str: + named_individuals: bool = False) -> str: """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 diff --git a/tests/test_examples.py b/tests/test_examples.py index c7d3f29..926696c 100644 --- a/tests/test_examples.py +++ b/tests/test_examples.py @@ -20,7 +20,7 @@ def test_readme(self): male_teachers_with_children = OWLObjectIntersectionOf([males_with_children, teacher]) assert owl_expression_to_dl(male_teachers_with_children)=="(∃ hasChild.male) ⊓ teacher" - assert owl_expression_to_sparql("?x", male_teachers_with_children)=="""SELECT + assert owl_expression_to_sparql(male_teachers_with_children)=="""SELECT DISTINCT ?x WHERE { ?x ?s_1 . ?s_1 a .