0

I'm trying to make SPARQL queries on an OWL file (see pastebin) but it is the first time I'm dealing with an OWL file, so I used RDFLIB in Python to make SPARQL queries. When i run the code I get an error (shown below code) which I do not understand. What could be causing this?

Code

import rdflib
graph = rdflib.Graph()
prefix="""PREFIX  dc:<http://purl.org/dc/elements/1.1/>
PREFIX  foaf: <http://xmlns.com/foaf/0.1/>
PREFIX  olia-ar: <http://purl.org/olia/arabic_khoja.owl#>
PREFIX  dcterms: <http://purl.org/dc/terms/>
PREFIX  rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX  owl:  <http://www.w3.org/2002/07/owl#>
PREFIX  xsd:  <http://www.w3.org/2001/XMLSchema#>
PREFIX  lexvo: <http://lexvo.org/id/iso639-3/>
PREFIX  rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX  p1: <http://protege.stanford.edu/plugins/owl/protege#>
PREFIX  base: <http://www.owl-ontologies.com/unnamed.owl#>
PREFIX xmlns:<http://www.owl-ontologies.com/unnamed.owl#>
"""
queryString = prefix+"\n"+"""SELECT ?animalClass
WHERE {
      ?animal :Has_Usage "Ride";
              rdf:type ?animalClass.
      }"""
graph.parse('animal.owl')
result = graph.query(queryString)
for row in result:
    print row

Error

Traceback (most recent call last):
  File "D:\Python27\animal.py", line 22, in <module>
    result = graph.query(queryString)
  File "build\bdist.win32\egg\rdflib\graph.py", line 1007, in query
    query_object, initBindings, initNs, **kwargs))
  File "D:\Python27\lib\site-packages\rdfextras-0.4-py2.7.egg\rdfextras\sparql\processor.py", line 49, in query
    loadContexts=loadContexts)
  File "D:\Python27\lib\site-packages\rdfextras-0.4-py2.7.egg\rdfextras\sparql\algebra.py", line 358, in TopEvaluate
    None)
  File "D:\Python27\lib\site-packages\rdfextras-0.4-py2.7.egg\rdfextras\sparql\algebra.py", line 179, in ReduceToAlgebra
    right = ReduceGraphPattern(right,prolog)
  File "D:\Python27\lib\site-packages\rdfextras-0.4-py2.7.egg\rdfextras\sparql\algebra.py", line 63, in ReduceGraphPattern
    bgp=BasicGraphPattern(list(unRollTripleItems(triple,prolog)),prolog)
  File "D:\Python27\lib\site-packages\rdfextras-0.4-py2.7.egg\rdfextras\sparql\evaluate.py", line 301, in unRollTripleItems
    for item in unRollRDFTerm(items, queryProlog):
  File "D:\Python27\lib\site-packages\rdfextras-0.4-py2.7.egg\rdfextras\sparql\evaluate.py", line 281, in unRollRDFTerm
    convertTerm(propVal.property, queryProlog),
  File "D:\Python27\lib\site-packages\rdfextras-0.4-py2.7.egg\rdfextras\sparql\evaluate.py", line 151, in convertTerm
    base = queryProlog.prefixBindings[u'']
KeyError: u''
Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353

1 Answers1

0

The obvious error I can see is that you use the prefixed name :Has_Usage but you haven't defined an empty prefix i.e.

PREFIX : <http://example.org/ns#>

I guess this is maybe what you were trying to do with the PREFIX xmlns: declaration?

RobV
  • 28,022
  • 11
  • 77
  • 119