查找包含集合中所有值的列表?

编程入门 行业动态 更新时间:2024-10-28 18:34:54
本文介绍了查找包含集合中所有值的列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何在 SPARQL 中找到包含一组项目中的每一个的列表?假设我有这些数据:

How can I find lists that contain each of a set of items in SPARQL? Let's say I have this data:

<foo/test> <foo/name> ( "new" "fangled" "thing" ) . <foo/test2> <foo/name> ( "new" "york" "city" ) .

如何找到列表中同时包含new"和york"的项目?下面的 SPARQL 不起作用,因为 filter 作用于 ?t 的每个绑定,而不是它们的集合.

How can I find the items whose lists contain both "new" and "york"? The following SPARQL doesn't work, since filter works on each binding of ?t, not the set of all of them.

PREFIX rdf: <www.w3/1999/02/22-rdf-syntax-ns#> SELECT ?s ?p WHERE { ?s <foo/name>/rdf:rest*/rdf:first ?t FILTER( ?t = "new" && ?t = "york") }

推荐答案

查找具有多个必需值的列表

如果您要查找包含all 多个值的列表,则需要使用更复杂的查询.此查询查找所有具有 ?list 值的 ?s 值,然后过滤掉那些不是一个词是 不在列表中.单词列表是使用 values 块指定的.

Finding lists with multiple required values

If you're looking for lists that contain all of a number of values, you'll need to use a more complicated query. This query finds all the ?s values that have a ?list value, and then filters out those where there is not a word that is not in the list. The list of words is specified using a values block.

prefix rdf: <www.w3/1999/02/22-rdf-syntax-ns#> select ?s { ?s <foo/name> ?list . filter not exists { #-- It's not the case values ?word { "new" "york" } #-- that any of the words filter not exists { #-- are not ?list rdf:rest*/rdf:first ?word #-- in the list. } } }

-------------------------- | s | ========================== | <foo/test2> | --------------------------

在列表中查找替代字符串

另一方面,如果您只是想搜索多个选项中的一个,那么您使用的是正确的属性路径,但您得到了错误的过滤器表达式.您希望字符串等于new"或york".没有字符串同时等于new"和york".您只需要执行 filter(?t = "new" || ?t = "york") 或更好地使用 in: filter(?t in ("new", "york")).这是一个带有结果的完整示例:

Find alternative strings in a list

On the other hand, if you're just trying to search for one of a number of options, you're using the right property path, but you've got the wrong filter expression. You want strings equals to "new" or "york". No string is equal to both "new" and "york". You just need to do filter(?t = "new" || ?t = "york") or better yet use in: filter(?t in ("new", "york")). Here's a full example with results:

prefix rdf: <www.w3/1999/02/22-rdf-syntax-ns#> select ?s ?t { ?s <foo/name>/rdf:rest*/rdf:first ?t . filter(?t in ("new","york")) }

----------------------------------- | s | t | =================================== | <foo/test2> | "new" | | <foo/test2> | "york" | | <foo/test> | "new" | -----------------------------------

更多推荐

查找包含集合中所有值的列表?

本文发布于:2023-10-14 11:28:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1490942.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:列表

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!