如何使用sparql查询从示例owl数据中获取数据

问题描述 投票:0回答:1

这是我的例子猫头鹰:

    <rdf:type rdf:resource="http://www.w3.org/2000/10/swap/pim/contact#Person"/>
    <foaf:age rdf:datatype="http://www.w3.org/2001/XMLSchema#string">10</foaf:age>
    <foaf:birthday rdf:datatype="http://www.w3.org/2001/XMLSchema#string">10.10</foaf:birthday>
    <foaf:firstName rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Liis</foaf:firstName>
</owl:NamedIndividual>

因为im新手与sparql,我想知道怎么做一个查询来获得这个rdf的所有实例一个<rdf:type rdf:resource="http://www.w3.org/2000/10/swap/pim/contact#Person"/>

nd然后从它获取数据例如get age和get age = 10或获取name和name =“someName”<foaf:age rdf:datatype="http://www.w3.org/2001/XMLSchema#string">10</foaf:age>我的意思是从这一行获取数据。

sparql rdf jena ontology fuseki
1个回答
0
投票

我对这个问题的回答是:这个查询帮助你找到所有实例,s是对象名,p是访问这些数据的类型,o是行的值。

prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix owl: <http://www.w3.org/2002/07/owl#>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX resource: <http://purl.org/vocab/resourcelist/schema#>

select distinct ?s ?p ?o ?k where {
?s ?p ?o ;
  a <http://www.w3.org/2000/10/swap/pim/contact#Person> .
?k foaf:age ?x .}

第二部分?k foaf:age ?x .是如何通过类型名称来实现实例数据。结果是<http://example.register.nl/nationaalhandelsregister#person1>,10

© www.soinside.com 2019 - 2024. All rights reserved.