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

Reply via email to