I have built a small ontology in Protege to test punning with a SPARQL query. The Ontology is:
<?xml version="1.0"?>
<Ontology xmlns="http://www.w3.org/2002/07/owl#"
xml:base="http://www.semanticweb.org/usr/ontologies/2022/2/untitled-ontology-88"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:xml="http://www.w3.org/XML/1998/namespace"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
ontologyIRI="http://www.semanticweb.org/usr/ontologies/2022/2/untitled-ontology-88">
<Prefix name="owl" IRI="http://www.w3.org/2002/07/owl#"/>
<Prefix name="rdf" IRI="http://www.w3.org/1999/02/22-rdf-syntax-ns#"/>
<Prefix name="xml" IRI="http://www.w3.org/XML/1998/namespace"/>
<Prefix name="xsd" IRI="http://www.w3.org/2001/XMLSchema#"/>
<Prefix name="rdfs" IRI="http://www.w3.org/2000/01/rdf-schema#"/>
<Declaration>
<Class IRI="#B"/>
</Declaration>
<Declaration>
<Class IRI="#CL"/>
</Declaration>
<Declaration>
<Class IRI="#E"/>
</Declaration>
<Declaration>
<Class IRI="#ES"/>
</Declaration>
<Declaration>
<Class IRI="#GE"/>
</Declaration>
<Declaration>
<Class IRI="#RLS"/>
</Declaration>
<Declaration>
<ObjectProperty IRI="#Lives_in"/>
</Declaration>
<Declaration>
<DataProperty IRI="#hasAge"/>
</Declaration>
<Declaration>
<NamedIndividual IRI="#CPZ"/>
</Declaration>
<Declaration>
<NamedIndividual IRI="#ES"/>
</Declaration>
<Declaration>
<NamedIndividual IRI="#GE"/>
</Declaration>
<Declaration>
<NamedIndividual IRI="#Harry"/>
</Declaration>
<SubClassOf>
<Class IRI="#E"/>
<Class IRI="#B"/>
</SubClassOf>
<SubClassOf>
<Class IRI="#ES"/>
<Class IRI="#RLS"/>
</SubClassOf>
<SubClassOf>
<Class IRI="#GE"/>
<Class IRI="#E"/>
</SubClassOf>
<ClassAssertion>
<Class IRI="#ES"/>
<NamedIndividual IRI="#GE"/>
</ClassAssertion>
<ClassAssertion>
<Class IRI="#GE"/>
<NamedIndividual IRI="#Harry"/>
</ClassAssertion>
<ObjectPropertyAssertion>
<ObjectProperty IRI="#Lives_in"/>
<NamedIndividual IRI="#Harry"/>
<NamedIndividual IRI="#CPZ"/>
</ObjectPropertyAssertion>
</Ontology>
<!-- Generated by the OWL API (version 4.5.9.2019-02-01T07:24:44Z) https://github.com/owlcs/owlapi -->
And the SPARQL query that i am using to test the pun entity (GE) is:
SELECT ?y ?x ?z
WHERE {
?x a ?y.
?z a ?x.
?z :Lives_in :CPZ.
}
An the output that i am getting is:
my question is why I am getting 6 answers instead of the first one in output? and what does the other 5 bindings of ?y(owl:Class and owl:NamedIndividual) mean?
Thank you!
Harry is a GE, from your assertions. GE is both a class and an individual; so GE appears in other statements as well, and that's multiplying the answers you're seeing. It's analogous as joining across tables where the join value matches multiple rows in one of the tables involved.