In my protege, I state explicitly that the class Symphony is subclass of class Recommendable, as illustrated here: Classes Hierarchy
I've also added some instances to the class Symphony, when I query the Symphony instances, I get results. However, when I query the Recommendable instances, I get nothing.
This is the query for Symphony class:
SELECT DISTINCT ?subject WHERE {
?subject rdf:type owbes:Symphony
}
And here is the result: Symphony instances query result
This is the query for Recommendable class.
SELECT DISTINCT ?subject WHERE {
?subject rdf:type owbes:Recommendable
}
This result is empty, as you see here [Recommendable instances query result][3]
Both from the same prefix. What wrong did I do?
This is what's being generated in the owl file:
<owl:Class rdf:about="bla bla bla/recommendation-systems#Symphony">
<rdfs:subClassOf rdf:resource="bla bla bla/recommendation-systems#Recommendable"/>
</owl:Class>
As you see, I've correctly made Symphony a subclass of Recommendable
I found the solution: Making this query solves the problem
SELECT ?subject WHERE {
?subject rdf:type ?type.
?type rdfs:subClassOf owbes:Recommendable
}
Yet, I don't know why rdf:type doesn't work
<?xml version="1.0"?>
<rdf:RDF xmlns="http://www.semanticweb.org/welovethesemanticweb#"
xml:base="http://www.semanticweb.org/welovethesemanticweb"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
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#"
xmlns:recommendation-systems="http://www.welovethesemanticweb.com/recommendation-systems#">
<owl:Ontology rdf:about="http://www.semanticweb.org/welovethesemanticweb"/>
<!--
///////////////////////////////////////////////////////////////////////////////////////
//
// Annotation properties
//
///////////////////////////////////////////////////////////////////////////////////////
-->
<!-- http://www.welovethesemanticweb.com/recommendation-systems#hasSimilarityValue -->
<owl:AnnotationProperty rdf:about="http://www.welovethesemanticweb.com/recommendation-systems#hasSimilarityValue"/>
<!--
///////////////////////////////////////////////////////////////////////////////////////
//
// Object Properties
//
///////////////////////////////////////////////////////////////////////////////////////
-->
<!-- http://www.welovethesemanticweb.com/recommendation-systems#composedBy -->
<owl:ObjectProperty rdf:about="http://www.welovethesemanticweb.com/recommendation-systems#composedBy">
<rdfs:subPropertyOf rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#hasArtist"/>
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#AsymmetricProperty"/>
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#IrreflexiveProperty"/>
<rdfs:domain rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Symphony"/>
<rdfs:range rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Composer"/>
<rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Composed By</rdfs:label>
</owl:ObjectProperty>
<!-- http://www.welovethesemanticweb.com/recommendation-systems#fromEra -->
<owl:ObjectProperty rdf:about="http://www.welovethesemanticweb.com/recommendation-systems#fromEra">
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#AsymmetricProperty"/>
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#IrreflexiveProperty"/>
<rdfs:domain rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Artist"/>
<rdfs:range rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#MusicalEra"/>
<rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Describes the musical era that music is from</rdfs:label>
<rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">From Era</rdfs:label>
<recommendation-systems:hasSimilarityValue rdf:datatype="http://www.w3.org/2001/XMLSchema#double">0.1</recommendation-systems:hasSimilarityValue>
</owl:ObjectProperty>
<!-- http://www.welovethesemanticweb.com/recommendation-systems#hasArtist -->
<owl:ObjectProperty rdf:about="http://www.welovethesemanticweb.com/recommendation-systems#hasArtist">
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#AsymmetricProperty"/>
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#IrreflexiveProperty"/>
<rdfs:domain rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Recommendable"/>
<rdfs:range rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Artist"/>
<rdfs:comment>Describes the arties of the music</rdfs:comment>
<rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Has Artist</rdfs:label>
<recommendation-systems:hasSimilarityValue rdf:datatype="http://www.w3.org/2001/XMLSchema#double">0.4</recommendation-systems:hasSimilarityValue>
</owl:ObjectProperty>
<!--
///////////////////////////////////////////////////////////////////////////////////////
//
// Data properties
//
///////////////////////////////////////////////////////////////////////////////////////
-->
<!-- http://www.welovethesemanticweb.com/recommendation-systems#contributeToSimilarities -->
<owl:DatatypeProperty rdf:about="http://www.welovethesemanticweb.com/recommendation-systems#contributeToSimilarities">
<rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#double"/>
</owl:DatatypeProperty>
<!--
///////////////////////////////////////////////////////////////////////////////////////
//
// Classes
//
///////////////////////////////////////////////////////////////////////////////////////
-->
<!-- http://www.welovethesemanticweb.com/recommendation-systems#Artist -->
<owl:Class rdf:about="http://www.welovethesemanticweb.com/recommendation-systems#Artist">
<owl:disjointWith rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#MusicalEra"/>
<owl:disjointWith rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Recommendable"/>
<owl:disjointWith rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Song"/>
<owl:disjointWith rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Symphony"/>
</owl:Class>
<!-- http://www.welovethesemanticweb.com/recommendation-systems#Composer -->
<owl:Class rdf:about="http://www.welovethesemanticweb.com/recommendation-systems#Composer">
<rdfs:subClassOf rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Artist"/>
<owl:disjointWith rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#MusicalEra"/>
<owl:disjointWith rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Recommendable"/>
<owl:disjointWith rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Song"/>
<owl:disjointWith rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Symphony"/>
</owl:Class>
<!-- http://www.welovethesemanticweb.com/recommendation-systems#MusicalEra -->
<owl:Class rdf:about="http://www.welovethesemanticweb.com/recommendation-systems#MusicalEra">
<owl:disjointWith rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Recommendable"/>
<owl:disjointWith rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Singer"/>
<owl:disjointWith rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Song"/>
<owl:disjointWith rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Symphony"/>
</owl:Class>
<!-- http://www.welovethesemanticweb.com/recommendation-systems#Recommendable -->
<owl:Class rdf:about="http://www.welovethesemanticweb.com/recommendation-systems#Recommendable">
<owl:disjointWith rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Singer"/>
</owl:Class>
<!-- http://www.welovethesemanticweb.com/recommendation-systems#Singer -->
<owl:Class rdf:about="http://www.welovethesemanticweb.com/recommendation-systems#Singer">
<rdfs:subClassOf rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Artist"/>
<owl:disjointWith rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Song"/>
<owl:disjointWith rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Symphony"/>
</owl:Class>
<!-- http://www.welovethesemanticweb.com/recommendation-systems#Song -->
<owl:Class rdf:about="http://www.welovethesemanticweb.com/recommendation-systems#Song">
<rdfs:subClassOf rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Recommendable"/>
</owl:Class>
<!-- http://www.welovethesemanticweb.com/recommendation-systems#Symphony -->
<owl:Class rdf:about="http://www.welovethesemanticweb.com/recommendation-systems#Symphony">
<rdfs:subClassOf rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Recommendable"/>
</owl:Class>
<!--
///////////////////////////////////////////////////////////////////////////////////////
//
// Individuals
//
///////////////////////////////////////////////////////////////////////////////////////
-->
<!-- http://www.welovethesemanticweb.com/recommendation-systems#Adele -->
<owl:NamedIndividual rdf:about="http://www.welovethesemanticweb.com/recommendation-systems#Adele">
<rdf:type rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Artist"/>
<rdf:type rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Singer"/>
<recommendation-systems:fromEra rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#current"/>
</owl:NamedIndividual>
<!-- http://www.welovethesemanticweb.com/recommendation-systems#Beethoven -->
<owl:NamedIndividual rdf:about="http://www.welovethesemanticweb.com/recommendation-systems#Beethoven">
<rdf:type rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Artist"/>
<rdf:type rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Composer"/>
<recommendation-systems:fromEra rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#classical"/>
</owl:NamedIndividual>
<!-- http://www.welovethesemanticweb.com/recommendation-systems#Dies_Irae -->
<owl:NamedIndividual rdf:about="http://www.welovethesemanticweb.com/recommendation-systems#Dies_Irae">
<rdf:type rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Recommendable"/>
<rdf:type rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Symphony"/>
<recommendation-systems:composedBy rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Mozart"/>
<recommendation-systems:hasArtist rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Mozart"/>
<rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Dies Irae</rdfs:label>
</owl:NamedIndividual>
<!-- http://www.welovethesemanticweb.com/recommendation-systems#Le_nozze_di_Figaro -->
<owl:NamedIndividual rdf:about="http://www.welovethesemanticweb.com/recommendation-systems#Le_nozze_di_Figaro">
<rdf:type rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Recommendable"/>
<rdf:type rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Symphony"/>
<recommendation-systems:composedBy rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Mozart"/>
<recommendation-systems:hasArtist rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Mozart"/>
<rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Le Nozze Di Digaro</rdfs:label>
</owl:NamedIndividual>
<!-- http://www.welovethesemanticweb.com/recommendation-systems#Mozart -->
<owl:NamedIndividual rdf:about="http://www.welovethesemanticweb.com/recommendation-systems#Mozart">
<rdf:type rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Artist"/>
<rdf:type rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Composer"/>
<recommendation-systems:fromEra rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#classical"/>
</owl:NamedIndividual>
<!-- http://www.welovethesemanticweb.com/recommendation-systems#baroque -->
<owl:NamedIndividual rdf:about="http://www.welovethesemanticweb.com/recommendation-systems#baroque">
<rdf:type rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#MusicalEra"/>
</owl:NamedIndividual>
<!-- http://www.welovethesemanticweb.com/recommendation-systems#classical -->
<owl:NamedIndividual rdf:about="http://www.welovethesemanticweb.com/recommendation-systems#classical">
<rdf:type rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#MusicalEra"/>
</owl:NamedIndividual>
<!-- http://www.welovethesemanticweb.com/recommendation-systems#current -->
<owl:NamedIndividual rdf:about="http://www.welovethesemanticweb.com/recommendation-systems#current">
<rdf:type rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#MusicalEra"/>
</owl:NamedIndividual>
<!-- http://www.welovethesemanticweb.com/recommendation-systems#romantic -->
<owl:NamedIndividual rdf:about="http://www.welovethesemanticweb.com/recommendation-systems#romantic">
<rdf:type rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#MusicalEra"/>
</owl:NamedIndividual>
<!-- http://www.welovethesemanticweb.com/recommendation-systems#5th_Symphony -->
<owl:NamedIndividual rdf:about="http://www.welovethesemanticweb.com/recommendation-systems#5th_Symphony">
<rdf:type rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Recommendable"/>
<rdf:type rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Symphony"/>
<recommendation-systems:composedBy rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Beethoven"/>
<recommendation-systems:hasArtist rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Beethoven"/>
<rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">5th Symphony</rdfs:label>
</owl:NamedIndividual>
<!-- http://www.welovethesemanticweb.com/recommendation-systems#Requiem:_Sequentia -->
<owl:NamedIndividual rdf:about="http://www.welovethesemanticweb.com/recommendation-systems#Requiem:_Sequentia">
<rdf:type rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Recommendable"/>
<rdf:type rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Symphony"/>
<recommendation-systems:composedBy rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Mozart"/>
<recommendation-systems:hasArtist rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Mozart"/>
<rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Requiem Sequentia</rdfs:label>
</owl:NamedIndividual>
<!--
///////////////////////////////////////////////////////////////////////////////////////
//
// General axioms
//
///////////////////////////////////////////////////////////////////////////////////////
-->
<rdf:Description>
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#AllDifferent"/>
<owl:distinctMembers rdf:parseType="Collection">
<rdf:Description rdf:about="http://www.welovethesemanticweb.com/recommendation-systems#baroque"/>
<rdf:Description rdf:about="http://www.welovethesemanticweb.com/recommendation-systems#classical"/>
<rdf:Description rdf:about="http://www.welovethesemanticweb.com/recommendation-systems#romantic"/>
</owl:distinctMembers>
</rdf:Description>
</rdf:RDF>
<!-- Generated by the OWL API (version 4.1.3.20151118-2017) https://github.com/owlcs/owlapi -->
When a class C is declared as a subclass of class D, you can infer that an instance of C is also an instance of D. However, that process of inference is something that you need a reasoner for. If you're not using a reasoner, you won't automatically get that result. In short, you're asking for a triple of the form
?subject rdf:type owbes:Recommendable
but that's not in the data. What's in the data is two triples:
?subject rdf:type owbes:Symphony
owbes:Symphony rdfs:subClassOf owbes:Recommendable
In this case, you can actually get by using a SPARQL query with property paths; you don't need a full reasoner. You can use a query like this:
select ?subject where {
?subject rdf:type/rdfs:subClassOf* owbes:Recommendable
}
This says to find subjects that have a type that's linked to owbes:Recommendable by a chain (possibly of length zero) of rdfs:subClassOf properties. In practice, that means to find ?subjects that are owbes:Recommendable or one of its subclasses.
For some more information, see: