目前,我在Dbpedia上使用SPARQL(使用Virtuoso服务器)时,遇到了Unicode解码问题的行。这是我得到Knut%C3%85ngstr%C3%B6m的示例。正确的名称是KnutÅngström。酷,现在我该如何解决?我精心设计的查询是:
select distinct (strafter(str(?influencerString),str(dbpedia:)) as ?influencerString) (strafter(str(?influenceeString),str(dbpedia:)) as ?influenceeString) where {
{ ?influencer a dbpedia-owl:Person . ?influencee a dbpedia-owl:Person .
?influencer dbpedia-owl:influenced ?influencee .
bind( replace( str(?influencer), "_", " " ) as ?influencerString )
bind( replace( str(?influencee), "_", " " ) as ?influenceeString )
}
UNION
{ ?influencee a dbpedia-owl:Person . ?influencer a dbpedia-owl:Person .
?influencee dbpedia-owl:influencedBy ?influencer .
bind( replace( str(?influencee), "_", " " ) as ?influenceeString )
bind( replace( str(?influencer), "_", " " ) as ?influencerString )
}
}
DBpedia Wiki解释说,英语DBpedia数据集中的资源标识符使用URI,而不是IRI,这意味着您最终会遇到这样的编码问题。
3.命名或命名“事物”
DBpedia数据集中的每件事都由形式为http://dbpedia.org/resource/Name的可取消引用的基于IRI或URI的引用表示,其中Name是从源Wikipedia文章的URL派生的。格式为http://en.wikipedia.org/wiki/Name。因此,每个DBpedia实体都直接与Wikipedia文章联系在一起。每个DBpedia实体名称都解析为面向描述的Web文档(或Web资源)。
在DBpedia版本3.6之前,我们仅使用英语维基百科中的文章名称,但是从DBpedia版本3.7开始,我们还提供了包含IRI的本地化数据集,例如http://xx.dbpedia.org/resource/Name,其中xx是维基百科的语言代码和名称取自源URL http://xx.wikipedia.org/wiki/Name。
从DBpedia 3.8版开始,我们将IRI用于大多数DBpedia实体名称。IRI更具可读性,并且通常比URI更可取,但是为了向后兼容,我们仍然将URI用于从英语维基百科中提取的DBpedia资源,并将IRI用于所有其他语言。Turtle文件中的三元组对所有语言(甚至英语)都使用IRI。
有关URI编码的一些详细信息应始终予以考虑。
在这种特殊情况下,看起来您实际上不需要拆开标识符就可以为实体获取标签。
## If things were guaranteed to have just one English label,
## we could simply take ?xLabel as the value that we want with
## `select ?xLabel { … }`, but since there might be more than
## one, we can group by `?x` and then take a sample from the
## set of labels for each `?x`.
select (sample(?xLabel) as ?label) {
?x dbpedia-owl:influenced dbpedia:August_Kundt ;
rdfs:label ?xLabel .
filter(langMatches(lang(?xLabel),"en"))
}
group by ?x
我们可以简化一下您的查询:
select
(sample(?rLabel) as ?influencerName)
(sample(?eLabel) as ?influenceeName)
where {
?influencer dbpedia-owl:influenced|^dbpedia-owl:influencedBy ?influencee .
dbpedia-owl:Person ^a ?influencer, ?influencee .
?influencer rdfs:label ?rLabel .
filter( langMatches(lang(?rLabel),"en") )
?influencee rdfs:label ?eLabel .
filter( langMatches(lang(?eLabel),"en") )
}
group by ?influencer ?influencee
如果您不希望在这些结果上使用语言标签,请添加一个调用str()
:
select
(str(sample(?rLabel)) as ?influencerName)
(str(sample(?eLabel)) as ?influenceeName)
where {
?influencer dbpedia-owl:influenced|^dbpedia-owl:influencedBy ?influencee .
dbpedia-owl:Person ^a ?influencer, ?influencee .
?influencer rdfs:label ?rLabel .
filter( langMatches(lang(?rLabel),"en") )
?influencee rdfs:label ?eLabel .
filter( langMatches(lang(?eLabel),"en") )
}
group by ?influencer ?influencee
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句