我有以下数据图:
@prefix hr: <http://learningsparql.com/ns/humanResources#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix sch: <http://schema.org/> .
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
hr:Another a rdfs:Class .
hr:Employee a rdfs:Class ;
rdfs:label "model" ;
rdfs:comment "a good employee" .
hr:Longer a hr:Employee ;
rdfs:label "model" ;
rdfs:comment "a good employee" .
hr:freestanding a rdf:Property ;
sch:rangeIncludes sch:Text .
hr:missing rdfs:comment "some comment about missing" .
hr:name a rdf:Property ;
sch:domainIncludes hr:Employee .
hr:nosuper a rdf:Property ;
sch:domainIncludes hr:Uncreated ;
sch:rangeIncludes sch:Text .
hr:randomtype a hr:invalidtype ;
rdfs:label "some label about randomtype" ;
rdfs:comment "some comment about randomtype" .
hr:typo a rdfs:Classs ;
rdfs:label "some label about typo" ;
rdfs:comment "some comment about typo" .
三元组中定义的唯一主题是hr:Another,hr:Employee,hr:Longer,hr:freestanding,hr:missing,hr:name,hr:nosuper,hr:randomtype和hr:typo。作为证明,当我运行查询时:
SELECT DISTINCT ?s
WHERE {
?s ?p ?o .
}
我得到结果:
--------------------------------------------------------------
| s |
==============================================================
| <http://learningsparql.com/ns/humanResources#freestanding> |
| <http://learningsparql.com/ns/humanResources#Another> |
| <http://learningsparql.com/ns/humanResources#typo> |
| <http://learningsparql.com/ns/humanResources#nosuper> |
| <http://learningsparql.com/ns/humanResources#Employee> |
| <http://learningsparql.com/ns/humanResources#randomtype> |
| <http://learningsparql.com/ns/humanResources#Longer> |
| <http://learningsparql.com/ns/humanResources#missing> |
| <http://learningsparql.com/ns/humanResources#name> |
--------------------------------------------------------------
但是,如果我执行此SPARQL查询:
SELECT DISTINCT ?s
WHERE {
{
?s rdf:type* ?o .
}
}
我得到以下结果:
--------------------------------------------------------------
| s |
==============================================================
| <http://learningsparql.com/ns/humanResources#Longer> |
| rdfs:Class |
| sch:Text |
| "some comment about typo" |
| "some label about typo" |
| <http://learningsparql.com/ns/humanResources#nosuper> |
| "a good employee" |
| <http://learningsparql.com/ns/humanResources#Uncreated> |
| <http://learningsparql.com/ns/humanResources#missing> |
| "some comment about randomtype" |
| "model" |
| <http://learningsparql.com/ns/humanResources#freestanding> |
| "some label about randomtype" |
| "some comment about missing" |
| <http://learningsparql.com/ns/humanResources#Another> |
| <http://learningsparql.com/ns/humanResources#invalidtype> |
| <http://learningsparql.com/ns/humanResources#typo> |
| <http://learningsparql.com/ns/humanResources#randomtype> |
| <http://learningsparql.com/ns/humanResources#Employee> |
| rdfs:Classs |
| rdf:Property |
| <http://learningsparql.com/ns/humanResources#name> |
--------------------------------------------------------------
我不确定为什么rdf:Property,“好员工”,sch:Text等项目不是数据图中的主题时会作为主题返回。
他们为什么?
显然,这与SPARQL如何处理我尚不了解的属性路径有关。
您正在使用具有零个或多个通配符('*')的属性路径。有效地,模式?s rdf:type* ?o
表示“通过零个或多个类型关系连接到任何值?s
的每个值?o
”。