Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
524 views
in Technique[技术] by (71.8m points)

rdf - Retrieving a DBpedia resource by its string name with SPARQL

I am trying to get the resource describing country Romania by the country name with this query:

PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX : <http://dbpedia.org/resource/>

SELECT DISTINCT ?x WHERE {
     ?x foaf:name 'Romania'
}

SPARQL results

However, it does not retrieve anything. How can I get the resource http://dbpedia.org/resource/Romania (:Romania) by the string 'Romania'. If I want to retrieve the name of the country by the country resource I use the following query which works fine:

PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX : <http://dbpedia.org/resource/>

SELECT DISTINCT ?x WHERE {
     :Romania foaf:name ?x
}

SPARQL results

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This ought to do it:

SELECT ?c
WHERE {
  ?c a dbo:Country ;
     foaf:name "Romania"@en .
  FILTER NOT EXISTS { ?c dbo:dissolutionYear ?y }
}

SPARQL results

The critical quirk here is that "Romania" with no language tag is different from "Romania"@en. And then you also have a bunch of historical states that were also called Romania, so we filter out any of those that have years of dissolution. DBpedia's data-completeness for years of dissolution isn't terrific, but all the Romanian ones, at least, are marked.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...