diff --git a/examples/quality_of_owl_ce_via_sparql.py b/examples/quality_of_owl_ce_via_sparql.py new file mode 100644 index 00000000..ea9603f5 --- /dev/null +++ b/examples/quality_of_owl_ce_via_sparql.py @@ -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 +""" \ No newline at end of file diff --git a/owlapy/converter.py b/owlapy/converter.py index 426e32dd..b6ebcaa1 100644 --- a/owlapy/converter.py +++ b/owlapy/converter.py @@ -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) @@ -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)