Find lists containing ALL values ​​in a set?

How can I find lists containing each set of elements in SPARQL? Let's say I have this data:

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

How can I find items whose lists contain both "new" and "York"? Does the following SPARQL not work as the filter works with every binding ? T , not with a set of all of them.

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

SELECT ?s ?p WHERE {       
    ?s <http://foo.org/name>/rdf:rest*/rdf:first ?t 
    FILTER( ?t = "new" && ?t = "york")   
}
+4
source share
1 answer

Search for lists with multiple required values

, , . ? S, ? List, , , . values ​​.

prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

select ?s {
  ?s <http://foo.org/name> ?list .
  filter not exists {                   #-- It 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                      |
==========================
| <http://foo.org/test2> |
--------------------------

, , , . , "" "york" . "" "york" . (? T = "new" ||? T = "york" ) : (? t in ( "", "" )). :

prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

select ?s ?t {
  ?s <http://foo.org/name>/rdf:rest*/rdf:first ?t .
  filter(?t in ("new","york"))
}
-----------------------------------
| s                      | t      |
===================================
| <http://foo.org/test2> | "new"  |
| <http://foo.org/test2> | "york" |
| <http://foo.org/test>  | "new"  |
-----------------------------------
+5

Source: https://habr.com/ru/post/1626091/


All Articles