sparql virtuoso bif:contains 在一个联合中

sparql virtuoso bif:contains in a union

我正在尝试使用 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 中的一个子句,则查询有效。请问有什么建议吗?

您的查询拆分错误。 UNION 的每一部分都必须是一个完整的模式。看我的 query and 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

简单的你可以这样使用:

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