Re: Simple cardinality tests with SPARQL

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 .
> }

you want to check cardinality 1-n of the bar propery on class Foo, I 
assume... looks fine, could syntactically be abbreviated a bit using 
turtle shortcuts:


ASK WHERE { [a 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)
> }

also looks reasonable to me, you could do a positive version, by "hifing 
the NOT in an OPTIONAL as usual:

ASK
WHERE
  {
      OPTIONAL{ [a pfx:Foo ] pfx:bar ?b, ?b1 . FILTER(?b != ?b1) }
      FILTER( ! bound (?b ) )
  }



> Could these queries be formulated in a simpler, more elegant way ?
> 
>   Many thanks for your suggestions
>     Jaro
> 
> 
> 


-- 
Dr. Axel Polleres
Digital Enterprise Research Institute, National University of Ireland, 
Galway
email: axel.polleres@deri.org  url: http://www.polleres.net/

Received on Thursday, 13 November 2008 00:43:55 UTC