Note that there are some explanatory texts on larger screens.

plurals
  1. POSPARQL: How to get an insance of an ontology, if depth of the class hierarchy is unknown?
    primarykey
    data
    text
    <p>I have a question about SPARQL. I have an ontology of animals:</p> <pre><code>Animals (is a superclass with object property &lt;hasColor&gt;) ------ Mammals (subclass of Animals) ------------- Dog (subclass of Mammals) ---------------- dog1 (a instance with property &lt;hasColor&gt;="white") ---------------- dog2 (a instance with property &lt;hasColor&gt;="red" ) ------ Bird (subclass of Animals) </code></pre> <p><strong>Is it possible to find with SPARQL "all Animals, that are 'white' " or "all instances of Animals"? And backwards: How can I know, if a instance (dog1) belongs to Animals?</strong></p> <p><strong>NOTE</strong>: The depth and breadth of the class hierarchy is unknown in advance.</p> <p>Also the query below will not work </p> <pre><code>SELECT ?x WHERE {?x rdfs:subClassOf :Animals . ?x :hasСolor "white"} </code></pre> <p>And the next query (find all Animals, that are 'white') works only if the depth of class hierarchy is known. (So if the hierarchy is known, can I make the specified steps (from top of hierarchy to bottom) to reach the goal: in this case 2 steps.</p> <pre><code>SELECT ?z WHERE { ?x rdfs:subClassOf :Animals . ?y rdfs:subClassOf ?x . ?z rdf:type ?y . ?z :hasColor "white" } </code></pre> <p>The same is true for the next example - "find all instances of Animals"</p> <pre><code>SELECT ?z WHERE { ?x rdfs:subClassOf :Animals . ?y rdfs:subClassOf ?x . ?z rdf:type ?y . } </code></pre> <p>What to do, if the hierarchie is unknown?</p> <p>The query will be processed with <strong>SDB</strong> (is a component of <strong>Jena</strong>).</p> <p>I want something like : <code>select ?x where {?x rdfs:subClassOf :Animals . ?x :hasСolor "white"})</code></p> <p><strong>UPD.</strong> Solution for "find all Animals (instances), that are 'white'" might look like this:</p> <blockquote> <p>SELECT ?y WHERE { ?x rdfs:subClassOf* :Animals . ?y rdf:type ?x . ?y :hasColor "white"}</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload