【问题标题】:sparql virtuoso bif:contains in a unionsparql virtuoso bif:包含在一个联合中
【发布时间】:2017-05-30 14:55:07
【问题描述】:

我正在尝试使用 Virtuoso 支持的 bif:contains 关系编写一个 SPARQL 查询来执行轻量级字符串匹配。我想检查标签是否包含单词 A 或 B,所以我使用 union 如下:

SELECT DISTINCT ?s ?o WHERE {
?s <http://www.w3.org/2000/01/rdf-schema#label> ?o . 
{?o bif:contains "Ramji"} 
union {?o bif:contains "Manjhi"}.
}

但是,这不会编译并引发错误:

Virtuoso 37000 Error SP031: SPARQL compiler: The group does not contain 
triple pattern with '$o' object before bif:contains() predicate

SPARQL query:
define sql:big-data-const 0 
#output-format:text/html
define sql:signal-void-variables 1 SELECT DISTINCT ?s ?o WHERE {
?s <http://www.w3.org/2000/01/rdf-schema#label> ?o . 
{?o bif:contains "Ramji"} 
union {?o bif:contains "Manjhi"}.
}

如果只使用union 中的一个子句,则查询有效。请问有什么建议吗?

【问题讨论】:

    标签: sparql virtuoso


    【解决方案1】:

    您的查询在错误的位置拆分。 UNION 的每个部分都必须是一个完整的模式。见我的query 和results —

    SELECT DISTINCT ?s ?o 
       WHERE 
          {
             {
                ?s  <http://www.w3.org/2000/01/rdf-schema#label>  ?o      . 
                ?o  bif:contains                                  "Ramji"
             } 
          UNION
             {
                ?s  <http://www.w3.org/2000/01/rdf-schema#label>  ?o      . 
                ?o  bif:contains                                  "Manjhi"
             }
          }
       ORDER BY ?s
    

    【讨论】:

      【解决方案2】:

      你可以这样使用:

      SELECT DISTINCT ?s ?o WHERE {
      ?s <http://www.w3.org/2000/01/rdf-schema#label> ?o . 
      ?o bif:contains "'Ramji' or 'Manjhi'"}
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多