简体   繁体   English

如何编写SPARQL查询以从OWL文件中获取值

[英]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" . 我有一个带有owl:Thing "Objects"子类的OWL文件。

<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). 该子类具有三个具有DataProperty断言( XY坐标与值)的个人( Door1Coridor1Window1 )。 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 ). 我需要获取个人的值(假设Door1 )。 How can I do this with SPARQL? 如何使用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? 能否请我解释一下如何编写(或更重要的是如何阅读或思考)此查询以从本体中找到值X=2Y=20

Thank you 谢谢

OK, step 1 is to lose the RDF/XML text serialization. 好的,步骤1是丢失RDF / XML文本序列化。 Use anything else, but Turtle is closest to SPARQL. 使用其他任何东西,但是Turtle最接近SPARQL。 Any RDF editor can be used to convert to Turtle. 任何RDF编辑器均可用于转换为Turtle。 The equivalent text serialization for Door1 in Turtle is: Turtle中Door1的等效文本序列化为:

: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. 此语法的优点是可以将RDF资源视为具有属性的对象。

Step 2 is that the SPARQL query becomes obvious because you can line up the triple patterns with the triples specified in Turtle: 第2步是SPARQL查询变得显而易见,因为您可以将三元组模式与Turtle中指定的三元组对齐:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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