根据“三元组不存在”选择使用 sparql;

发布于 2024-11-30 03:04:06 字数 398 浏览 9 评论 0原文

我需要一点帮助从我的商店中选择正确的三元组...

<a> a <type/1> .
<b> a <type/1> .
<c> a <type/1> .
<c> a <type/2> .

我只想选择 type/1 而不是 type/2 的元素

使用 sparql select 查询实现此目的的最佳方法是什么?

我正在寻找类似的东西:

select ?a where 
{ 
    ?a a <type/1> .
    !{ ?a a <type/2> }
}

谢谢,

:)

I need a little help selecting the right triples from my store....

<a> a <type/1> .
<b> a <type/1> .
<c> a <type/1> .
<c> a <type/2> .

i want to select only elements which are type/1 and not type/2

What is the best way to achieve this using a sparql select query?

am looking for omething like:

select ?a where 
{ 
    ?a a <type/1> .
    !{ ?a a <type/2> }
}

Thanks,

:)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不即不离 2024-12-07 03:04:06

另一种 SPARQL 1.1 解决方案是使用 MINUS,例如

SELECT ?a
WHERE
{
  ?a a <type/1> .
  MINUS { ?a a <type/2> . }
}

MINUS 从现有匹配中减去与其三重模式匹配的解决方案。

在大多数情况下,使用 FILTER NOT EXISTS { }MINUS { } 是等效的,但要注意在某些极端情况下情况并非如此 - 请参阅 SPARQL 1.1 规范 了解一些示例。

An alternative SPARQL 1.1 solution is to use MINUS e.g.

SELECT ?a
WHERE
{
  ?a a <type/1> .
  MINUS { ?a a <type/2> . }
}

MINUS subtracts solutions that match its triple pattern from the existing matches.

In most cases using FILTER NOT EXISTS { } and MINUS { } are equivalent but beware there are some corner cases where this is not true - see the SPARQL 1.1 specification for some examples of this.

千笙结 2024-12-07 03:04:06

在 SPARQL 1.0 中,这有点棘手:

SELECT ?a WHERE {
    ?a a <type/1>.
    OPTIONAL {
        ?a a ?othertype .
        FILTER (?othertype = <type/2>)
    }
    FILTER (!BOUND(?othertype))
}

OPTIONAL 子句为任何具有 ?a 绑定 ?othertype,并且对于任何没有它的 ?a 使其保持未绑定状态。

然后,最终的FILTER 仅选择 ?a 未绑定的那些行。

在 SPARQL 1.1 中更容易:

SELECT ?a WHERE {
    ?a a <type/1>.
    FILTER NOT EXISTS { ?a a <type/2> . }
}

In SPARQL 1.0 that's a bit tricky:

SELECT ?a WHERE {
    ?a a <type/1>.
    OPTIONAL {
        ?a a ?othertype .
        FILTER (?othertype = <type/2>)
    }
    FILTER (!BOUND(?othertype))
}

The OPTIONAL clause binds ?othertype for any ?a that has <type/2>, and leaves it unbound for any ?a that doesn't have it.

The final FILTER then selects only those rows where ?a was left unbound.

In SPARQL 1.1 it's much easier:

SELECT ?a WHERE {
    ?a a <type/1>.
    FILTER NOT EXISTS { ?a a <type/2> . }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文