Skip to content

Commit

Permalink
Assertion info extended
Browse files Browse the repository at this point in the history
  • Loading branch information
Demirrr committed Oct 17, 2024
1 parent 014601d commit c6b53f4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
23 changes: 23 additions & 0 deletions examples/quality_of_owl_ce_via_sparql.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""
The confusion matrix indicating the quality of an OWL Class Expression can be computed through SPARQL.
By this, we avoid the process of retrieving instances of an OWL Class Expression, hence, accelerate the learning process
"""
from owlapy import owl_expression_to_sparql_with_confusion_matrix
from owlapy.owl_individual import OWLNamedIndividual
from owlapy.class_expression import OWLClass
import requests

pos={OWLNamedIndividual('http://dbpedia.org/resource/George_Montagu_(naturalist)'), OWLNamedIndividual('http://dbpedia.org/resource/Andrei_Monin'), OWLNamedIndividual('http://dbpedia.org/resource/Joe_Bastardi')}
neg={OWLNamedIndividual('http://dbpedia.org/resource/James_M._Bower'), OWLNamedIndividual('http://dbpedia.org/resource/Shirley_Meng'), OWLNamedIndividual('http://dbpedia.org/resource/Betsy_Weatherhead')}
response = requests.post("https://dbpedia-2022-12.data.dice-research.org/sparql", data={"query": owl_expression_to_sparql_with_confusion_matrix(expression=OWLClass('http://dbpedia.org/ontology/Person'),positive_examples=pos,negative_examples=neg)})
for res in response.json()["results"]["bindings"]:
for k,v in res.items():
print(k,eval(v["value"]))


"""
tp 3.0
fn 0.0
fp 3.0
tn 0.0
"""
3 changes: 2 additions & 1 deletion owlapy/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def current_variable(self):
# each overload of the method is responsible for processing a different type of class expressions (e.g., ⊔ or ⊓)
@singledispatchmethod
def process(self, ce: OWLClassExpression):
raise NotImplementedError(ce)
raise NotImplementedError(f"We cannot create SPARQL query based on the following owl class {ce}")

# an overload of process function
# this overload is responsible for handling single concepts (e.g., Brother)
Expand Down Expand Up @@ -607,6 +607,7 @@ def as_query(self,
count: bool = False,
values: Optional[Iterable[OWLNamedIndividual]] = None,
named_individuals: bool = False) -> str:
assert isinstance(ce,OWLClassExpression), f"ce must be an instance of OWLClassExpression. Currently {type(ce)}"
# root variable: the variable that will be projected
# ce: the class expression to be transformed to a SPARQL query
# for_all_de_morgan: true -> ¬(∃r.¬C), false -> (∀r.C)
Expand Down

0 comments on commit c6b53f4

Please sign in to comment.