3

I am currently querying DBPedia for a list of person names by using the SPARQL package in R. And now I am working on counting of different categories for one person, such as the number of wikilink or external_link. But I only know to count all the items together per person, such as:

    query= "SELECT COUNT (*){
    <http://dbpedia.org/resource/Philipp_Melanchthon> ?p ?o 
    }"

This just print out the count of all the items for one person, is there any way to print out the count of different categories for one person respectively? Many thx.

Frown
  • 259
  • 1
  • 12
  • You're welcome. You can consider [accpting](http://stackoverflow.com/help/accepted-answer) the answer if your question has been answered. – Artemis May 29 '15 at 13:40

1 Answers1

4

As you pointed out the following query gives you all the relations and objects related to it:

SELECT distinct *{
    dbpedia:Philipp_Melanchthon ?p ?o.
}

If you want to find out the external links, you need to replace ?p with the appropriate property in this case dbpedia-owl:wikiPageExternalLink:

SELECT distinct *{
    dbpedia:Philipp_Melanchthon dbpedia-owl:wikiPageExternalLink ?o.
}

Thus count will give you the external links:

SELECT (count(?o)){
    dbpedia:Philipp_Melanchthon dbpedia-owl:wikiPageExternalLink ?o.
}
Artemis
  • 3,271
  • 2
  • 20
  • 33
  • Super! Thx, I really want to give u a vote, but I don't have enough reputation... – Frown May 29 '15 at 13:37
  • That last query isn't legal. It needs to be `select distinct (count(?o) as ?something) { ... }`. Then it will be legal, but still probably not right. There's only going to be one count, so **distinct** is useless here. It should probably be `select (count(distinct ?o) as ?something) { ... }`, so that you're counting distinct values of ?o, rather than picking distinct counts of ?o. – Joshua Taylor May 29 '15 at 13:37
  • Thanks Jashua, fixed it. – Artemis May 29 '15 at 13:38