Chris Stryczynski
Chris Stryczynski

Reputation: 34001

What SPARQL term can I use to reference a Wikipedia category

I'm trying to extract a list of articles from a specific category in Wikipedia. I'm trying to accomplish this via DBpedia. However, I can't actually find the specific 'term' or 'field' to reference a 'category'. Where is this documented?

The section 4.2. Classifications following section from the DBpedia documentation has a link to the DCMI vocabulary, but I do not see any relevant 'field' or 'term' for category.

Upvotes: 2

Views: 140

Answers (1)

Joshua Taylor
Joshua Taylor

Reputation: 85883

Use dcterms:subject

When working with DBpedia, it's almost always easier to browse some data first and then figure out how to the write the query. For instance, in this case, you can take a look at dbpedia:Mount_Monadnock. You'll see that it's related by the dcterms:subject property to four categories:

  • category:Landforms_of_Cheshire_County,_New_Hampshire
  • category:Monadnocks
  • category:Mountains_of_New_Hampshire
  • category:National_Natural_Landmarks_in_New_Hampshire

If you look at the links that those point to, you'll see the right URIs, e.g.,

  • http://dbpedia.org/resource/Category:Mountains_of_New_Hampshire

Now, if you're looking at the DBpedia SPARQL Endpoint web interface, you'll see a Namespace Prefixes link in the top right, which will show you the predefined (when you're working with the web interface) prefix:

  • category: http://dbpedia.org/resource/Category:

Thus, you could use a query like this to get a list of articles in the Mountains of New Hampshire category:

select ?article {
  ?article dcterms:subject category:Mountains_of_New_Hampshire
}

SPARQL results

What the DBpedia documentation says

The link to the documentation in the question points to

4.2. Classifications

… Wikipedia Categories are represented using the SKOS vocabulary and DCMI terms.

As we've seen, the dcterms:subject property is used to link articles to their categories. The SKOS vocabulary is used to connect categories. E.g., skos:broader is used to connect subcategories and supercategories. I agree that the documentation does not give quite as much information as one might expect, but this might be forgivable since the data is easy enough to browse (and the properties are described in the documentation on those vocabularies).

Related

It's a bit more specific, and would have been hard to search for if I didn't already know what to look for, but this question and answer helps:

This is also helpful:

Upvotes: 4

Related Questions