0

I'd like to know the number of subjects having a certain property.

For instance I'd like to know how many subjects having the trainer property: http://dbpedia.org/ontology/trainer

A somewhat related answer is this: https://stackoverflow.com/a/21729888/1680130

There I can change the query to get a list of subjects for a single property. But I simply would like to have a count of the subjects for the given property.

Community
  • 1
  • 1
Marius Lian
  • 523
  • 7
  • 15
  • 3
    I've notices that you've asked a number of relatively simple questions in a short period of time. While they're specific enough to be answerable, be aware that users may downvote questions if they appear to lack research effort, and that it's not all that hard to trigger a question ban if you have a number of downvoted questions in a short amount of time. – Joshua Taylor Nov 19 '14 at 11:47
  • I'd suggest that you spend a bit of time looking at [SPARQL 1.1 Query Language](http://www.w3.org/TR/sparql11-query/). The language is very well documented, and there are examples in there, too. – Joshua Taylor Nov 19 '14 at 11:49
  • I hate reading standards but I love to learn by Q&A - both reading answers to questions by others but also asking myself. The reason why I ask quite simple questions here is 1) because I am new to SPARQL and 2) there is not so many Q&A's for SPARQL yet compared to other languages. For python or JS all basic questions are already asked. – Marius Lian Nov 20 '14 at 21:50
  • 1
    Clear questions and answers can certainly be helpful, but reading standards is an important skill for any programmer. However, most standards shouldn't be read front-to-back, but skimmed initially so that you've got an idea what's there. Then you can revisit when you have specific questions. Stack Overflow is designed for professional and enthusiast programmers, and people may react negatively to users who don't appear enthusiastic enough to do that bit of research. It can come across as saying "your time is less valuable than mine, so read the manuals for me and tell me how to do this." – Joshua Taylor Nov 20 '14 at 21:53
  • I think it would be very strange to down vote like you say. The whole point of Q&A sites is that over time they end up as documentation of for instance a query language. It doesn't make sense then that some questions are too "stupid" or basic. What should be down voted is questions already answered - not questions that you could have found with some research. – Marius Lian Nov 20 '14 at 21:56
  • Questions that have already been answered shouldn't necessarily be downvoted; often times they can provide additional pointers to the canonical answer. That's especially important for questions where the problem may be "if I only knew what term to search for..." – Joshua Taylor Nov 20 '14 at 21:58
  • At any rate, this is turning into a meta-discussion, and you could certainly bring it up on meta.SE, where more users could chime in. I think that [How much research effort is expected of Stack Overflow users?](http://meta.stackoverflow.com/q/261592/1281433) might be a good starting point. – Joshua Taylor Nov 20 '14 at 21:59
  • Don't see any point in bringing a discussion I did not start there ;-) Anyway, I will read/skim the specification as you suggest and thanks for this and other answers, I really appreciate it. I can't promise I won't ask simple questions in the future though. I stand by my opinion that questions that are not asked could and should be asked. – Marius Lian Nov 20 '14 at 22:25
  • Community standards have leaned toward the principle that answers that can be easily found in the documentation (and that's subjective; sometimes the documentation isn't obvious, or depends on some interpretation) don't need to be asked. See http://meta.stackexchange.com/q/208372/225437. – Joshua Taylor Nov 21 '14 at 03:39

1 Answers1

4

This is a pretty simple query. You want to use the count aggregate mentioned in §11 Aggregates, and described in more detail in §18.5.1.2 Count.

select (count(distinct ?s) as ?nThingsWithTrainer) {
  ?s dbpedia-owl:trainer []
}

SPARQL Results

In general, it's a good idea to at least skim over the standard, SPARQL 1.1 Query Language. You don't need to memorize every bit of it, but if you take a glance at it, you'll see lots of examples, and you'll have a good idea what's actually in the language, and know where to look.

Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353