gpt4 book ai didi

sparql - 为什么这个 SPARQL 查询返回某些项目作为主题?

转载 作者:行者123 更新时间:2023-12-04 10:10:28 25 4
gpt4 key购买 nike

我有以下数据图:

@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 ”。

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

关于sparql - 为什么这个 SPARQL 查询返回某些项目作为主题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61352612/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com