Skip to content

Commit

Permalink
Merge pull request #32 from dice-group/general-adjustments
Browse files Browse the repository at this point in the history
Issues solved
  • Loading branch information
Demirrr authored Apr 27, 2024
2 parents 841aeea + 8b7472f commit 18a828f
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <http://example.com/society#hasChild> ?s_1 . ?s_1 a <http://example.com/society#male> . ?x a <http://example.com/society#teacher> . } }
```

Expand Down
2 changes: 1 addition & 1 deletion docs/usage/usage_examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <http://example.com/family#male> . { SELECT ?x WHERE { ?x <http://example.com/family#hasChild> ?s_1 . ?s_1 a <http://example.com/family#person> . } GROUP BY ?x HAVING ( COUNT ( ?s_1 ) >= 1 ) } }

print(owl_expression_to_manchester(ce))
Expand Down
2 changes: 2 additions & 0 deletions owlapy/class_expression/restriction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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

Expand Down
8 changes: 4 additions & 4 deletions owlapy/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <http://example.com/society#hasChild> ?s_1 .
?s_1 a <http://example.com/society#male> .
Expand Down

0 comments on commit 18a828f

Please sign in to comment.