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

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

我有一个 OWL 文件,其子类是 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"/>

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

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

但我的查询似乎完全错误。有人可以向我解释如何编写(或者更重要的是如何阅读或思考)这个查询以从 ontology?[=24= 中找到值 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 . 
}