为什么此 SPARQL 查询 return 某些项目作为主题?

Why does this SPARQL query return certain items as subjects?

我有如下数据图:

@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、"a good employee"、sch:Text 等项目在数据图中不是主题时却作为主题返回。

为什么是他们?

显然,这与 SPARQL 如何处理 属性 我还不了解的路径有关。

您正在使用带有零个或多个通配符(“*”)的 属性 路径。实际上,模式 ?s rdf:type* ?o 表示 "every value ?s connected through zero or more type relations to any value ?o"。

图中出现的每个 值(实际上是任何图中的每个值)都与之匹配,因为每个值至少具有零类型关系。因此,会返回像 "some comment about typo" 这样的值,因为尽管它从未作为主题出现在您的数据中,但它确实是一个与其他事物具有零类型关系的值。