开发者

How to use logical OR in SPARQL regex()?

开发者 https://www.devze.com 2023-01-07 13:04 出处:网络
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'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开发者_如何学JAVA 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.


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" )
  }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号