How to find all titles including a certain word in SPARQL

27 Views Asked by At
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX leg: <http://www.legislation.gov.uk/def/legislation/>

SELECT *
WHERE {
  ?x leg:title ?y.
  FILTER(?y in ("Education Act 2002"))
}

With this query I can match on Education Act 2002 exactly, but I want to be able to match on it even if I just have the word "Education".

Any tips on how to do this?

1

There are 1 best solutions below

2
logi-kal On

The IN operator is used for searching in a list of values.

For string pattern matching you can use the REGEX function:

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX leg: <http://www.legislation.gov.uk/def/legislation/>

SELECT *
WHERE {
  ?x leg:title ?y.
  FILTER(regex(?y,"Education")) # this matches any string containing the word "Education"
}