问题
I dabbled with DBpedia
a couple of years ago and find it fascinating, but now that I want to perform a query after not using it for ages, I find it totally impenetrable.
What SPARQL
query should I issue to retrieve the set of all Wikipedia pages that are members of both "Category ABC" and "Category XYZ"?
All of the examples I can find seem to be quite a bit more involved than my seemingly basic question, making it difficult to distil something minimal.
(As an example I'd like to find all Australian players that have played professional football for Italian teams.)
回答1:
The link between resources and categories is represented using the dcterms:subject
relation (as you can see if you go, for example, to the DBPedia representation for Elvis Presley).
So to query for all resources that belong to two categories (e.g. "American male singers" and "identical twins"), simply do this:
SELECT ?res
WHERE {
?res dcterms:subject category:American_male_singers, category:Identical_twins .
}
In general, when trying to formulate SPARQL queries over DBPedia, it helps to browse around a bit first (like I did by looking at the Elvis page), to try and figure out which properties and relations are available.
Edit The above query, by the way, retrieves the DBPedia resources themselves. If you want to get the actual Wikipedia pages, you should adapt your query like so:
SELECT ?wikiPage
WHERE {
?res dcterms:subject category:American_male_singers, category:Identical_twins ;
foaf:page ?wikiPage .
}
来源:https://stackoverflow.com/questions/11292152/how-to-find-all-wikipedia-pages-which-are-members-two-given-categories-using-dbp