【问题标题】:How to use logical OR in SPARQL regex()?如何在 SPARQL regex() 中使用逻辑 OR?
【发布时间】:2011-03-17 08:52:45
【问题描述】:

我在我的 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 元素元组来填充 %ss。

【问题讨论】:

    标签: python regex filter sparql


    【解决方案1】:

    这个怎么样?

    SELECT ?thing
    WHERE {
      { 
        ?thing x:name ?name .
        FILTER regex(?name, "%s", "i" )
      } UNION {
        ?thing x:featurename ?name .
        FILTER regex(?featurename, "%s", "i" )
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2017-11-23
      • 1970-01-01
      • 2013-10-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-30
      • 2012-01-12
      • 2019-08-30
      相关资源
      最近更新 更多