W3C home > Mailing lists > Public > semantic-web@w3.org > November 2012

Re: Counting datatypes per property

From: Richard Cyganiak <richard@cyganiak.de>
Date: Thu, 8 Nov 2012 13:05:38 +0000
Cc: semantic-web@w3.org, Dominik Wienand <dominik.wienand@online.de>
Message-Id: <6408062B-F1BA-47B3-B242-2D19A5CDE31D@cyganiak.de>
To: Heiko Paulheim <paulheim@ke.tu-darmstadt.de>

This should work:

  SELECT (DATATYPE(?y) AS ?datatype) (COUNT(*) AS ?count) {
      ?x dbpprop:utcOffset ?y

On 8 Nov 2012, at 10:43, Heiko Paulheim wrote:
> we are trying to analyze datatype properties by the datatype they use. Our first idea was to use a simple SPARQL query per property, however, the following does not do what I would expect it to do:
> SELECT COUNT(?x) DATATYPE(?y) WHERE {?x dbpprop:utcOffset ?y}
> This query does not group all entries with, e.g., <http://www.w3.org/2001/XMLSchema#int> in one row. Why not? 

To understand what your query is actually doing, run this:

  SELECT ?y COUNT(?x) DATATYPE(?y) WHERE {?x dbpprop:utcOffset ?y}

The best way I can explain this: The "COUNT(?x)" introduces an implicit "GROUP BY ?y", because ?y is the only variable not used in an aggregate function, and so each result you get is for one distinct value of ?y, and not for one distinct datatype of ?y as you want.

Here's a fixed one. The main point is the GROUP BY clause that explicitly groups by distinct datatypes.

  SELECT (DATATYPE(?y) AS ?datatype) (COUNT(*) AS ?count) {
      ?x dbpprop:utcOffset ?y


> What am I doing wrong here?
> Best regards,
> Heiko
> -- 
> Dr. Heiko Paulheim
> Knowledge Engineering Group
> Technische Universitšt Darmstadt
> Phone: +49 6151 16 6634
> Fax:   +49 6151 16 5482
> http://www.ke.tu-darmstadt.de/staff/heiko-paulheim
Received on Thursday, 8 November 2012 13:06:01 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 1 March 2016 07:42:37 UTC