简体   繁体   中英

How to write a SPARQL query to take the values from an OWL file

I've got an OWL file with a subclass of owl:Thing "Objects" .

<rdf:RDF xmlns="http://www.semanticweb.org/PredefinedOntology#"
     xml:base="http://www.semanticweb.org/PredefinedOntology"
     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:swrlb="http://www.w3.org/2003/11/swrlb#"
     xmlns:swrl="http://www.w3.org/2003/11/swrl#"
     xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
     xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
    <owl:Ontology rdf:about="http://www.semanticweb.org/PredefinedOntology"/>

This subclass has three individuals ( Door1 , Coridor1 , Window1 ) with DataProperty assertions ( X and Y coordinates with the values). One of the individuals looks like this:

<!-- http://www.semanticweb.org/PredefinedOntology#Door1 -->

    <owl:NamedIndividual rdf:about="http://www.semanticweb.org/PredefinedOntology#Door1">
        <rdf:type rdf:resource="http://www.semanticweb.org/PredefinedOntology#Objects"/>
        <X rdf:datatype="http://www.w3.org/2001/XMLSchema#integer">2</X>
        <Y rdf:datatype="http://www.w3.org/2001/XMLSchema#integer">20</Y>
    </owl:NamedIndividual>

I need to get the values of the individual (let's say Door1 ). How can I do this with SPARQL? I was trying:

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT ?X ?datatype
WHERE {?X rdf:datatype ?datatype}

But it seems like my query is completely wrong. Could some one please explain to me how to write (or even more important how to read or think) this query to find the values X=2 and Y=20 from the ontology?

Thank you

OK, step 1 is to lose the RDF/XML text serialization. Use anything else, but Turtle is closest to SPARQL. Any RDF editor can be used to convert to Turtle. The equivalent text serialization for Door1 in Turtle is:

:Door1
   rdf:type :Objects ;
   rdf:type owl:NamedIndividual ;
   :X 2 ;
   :Y 20 .

One part of this syntax that may not be obvious is that each line is a triple (subject, predicate, object), and the ; means that the subject from the previous line is used. An advantage of this syntax is that RDF resources can be viewed as an object with properties.

Step 2 is that the SPARQL query becomes obvious because you can line up the triple patterns with the triples specified in Turtle:

SELECT ?X ?Y ?inst
WHERE {
   ?inst rdf:type owl:NamedIndividual ;
      :X ?X ;
      :Y ?Y . 
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM