如何在 SPARQL regex() 中使用逻辑 OR?
我在 python 程序的 SPARQL 查询中使用这一行:(
FILTER regex(?name, "%s", "i" )
其中 %s
是用户输入的搜索文本)
我希望它匹配 ?name
或 ?featurename
包含 %s
,但我似乎找不到任何使用 regex() 的文档或教程。我尝试了一些看起来合理的事情:
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" )
并且每一个都没有 ()
FILTER regex(?name, "%s", "i" ) || regex(?featurename, "%s", "i" )
这样做的正确方法是什么? 谢谢
更新:使用 UNION 有效。但我发现,如果你只是像这样重复 regex() 部分,它也可以工作:
FILTER (regex(?name, "%s", "i") || regex(?featurename, "%s", "i" ))
两种解决方案似乎都有点混乱,因为你必须使用带有相同字符串副本的 2 元素元组来填充两个 %s。
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 %s
s.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这又如何呢?
What about this?