From 9a01e89600f4b78ee23467a30c3aa5fcdccbb63d Mon Sep 17 00:00:00 2001 From: Alkid Date: Fri, 26 Apr 2024 15:32:33 +0200 Subject: [PATCH 1/4] changed order of input arguments #29 --- owlapy/converter.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/owlapy/converter.py b/owlapy/converter.py index 3751db5..8ad9393 100644 --- a/owlapy/converter.py +++ b/owlapy/converter.py @@ -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 From 37f5c216c3a2aecf13a9c92762d955c82b6a0ebf Mon Sep 17 00:00:00 2001 From: Alkid Date: Fri, 26 Apr 2024 15:39:36 +0200 Subject: [PATCH 2/4] updated usage of owl_expression_to_sparql --- README.md | 2 +- docs/usage/usage_examples.md | 2 +- tests/test_examples.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) 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/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 . From b5029826c3ec9025b02a010dfe584233d0bcadb9 Mon Sep 17 00:00:00 2001 From: Alkid Date: Fri, 26 Apr 2024 22:25:01 +0200 Subject: [PATCH 3/4] added type restriction for fillers of OWLQuantifiedDataRestriction and OWLDataCardinalityRestriction --- owlapy/class_expression/restriction.py | 2 ++ 1 file changed, 2 insertions(+) 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 From 8b7472fe17f623cb25ef10fb76bf36918aaafe85 Mon Sep 17 00:00:00 2001 From: Alkid Date: Fri, 26 Apr 2024 22:25:56 +0200 Subject: [PATCH 4/4] fixed bug for type assertion when converting OWLDataHasValue --- owlapy/converter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/owlapy/converter.py b/owlapy/converter.py index 8ad9393..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