ok... after lots of experiment I finally got some that worked for my usecase.

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX annotea: <http://www.w3.org/2000/10/annotation-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT DISTINCT ?entry_uri
WHERE {

      {
        ?annotation annotea:related ?entry_uri .
        ?annotation annotea:body ?term_uri .
        ?term_uri rdfs:label ?term.filter(?term = 'test2')
      }
       UNION
      {
        ?annotation annotea:related ?entry_uri .
        ?annotation annotea:body ?term_uri .
        ?term_uri rdfs:label ?term.filter(?term = 'test3')
      }
}

Note, three unions does not work(same pattern but with another term in
the graph, 'term3'), which limit's the usefulness of this approach
(but this seems to be reparable bug):

    return graph.query(q).serialize(format='python')
  File "/Users/whit/dev/tagger/src/rdflib.plug/rdflib/Graph.py", line
690, in query
    processed_query = processor.query(strOrQuery, initBindings,
initNs, DEBUG, dataSetBase)
  File 
"/Users/whit/dev/tagger/src/rdflib.plug/rdflib/sparql/bison/Processor.py",
line 39, in query
    return 
TopEvaluate(strOrQuery,self.graph,initBindings,DEBUG=DEBUG,dataSetBase=dataSetBase)
  File "/Users/whit/dev/tagger/src/rdflib.plug/rdflib/sparql/Algebra.py",
line 341, in TopEvaluate
    topUnionBindings = result.parent1.top.returnResult(selectionF)+\
AttributeError: 'NoneType' object has no attribute 'returnResult'

Though it works (or could for more than 2), it seems unwieldy since it
requires replicating the entire query for each variation.  But every
case where two statements like so:

WHERE  {
      ?annotation annotea:related ?entry_uri .
      ?annotation annotea:body ?term_uri .
      ?term_uri rdfs:label ?term.filter(?term = 'test2')
      ?term_uri rdfs:label ?term.filter(?term = 'test3')
}

returned nothing (where ultimately there is a single entry_id that has
both terms).  It seems fundamentally limiting for sparql if this is
the correct behavior (though http://www.w3.org/TR/rdf-sparql-query/
lists UNION as the way to do alternatives)

sort of frustrating. in the old graphpattern way of querying, this was
fairly easy to do and it's a fairly common querying usecase.  Should
we be able to do this with sparql? and if not, what are we suppose to
use (and how do we get graphpattern and graph)?  Is there a way to
generate programmatic queries that makes more sense (currently I am
generating strings and feed them to graph.query)?

I've attached the rdf/xml of my data so others could look and see if
I'm missing something.

-w
<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF
   xmlns:annotea="http://www.w3.org/2000/10/annotation-ns#";
   xmlns:foaf="http://xmlns.com/foaf/0.1/";
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#";
   xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#";
   xmlns:tagger="http://xmlns.openplans.org/tagger#";
>
  <rdf:Description rdf:about="http://annotation.openplans.org/entry/urn:uuid:60a76c80-d399-11d9-b91C-0003939e0af6";>
    <annotea:created rdf:datatype="http://www.w3.org/2001/XMLSchema#date";>2007-09-19 19:37:00.353979</annotea:created>
    <rdf:ID rdf:resource="urn:uuid:60a76c80-d399-11d9-b91C-0003939e0af6"/>
    <rdf:type rdf:resource="http://www.w3.org/2005/Atom/entry"/>
  </rdf:Description>
  <rdf:Description rdf:about="http://example.org/test3";>
    <rdfs:label>test3</rdfs:label>
    <tagger:hasScheme rdf:resource="http://example.org"/>
    <rdf:type rdf:resource="http://xmlns.com/foaf/0.1/topic"/>
  </rdf:Description>
  <rdf:Description rdf:about="http://annotation.openplans.org/annotation/GiHeEEPV2";>
    <annotea:body rdf:resource="http://annotation.openplans.org/tag/test1"/>
    <annotea:annotates rdf:resource="http://example.org/ann-page.html"/>
    <rdf:type rdf:resource="http://www.w3.org/2000/10/annotation-ns#Annotation"/>
    <annotea:related rdf:resource="http://annotation.openplans.org/entry/urn:uuid:60a76c80-d399-11d9-b91C-0003939e0af6"/>
    <annotea:created rdf:datatype="http://www.w3.org/2001/XMLSchema#date";>2007-09-19 19:37:00.353979</annotea:created>
    <annotea:author rdf:resource="http://example.org/test-user.html"/>
  </rdf:Description>
  <rdf:Description rdf:about="http://annotation.openplans.org/tag/test1";>
    <rdfs:label>test1</rdfs:label>
    <rdf:type rdf:resource="http://xmlns.com/foaf/0.1/topic"/>
  </rdf:Description>
  <rdf:Description rdf:about="http://annotation.openplans.org/tag/test2";>
    <rdfs:label>test2</rdfs:label>
    <rdf:type rdf:resource="http://xmlns.com/foaf/0.1/topic"/>
  </rdf:Description>
  <rdf:Description rdf:about="http://annotation.openplans.org/annotation/GiHeEEPV3";>
    <annotea:body rdf:resource="http://annotation.openplans.org/tag/test2"/>
    <annotea:annotates rdf:resource="http://example.org/ann-page.html"/>
    <rdf:type rdf:resource="http://www.w3.org/2000/10/annotation-ns#Annotation"/>
    <annotea:related rdf:resource="http://annotation.openplans.org/entry/urn:uuid:60a76c80-d399-11d9-b91C-0003939e0af6"/>
    <annotea:created rdf:datatype="http://www.w3.org/2001/XMLSchema#date";>2007-09-19 19:37:00.353979</annotea:created>
    <annotea:author rdf:resource="http://example.org/test-user.html"/>
  </rdf:Description>
  <rdf:Description rdf:about="http://example.org/ann-page.html";>
    <rdf:type rdf:resource="http://www.w3.org/2005/Atom/link"/>
  </rdf:Description>
  <rdf:Description rdf:about="http://example.org/test-user.html";>
    <foaf:name>Test User</foaf:name>
    <foaf:mbox>[EMAIL PROTECTED]</foaf:mbox>
    <rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person"/>
  </rdf:Description>
  <rdf:Description rdf:about="http://annotation.openplans.org/annotation/GiHeEEPV4";>
    <annotea:body rdf:resource="http://example.org/test3"/>
    <annotea:annotates rdf:resource="http://example.org/ann-page.html"/>
    <rdf:type rdf:resource="http://www.w3.org/2000/10/annotation-ns#Annotation"/>
    <annotea:related rdf:resource="http://annotation.openplans.org/entry/urn:uuid:60a76c80-d399-11d9-b91C-0003939e0af6"/>
    <annotea:created rdf:datatype="http://www.w3.org/2001/XMLSchema#date";>2007-09-19 19:37:00.353979</annotea:created>
    <annotea:author rdf:resource="http://example.org/test-user.html"/>
  </rdf:Description>
</rdf:RDF>
_______________________________________________
Dev mailing list
Dev@rdflib.net
http://rdflib.net/mailman/listinfo/dev

Reply via email to