[英]Get nationality of person using DBPedia and SPARQL
I have the following SPARQL query: 我有以下SPARQL查询:
SELECT ?nationalityLabel WHERE {
dbpedia:Henrik_Ibsen dbpedia-owl:nationality ?nationality .
?nationality rdfs:label ?nationalityLabel .
}
I have checked that Henrik Ibsen exists and that he has the nationality ontology/property on him: http://dbpedia.org/page/Henrik_Ibsen 我已经检查过Henrik Ibsen存在并且他有他的国籍本体/财产: http : //dbpedia.org/page/Henrik_Ibsen
And this is an ontology: http://dbpedia.org/ontology/nationality 这是一个本体论: http : //dbpedia.org/ontology/nationality
A very similar query to this listed here works: https://stackoverflow.com/a/10248653/1680130 与此处列出的非常类似的查询有效: https : //stackoverflow.com/a/10248653/1680130
The problem I have is that the query doesn't return any result. 我遇到的问题是查询不返回任何结果。
If I could get help solving this it would be great. 如果我能得到帮助解决这个问题就会很棒。
Summarized solution: Both answers were great so upvote to both but landed on Joshua's in the end because informing about dbpedia-owl being cleaner. 总结解决方案:这两个答案都非常好,所以对两者都赞不绝口,但最终落到了Joshua上,因为通知dbpedia-owl更干净。 Optimal solution in my opinion:
我认为最佳解决方案:
First check with dbpedia-owl for birth-place: 首先用dbpedia-owl检查出生地:
select ?label {
dbpedia:Henrik_Ibsen
dbpedia-owl:birthPlace
[ a dbpedia-owl:Country ;
rdfs:label ?label ]
filter langMatches(lang(?label),"en")
}
If found then get the demonym: 如果找到则获得恶魔:
select ?label {
dbpedia:Norway dbpedia-owl:demonym ?label
filter langMatches(lang(?label),"en")
}
If above fails then do the "dirty" query: 如果上面的失败,那么执行“脏”查询:
SELECT
?nationality
WHERE {
dbpedia:Henrik_Ibsen dbpprop:nationality ?nationality .
filter langMatches(lang(?nationality),"en")
}
Of course is "dirty" means data being correct but not so often present the order might be better other way around because people can be born in a country but from a different. 当然,“脏”意味着数据是正确的,但不常见的是,订单可能更好地反过来,因为人们可以出生在一个国家,但来自不同的国家。
Kristian's answer is right that the property is dbpprop:nationality
that Henrik Ibsen has. 克里斯蒂安的回答是正确的,该财产是
dbpprop:nationality
亨利克易卜生拥有的dbpprop:nationality
。 You're right that there is a dbpedia-owl:nationality
property, too, but Henrik Ibsen doesn't have a value for it, unfortunately. 你是对的,有一个
dbpedia-owl:nationality
属性,但不幸的是,Henrik Ibsen没有它的价值。 The value of dbpprop:nationality
that Henrik Ibsen has, though, is a string, which is a literal, and literals cannot be the subjects of triples in RDF, so ?nationality rdfs:label ?nationalityLabel
in your query will never match. 但是,Henrik Ibsen所拥有的
dbpprop:nationality
的值是一个字符串,它是一个字面值,并且文字不能成为RDF中三元组的主语,所以你的查询中的?nationality rdfs:label ?nationalityLabel
永远不会匹配。
The DBpedia ontology data ( dbpedia-owl
) tends to be cleaner than the dbpprop
data, so you might prefer a solution using dbpedia-owl
properties that Henrik Ibsen does have. DBpedia本体数据(
dbpedia-owl
)往往比dbpprop
数据更清晰,因此您可能更喜欢使用Henrik Ibsen确实具有的dbpedia-owl
属性的解决方案。 In this case, you might look to the dbpedia-owl:birthPlace
. 在这种情况下,您可以查看
dbpedia-owl:birthPlace
。 Then you could get the name the country of the birth places: 然后你可以得到出生地的国家名称:
select ?label {
dbpedia:Henrik_Ibsen
dbpedia-owl:birthPlace
[ a dbpedia-owl:Country ;
rdfs:label ?label ]
}
You might want to narrow the permissible languages: 您可能希望缩小允许的语言范围:
select ?label {
dbpedia:Henrik_Ibsen
dbpedia-owl:birthPlace
[ a dbpedia-owl:Country ;
rdfs:label ?label ]
filter langMatches(lang(?label),"en")
}
Those queries will produce the name of the country, but it wanted the corresponding demonym , you can get the dbpedia-owl:demonym
value of the country, if it's available. 这些查询会产生国家的名字,但它想对应的区域居民称谓词 ,你可以得到
dbpedia-owl:demonym
国的价值,如果它是可用的。 It's probably best to make the demonym optional, since a cursory investigation suggests that lots of countries in DBpedia don't have a value for it, so the name of the country may be the only option. 可能最好使该恶魔是可选的,因为粗略的调查表明DBpedia中的许多国家没有它的价值,因此该国家的名称可能是唯一的选择。 Eg,
例如,
select ?name ?demonym {
dbpedia:Henrik_Ibsen dbpedia-owl:birthPlace ?country .
?country a dbpedia-owl:Country ; rdfs:label ?name .
optional { ?country dbpedia-owl:demonym ?demonym }
filter langMatches(lang(?name),"en")
filter langMatches(lang(?demonym),"en")
}
Two things are wrong with the query: 查询有两个问题:
dbprop:nationality
value is a literal, which cannot be used as a subject resource, therefore, there will never be a label for dbpprop:nationality
. dbprop:nationality
值是一个文字,不能用作主题资源,因此,永远不会有dbpprop:nationality
的标签。 Instead, where the data exists, you would use dbpedia-owl:nationality
, which you did originally. dbpedia-owl:nationality
。 it just so happens that Henrik_Ibsen has no dbpedia-owl:nationality
value associated with him* dbpedia-owl:nationality
价值* Updated query (updated). 更新了查询(更新)。
SELECT
#### ?label #### See Edit
?nationality
WHERE {
dbpedia:Henrik_Ibsen dbpprop:nationality ?nationality .
#### OPTIONAL { ?nationality rdfs:label ?label . } #### See Edit.
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.