Hello again,

I found another small bug. When giving an empty prefix name in a
SPARQL query I get: TypeError: unsupported operand type(s) for +:
'NoneType' and 'unicode'

Here is from the SPARQL draft: http://www.w3.org/TR/rdf-sparql-query/#termSyntax

----------------

Prefixed names

The PREFIX keyword associates a prefix label with an IRI. A prefixed
name is a prefix label and a local part, separated by a colon ":". It
is mapped to an IRI by concatenating the local part to the IRI
corresponding to the prefix. The prefix label may be the empty string.

----------------

This happens in SPARQLEvaluate.py in the convertTerm method. I tried
making a small patch for it and a test case (see attachment).

I'm interested in getting the SPARQL engine to support a larger subset
of the SPARQL spec. Especially nested optionals. Is anyone working on
this currently?

Cheers,
Mikael
from rdflib import ConjunctiveGraph
from StringIO import StringIO
import unittest

test_data = """
@prefix foaf:       <http://xmlns.com/foaf/0.1/> .
@prefix rdf:        <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .

_:a  foaf:name       "Alice" .
"""

test_query = """PREFIX :<http://xmlns.com/foaf/0.1/>
SELECT ?name
WHERE {
    ?x :name ?name .
}"""

correct = '"name" : {"type": "literal", "xml:lang" : "None", "value" : "Alice"}'
                
class Query(unittest.TestCase):

    def testQueryPlus(self):
        graph = ConjunctiveGraph()
        graph.parse(StringIO(test_data), format="n3")
        result_json = graph.query(test_query).serialize(format='json')
        self.failUnless(result_json.find(correct) > 0)

if __name__ == "__main__":
    unittest.main()
Index: rdflib/sparql/bison/SPARQLEvaluate.py
===================================================================
--- rdflib/sparql/bison/SPARQLEvaluate.py	(revision 906)
+++ rdflib/sparql/bison/SPARQLEvaluate.py	(working copy)
@@ -53,8 +54,8 @@
         return term
     elif isinstance(term,QName):
         #QNames and QName prefixes are the same in the grammar
-        if not term.prefix:
-            return URIRef(queryProlog.baseDeclaration + term.localname)
+        if term.prefix == None:
+            return URIRef(queryProlog.baseDeclaration + term.localname)        
         else:
             return URIRef(queryProlog.prefixBindings[term.prefix] + term.localname)
     elif isinstance(term,QNamePrefix):
_______________________________________________
Dev mailing list
Dev@rdflib.net
http://rdflib.net/mailman/listinfo/dev

Reply via email to