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

Re: cwm/sparql mystery

From: Jon Crump <jjcrump@myuw.net>
Date: Sat, 1 Nov 2008 13:59:58 -0700 (PDT)
To: public-cwm-talk@w3.org
Message-ID: <Pine.LNX.4.64.0811011339580.26215@cicero11.myuw.net>

OK. In the extremely unlikely event that there is anyone reading this list 
who is as clueless and as at-sea as I am, I will answer my own question as 
search bait:

The clue (after a ridiculous amount of trial and error) was when I finally 
asked cwm to serialize the results of my query as n3 thus:

%cwm --rdf /path/to/rdf/model.rdf --sparql=/path/to/sparql/query.txt --n3

Doing this gave me sensible results, but they took the form of a "quoted" 
graph. In such a graph, the query variables I was searching for are 
expressed like this:

         "Some Literal"     :bound "label" .
         "2008-01-02"^^xsd:date     :bound "start" .
         "2008-01-04"^^xsd:date     :bound "end" .
         Event:case2     :bound "event" .

         }     a :Result .

This means that if the values you're searching for contain a literal, 
those literals are expressed as the SUBJECTS of the resulting triples and 
if you ask for --rdf output, cwm will complain:

"ValueError: Bad subject of statement: Some Literal.
                 RDF/XML cannot serialize a graph in which a subject is a 

This is apparently the problem also if what you're searching for is a 
datatyped literal like "2008-01-04"^^xsd:date, in which case the somewhat 
less explicit runtime error:

"RuntimeError: ('Unexpected subject', "(21, ('2008-01-04', 

Asking for --n3 output avoids this because, apparently, the "quoted graph" 
style of representing a sparql query result doesn't care if the subjects 
are literals.

The solution, for my purposes at any rate, was to use a CONSTRUCT query, 
instead of a SELECT, thus:

CONSTRUCT {?event ex:hasdate ?date; ex:hasstart ?start; ex:hasend ?end; 
ex:haslabel ?label.}

This way, the literals that are bound to the query variables are forced to 
be objects of triples and can thus be serialized as either rdf/xml or n3:

<rdf:Description rdf:about="http://temp.example.org/terms/Event#case2">
    <haslabel>Some Literal</haslabel>

Though it's not exactly to the point, and though much of it is over my 
head, the discussion of design issues at: 
http://www.w3.org/DesignIssues/N3QL.html was helpful in clarifying some of 
the underlying issues for me.

Open question: I still haven't worked out why, with this graph and this 
query, asking cwm to report with --sparqlResults gives me this Import 

Traceback (most recent call last):
   File "/Applications/RDFapps/cwm-1.2.1/cwm", line 750, in <module>
   File "/Applications/RDFapps/cwm-1.2.1/cwm", line 698, in doCommand
     from cwm_sparql import outputString, SPARQL_NS
ImportError: No module named cwm_sparql

Another Open question: I still haven't been able to coax the rdflib sparql 
implementation to give me similarly sensible results with this test query; 
but that's another story for another list I suppose.

Received on Saturday, 1 November 2008 21:00:40 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 20:01:05 UTC