Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use logical OR in SPARQL regex()?

I'm using this line in a SPARQL query in my python program:

FILTER regex(?name, "%s", "i" )

(where %s is the search text entered by the user)

I want this to match if either ?name or ?featurename contains %s, but I can't seem to find any documentation or tutorial for using regex(). I tried a couple things that seemed reasonable:

FILTER regex((?name | ?featurename), "%s", "i" )
FILTER regex((?name || ?featurename), "%s", "i" )
FILTER regex((?name OR ?featurename), "%s", "i" )
FILTER regex((?name, ?featurename), "%s", "i" )

and each of those without the ()

FILTER regex(?name, "%s", "i" ) || regex(?featurename, "%s", "i" )

What's the right way to do this? Thanks

UPDATE: Using UNION works. But I figured out that it also works if you just repeat the regex() part like so:

FILTER (regex(?name, "%s", "i") || regex(?featurename, "%s", "i" ))

Both solutions seem a little messy in that you have to use a 2-element tuple with copies of the same string to fill in both %ss.

like image 978
jefdaj Avatar asked Jul 17 '10 15:07

jefdaj


1 Answers

What about this?

SELECT ?thing
WHERE {
  { 
    ?thing x:name ?name .
    FILTER regex(?name, "%s", "i" )
  } UNION {
    ?thing x:featurename ?name .
    FILTER regex(?featurename, "%s", "i" )
  }
}
like image 106
glenn mcdonald Avatar answered Nov 09 '22 00:11

glenn mcdonald