可以遵循类型链来测试其终止位置吗?

问题描述 投票:1回答:1

假设我有以下内容:

@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 xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

hr:Employee a rdfs:Class .
hr:BadThree rdfs:comment "some comment about missing" .
hr:BadTwo a hr:BadOne .
hr:YetAnother a hr:Another .
hr:YetAnotherName a hr:AnotherName .
hr:Another a hr:Employee .
hr:AnotherName a hr:name .
hr:BadOne a hr:Dangling .
hr:name a rdf:Property .

并且我运行以下SPARQL查询:

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX sch:  <http://schema.org/>

SELECT DISTINCT ?s
WHERE {
    {
        ?s ?p ?o .
        FILTER NOT EXISTS {
            ?s a ?c .
            FILTER(?c IN (rdfs:Class, rdf:Property))
        }
    }
}

返回的结果将是:

----------------------------------------------------------------
| s                                                            |
================================================================
| <http://learningsparql.com/ns/humanResources#Another>        |
| <http://learningsparql.com/ns/humanResources#BadOne>         |
| <http://learningsparql.com/ns/humanResources#BadTwo>         |
| <http://learningsparql.com/ns/humanResources#YetAnother>     |
| <http://learningsparql.com/ns/humanResources#BadThree>       |
| <http://learningsparql.com/ns/humanResources#AnotherName>    |
| <http://learningsparql.com/ns/humanResources#YetAnotherName> |
----------------------------------------------------------------

我要返回的仅有两个结果是:

----------------------------------------------------------------
| s                                                            |
================================================================
| <http://learningsparql.com/ns/humanResources#BadOne>         |
| <http://learningsparql.com/ns/humanResources#BadTwo>         |
| <http://learningsparql.com/ns/humanResources#BadThree>       | 
----------------------------------------------------------------

什么使它们不好?如果我查看rdf:type信息,则类型链不会以rdfs:Class或rdf:Property的类型终止。

[如果我看hr:YetAnother,它的rd :: type为hr:Another。 hr:另一个具有hr:Employee的rdf:类型。因此,来自hr:YetAnother和hr:Another的类型链以rdfs:Class终止,并且它们不应由查询返回。

在我的示例中,类型链很小,但是链中可能会有更多链接,从而使它们更长。

是否可以使用SPARQL编写这样的查询?如果是这样,该查询将是什么?

sparql rdf rdfs turtle-rdf
1个回答
1
投票

解决此问题所需的SPARQL功能称为Property Paths

© www.soinside.com 2019 - 2024. All rights reserved.