Testing SPARQL

16 views
Skip to first unread message

Dominique Guardiola Falco

unread,
Jun 5, 2011, 12:16:03 PM6/5/11
to sur...@googlegroups.com
I test sparql for the first time and I get another error, where am I wrong here ?

>>> import surf
>>> store = surf.Store(reader='rdflib',writer='rdflib',rdflib_store='IOMemory')
>>> session = surf.Session(store)
>>> store.load_triples(source='http://www.w3.org/2009/08/skos-reference/skos.rdf')
True
>>> store.execute_sparql("SELECT ?s ?p ?o WHERE { ?s ?p ?o }")
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Users/dom/django/.virtualenvs/base/lib/python2.7/site-packages/SuRF-1.1.4_r352-py2.7.egg/surf/store.py", line 200, in execute_sparql
    return self.reader.execute_sparql(sparql_query, format = format)
  File "build/bdist.linux-x86_64/egg/surf_rdflib/reader.py", line 87, in execute_sparql
    return loads(result.serialize('json'))
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 326, in loads
    return _default_decoder.decode(s)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 360, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 376, in raw_decode
    obj, end = self.scan_once(s, idx)
ValueError: Invalid control character at: line 121 column 142 (char 8065)

Christoph Burgmer

unread,
Jun 5, 2011, 2:41:19 PM6/5/11
to sur...@googlegroups.com, Dominique Guardiola Falco

If you add a print to the line in surf where the error occurs you can look at
the JSON object that rdflib returns. Here is line 121:

{
"s" : {"type": "uri", "value" :
"http://www.w3.org/2004/02/skos/core#closeMatch"},
"p" : {"type": "uri", "value" :
"http://www.w3.org/2004/02/skos/core#definition"},
"o" : {"type": "literal", "xml:lang" : "en", "value" :
"skos:closeMatch is used to link two concepts that are sufficiently similar that
they can be used interchangeably in some information retrieval applications.
In order to avoid the possibility of "compound errors" when combining mappings
across more than two concept schemes, skos:closeMatch is not declared to be a
transitive property."}
},

Rdflib (probably more precisely rdfextras) doesn't properly escape the ' " '
inside the literal which makes the JSON parser rightly complain.

You can report this as a bug to rdfextras, but as this project is currently
pretty unstable I don't know how much chances you have getting that fix. Either
way I would suggest you use a real triple store, even if that requires you to
setup a full blown server locally.

-Christoph

Christoph Burgmer

unread,
Jun 5, 2011, 2:48:17 PM6/5/11
to Dominique Guardiola Falco, sur...@googlegroups.com
Am Sonntag, 5. Juni 2011 schrieb Christoph Burgmer:
> Either way I would suggest you use a real triple store, even if that
> requires you to setup a full blown server locally.

I'd recommend you install OpenLink's Virtuoso and use SuRF's sparql_procol
plugin.

-Christoph

Reply all
Reply to author
Forward
0 new messages