如何在任意长度的sparql路径中使用Union/or? [英] how to use Union/or in sparql path with arbitrary length?

查看:127
本文介绍了如何在任意长度的sparql路径中使用Union/or?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下查询从DBPedia本体中查找具有城市域(或城市超类)或国家范围(或国家超类)的所有属性.当我使用固定长度的路径没有问题,但是当我输入 * 来定义任意长度的路径时,会出现以下错误:

I'm using below query to find all properties with domain of city (or superclasses of city) or range of country (or superclasses of country) from DBPedia ontology. when I use path with fixed length there is no problem but when I put * to define paths with arbitrary length, I get this error:

Virtuoso 37000错误SP031:SPARQL编译器:变量 '_ :: trans_subj_6_4'用于查询的子表达式,但不使用 分配

Virtuoso 37000 Error SP031: SPARQL compiler: Variable '_::trans_subj_6_4' is used in subexpressions of the query but not assigned

我的SPARQL:

define sql:signal-void-variables 1
define input:default-graph-uri <http://dbpedia.org>

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX res: <http://dbpedia.org/resource/>
PREFIX owl:<http://www.w3.org/2002/07/owl#>
PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>

select ?property where{
  { ?property rdfs:domain/^rdfs:subClassOf* dbo:City }
  UNION
  { ?property rdfs:range/^rdfs:subClassOf* dbo:Country } 
}

另外,当我输入任何数字而不是 * 时,也会出现相同的错误.我正在使用 Virtuoso 作为DBPedia SPARQL端点.

Also when I put any number instead of *, I get same error. I'm using Virtuoso as DBPedia SPARQL endpoint.

推荐答案

使用VALUES代替UNION(如果可以)

与实际的SPARQL查询相比,Virtuoso给您的错误更多地是关于它对属性路径和 union 的实现.查询的SPARQL部分看起来正确. (我无法与Virtuoso特定的定义交谈.)

Use VALUES instead of UNION (when you can)

The error Virtuoso is giving you is more about its implementation of property paths and union than the actual SPARQL query. The SPARQL part of the query looks correct. (I can't speak to the Virtuoso specific defines.)

在原始SPARQL标准中需要 union 的许多地方,您现在可以使用 values 来指定变量可以具有的特定值.它通常会导致更具可读性的查询(至少在我看来),并且某些端点(例如Virtuoso)似乎可以更好地处理它.

In many places that required union in the original SPARQL standard, you can now use values to specify the particular values that variables can have. It typically leads to more readable queries (at least, in my opinion), and some endpoints, such as Virtuoso, seem to handle it better.

使用(并使用端点的Web界面使用的 dbpedia-owl 前缀),您将查询以下内容,Virtuoso将返回您的内容寻找:

Using values (and using the dbpedia-owl prefix that the web interface to the endpoint uses), you query becomes the following, and Virtuoso returns what you're looking for:

select ?property where {
  values (?p ?v) { (rdfs:domain dbpedia-owl:City)
                   (rdfs:range dbpedia-owl:Country) }
  ?property ?p ?class  .
  ?class ^rdfs:subClassOf* ?v .
}

同样,当我输入任何数字而不是*时,也会出现相同的错误.我正在使用 Virtuoso作为DBPedia SPARQL端点.

Also when I put any number instead of *, I get same error. I'm using Virtuoso as DBPedia SPARQL endpoint.

尽管Virtuoso接受属性路径长度的{n,m}表示法,但请注意,尽管这些出现在属性路径的某些草稿中,但实际上并没有使其成为SPARQL 1.1标准. Virtuoso仍然接受它们,但是如果使用它们,则可能无法将查询与其他端点一起使用.

While Virtuoso accepts the {n,m} notation for lengths of property paths, do be aware that while those appeared in some drafts of property paths, they didn't actually make it into the SPARQL 1.1 standard. Virtuoso still accepts them, but if you use them, you might not be able to use your query with other endpoints.

这篇关于如何在任意长度的sparql路径中使用Union/or?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆