问题描述
我正在尝试查询dpbedia,以使用Jena和ARQ获得一些维基百科文章的类别.
例如:
I'm trying to query dpbedia to get the categories of some wikipedia articles using Jena and ARQ
For example:
select ?category { dbpedia:ARTICLE_NAME dcterms:subject ?category }
以下是有效查询的示例
SPARQL结果
Here is an example of a working query
SPARQL results
问题是当ARTICLE_NAME中有特殊字符时,例如"Parma_F.C.",其中有.".
The problem is when there are special characters in ARTICLE_NAME for example "Parma_F.C.", where there is "."
select ?category { dbpedia:Parma_F.C. dcterms:subject ?category }
所以,我想问你是否有人对此有解决方案.
预先感谢
So, I would like to ask you if someone had a solution for that.
Thanks in advance
推荐答案
标识符 dbpedia:Parma_F.C.
是所谓的前缀名称,即,完整URI的缩写形式.有关完整的语法规则,请参见 SPARQL 1.1查询语言规范.
The identifier dbpedia:Parma_F.C.
is a so-called prefixed name, that is, an abbreviated form of a full URI. The full syntax rules for it are described in the SPARQL 1.1 Query Language specification.
问题特别是前缀名称末尾的句号.根据SPARQL语法,带前缀的名称除非经过转义,否则不能以句号结尾.解决方法只是使用反斜杠:
The problem is specifically the full stop at the end of the prefixed name. According to the SPARQL grammar, a prefixed name cannot end on a full stop unless it's escaped. The fix is simply to use a backslash:
dbpedia:Parma_F.C\.
您还可以选择替代方法,就是写出完整的URI. dbpedia
前缀映射到 http://dbpedia.org/resource/
命名空间,因此SPARQL中的完整URI将变为:
What you can also do as an alternative, is just write out the full URI. The dbpedia
prefix maps to the http://dbpedia.org/resource/
namespace, so the full URI in SPARQL would become:
<http://dbpedia.org/resource/Parma_F.C.>
,完整的查询将变为:
select ?category { <http://dbpedia.org/resource/Parma_F.C.> dcterms:subject ?category }
这篇关于在SPARQL查询中转义特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!