Re: Counting datatypes per property

Heiko,

This should work:

  SELECT (DATATYPE(?y) AS ?datatype) (COUNT(*) AS ?count) {
      ?x dbpprop:utcOffset ?y
  } GROUP BY DATATYPE(?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
  } GROUP BY DATATYPE(?y)

Best,
Richard


> 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