为什么这个 SPARQL 查询返回某些项目作为主题? [英] Why does this SPARQL query return certain items as subjects?

查看:47
本文介绍了为什么这个 SPARQL 查询返回某些项目作为主题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下数据图:

@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.作为证明,当我运行查询时:

The only subjects defined in the triples are hr:Another, hr:Employee, hr:Longer, hr:freestanding, hr:missing, hr:name, hr:nosuper, hr:randomtype, and hr:typo. As proof, when I run the query:

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 查询:

However, if I execute this SPARQL query:

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 等项目在数据图中不是主题时作为主题返回.

I am not sure why items like rdf:Property, "a good employee", sch:Text, etc. are being returned as subjects when they are not subjects in the data graph.

为什么是他们?

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

Clearly, this has something to do with how SPARQL handles property paths which I do not yet understand.

推荐答案

您正在使用带有零个或多个通配符 ('*') 的属性路径.实际上,模式 ?s rdf:type* ?o 意味着每个值 ?s 通过零个或多个类型关系连接到任何值 ?o>".

You are using a property path with a zero-or-more wildcard ('*'). Effectively, the pattern ?s rdf:type* ?o means "every value ?s connected through zero or more type relations to any value ?o".

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

Every value that appears in your graph (in fact every value in any graph) matches that, because every value has at least zero type relations. Therefore, a value like "some comment about typo" get returned, because although it never occurs as a subject in your data, it is true that it is a value that has zero type relations to something else.

这篇关于为什么这个 SPARQL 查询返回某些项目作为主题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆