SPARQL选择剩余的三元组

问题描述

我有一个带有数据的RDF图,使用不同的本体(例如VCARD和FOAF)来描述数据。

现在,为了简化查询,我想构建一个新图,在其中将一个本体映射到另一个本体上,以便将数据描述在一个本体中。

我已经找到了映射部分,但是我正在寻找的是一种选择“剩余三元组”的方法,即已经存在于正确本体中的那些 (因为映射后这些值应保持不变)。

我认为应该有一种通过否定来做到这一点的方法,但我似乎无法弄清楚。

例如,假设我有以下RDF图:

@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix vcard: <http://www.w3.org/2006/vcard/ns#> .
@base <http://example.org/>

<somePerson>
    a foaf:Person .
<someOtherPerson>
    a vcard:Individual .
# [Some more triples]

我想将其映射到:

@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@base <http://example.org/>

<somePerson>
    a foaf:Person .
<someOtherPerson>
    a foaf:Person.
# [Some more triples]

无需使用VCARD即可描述数据。

从第一个到第二个的映射足够简单,但是我正在寻找一种简单的方法来保持其他三元组不变。 (基本上将它们复制到输出中。)

解决方法

按照@UninformedUser的建议,此查询结构将解决问题。

prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix vcard: <http://www.w3.org/2006/vcard/ns#>
CONSTRUCT {
    ?name rdf:type foaf:Person .
    ?x ?y ?z .
}
WHERE {
    {
        {
            ?x ?y ?z .
        }
        FILTER NOT EXISTS
        {
            ?x rdf:type vcard:Individual .
        }
    }
    UNION
    {
        ?name rdf:type vcard:Individual .
    }
}

要从这里去:

@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix vcard: <http://www.w3.org/2006/vcard/ns#> .
@base <http://example.org/>

<somePerson>
    a foaf:Person .
<someOtherPerson>
    a vcard:Individual .
[Some more triples]

到这里:

@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@base <http://example.org/>

<somePerson>
    a foaf:Person .
<someOtherPerson>
    a foaf:Person.
[Some more triples]