繁体   English   中英

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

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

我有一个带有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"/>

该子类具有三个具有DataProperty断言( XY坐标与值)的个人( Door1Coridor1Window1 )。 其中一个人看起来像这样:

<!-- 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>

我需要获取个人的值(假设Door1 )。 如何使用SPARQL执行此操作? 我正在尝试:

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}

但似乎我的查询是完全错误的。 能否请我解释一下如何编写(或更重要的是如何阅读或思考)此查询以从本体中找到值X=2Y=20

谢谢

好的,步骤1是丢失RDF / XML文本序列化。 使用其他任何东西,但是Turtle最接近SPARQL。 任何RDF编辑器均可用于转换为Turtle。 Turtle中Door1的等效文本序列化为:

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

这种语法的一部分可能并不明显,即每一行都是三元组(主题,谓词,对象),而;; 表示使用前一行的主题。 此语法的优点是可以将RDF资源视为具有属性的对象。

第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