W3C home > Mailing lists > Public > public-sparql-dev@w3.org > October to December 2008

Re: Simple cardinality tests with SPARQL

From: Lee Feigenbaum <lee@thefigtrees.net>
Date: Wed, 12 Nov 2008 20:09:50 -0500
Message-ID: <491B7E5E.1040708@thefigtrees.net>
To: Jaroslav Pullmann <jaroslav.pullmann@fit.fraunhofer.de>
CC: public-sparql-dev@w3.org

Jaroslav Pullmann wrote:
> 
>  Hello,
> to check for property cardinalities within an RDF document I used 
> following queries:
> 
>  - for cardinality 0-1: NOT(Q2)
>  - for cardinality 1: Q1 AND NOT(Q2)
>  - for cardinality 1-n : Q1
> 
> 
> # Q1
> ASK
> WHERE
> {
>     ?s rdf:type pfx:Foo; pfx:bar ?b .
> }
> 
> # Q2 - no solutions, no duplicates
> ASK
> WHERE
> {
>     ?s rdf:type pfx:Foo;
>     pfx:bar ?b;
>     pfx:bar ?b1
>     FILTER(?b != ?b1)
> }
> 
> Could these queries be formulated in a simpler, more elegant way ?

I agree with Axel that in standard SPARQL these are basically the way to 
go. Just wanted to point out:

http://esw.w3.org/topic/SPARQL/Extensions/Aggregates

Several SPARQL implementations extend SPARQL with a COUNT() function 
that would make this much easier. For example, using Glitter (Open 
Anzo), I'd write:

SELECT (COUNT(?o) AS ?cardinality)
WHERE {
   ?s a pfx:Foo ; pfx:bar ?o .
}

Lee
Received on Thursday, 13 November 2008 01:11:05 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Thursday, 13 November 2008 01:11:05 GMT