简短的回答是数据看起来不太像您的查询期望的样子。让我们看一下这个 RDF/XML 片段所描述的图表:
<rdf:RDF xml:base="http://example.org/"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:service="http://www.daml.org/services/owl-s/1.1/Service.owl#"
xmlns:profile="http://www.daml.org/services/owl-s/1.1/Profile.owl#">
<profile:Profile rdf:ID="AddServiceName">
<service:presentedBy rdf:resource="AddServicePresenter"/>
<profile:serviceName>"ser"</profile:serviceName>
</profile:Profile>
</rdf:RDF>
Turtle 格式,更接近 SPARQL 的模式语言:
@prefix service: <http://www.daml.org/services/owl-s/1.1/Service.owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix profile: <http://www.daml.org/services/owl-s/1.1/Profile.owl#> .
<http://example.org/#AddServiceName>
a profile:Profile ;
profile:serviceName "\"ser\"" ;
service:presentedBy <http://example.org/AddServicePresenter> .
特别要注意的是,对应于 RDF 图中的主题或对象的 RDF/XML 元素可以使用其 XML 元素名称作为rdf:type
语句的简写。所以<profile:Profile rdf:ID="x">…</profile:Profile>
说资源<...#x>
有rdf:type profile:Profile
。在 Turtle 和 SPARQL 中,a
是 的简写rdf:type
,所以<...#x> a profile:Profile
表示<...#x> rdf:type profile:Profile
。的其他属性<...#x>
由元素的内容决定。在这种情况下<...#AddServiceName>
,有两个属性,一个 forservice:presentedBy
和一个 for profile:serviceName
。
要查找个人资料、他们的演示者和姓名,您需要如下查询:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX service: <http://www.daml.org/services/owl-s/1.1/Service.owl#>
PREFIX profile: <http://www.daml.org/services/owl-s/1.1/Profile.owl#>
SELECT ?profile ?presenter ?name WHERE {
?profile a profile:Profile ;
service:presentedBy ?presenter ;
profile:serviceName ?name .
}
三元组模式也可以写成更详细的形式:
?profile rdf:type profile:Profile .
?profile service:presentedBy ?presenter .
?profile profile:serviceName ?name .
运行此查询会产生以下结果:
$ arq --query query.sparql --data data.rdf
-----------------------------------------------------------------------------------------------
| profile | presenter | name |
===============================================================================================
| <http://example.org/#AddServiceName> | <http://example.org/AddServicePresenter> | "\"ser\"" |
-----------------------------------------------------------------------------------------------