I am trying to create a SPARQL query on an OWL file (see) but this is the first time that I have an OWL file , So I used RDFLIB in Python to create SPRQL queries. I get an error when I run the code (shown below the code) which I do not understand. What could be the reason?
code import rdflib graph = rdflib.Graph () prefix = "" "PREFIX DC: PREFIX FoF: & lt; http: //xmlns.com/foaf/0.1/> PREFIX olia-ar: & lt; http: //purl.org/olia/arabic_khoja.owl#> prefix digitum : & Lt; http: //purl.org/dc/terms/>PREFIX rdfs: & lt; http: //www.w3.org/2000/01/rdf-schema#> PREFIX OWL: & lt; Http://www.w3.org/2002/07/owl#> PREFIX xsd: http: //www.w3.org/2001/XMLSchema#> PREFIX lexvo: & lt; http: // Lexvo org / id / iso639-3 /> PREFIX rdf: & lt; http: //www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX p1: & lt; http: // Dependent Stanford.edu/plugins/owl/protege#>PREFIX Base: & lt; http: //www.owl-ontologies.com/unnamed.owl#> PREFIX xmlns: & lt; http: // www .owl-ontologies com / unnamed.owl # & gt; "" "queryString = prefix +" \ n "+" "SELECT? Animal class WHERE {? Animals: Has_Usage "Ride"; Rdf: type? AnimalClass.} "" Graph.An Animal.owl ') result = graph.query (queryString) for the resulting line: print line error traceback (most recent call final): file" D: \ Python27 \ animal.py "line 22, results = graph.query (queryString ) File "build \ bdist.win32 \ egg \ rdflib \ graph.py", line 1007, query query_object, initBindings, initNs, ** kwargs) The file "D: \ Python27 \ lib \ site-package \ rdfextras-0.4- Py2.7.egg \ rdfextras \ sparql \ processor.py ", line 49, query loadContexts = loadContexts) file" D: \ Python27 \ lib \ site- Packages \ rdfextras-0.4-py2.7.egg \ rdfextras \ sparql \ algebra.py ", in line 358, none in TopEvaluate) file" D: \ Python27 \ lib \ site-packages \ rdfextras-0.4-py2.7 Corrected = low graph paragraph (right, prolol) file ".: Python 27 \ lib \ site-packages \ rdfextras-0.4-py2.7. Egg \ rdfextras \ sparql \ algebra.py ", line 63, ReduceGraphPattern bgp = BasicGraphPattern (list (AnilolTriplight (Triple, Preroll)), pre file" D: \ Python 27 \ lib \ site-packages \ rdfextras-0.4-py2. 7.egg \ rdfextras \ sparql \ evaluate.py ", line 301, item in unrecognized triple item For UnRollRDFTerm (item, queryProl): Convert file "D: \ Python 27 \ lib \ site-packages \ rdfextras-0.4-py2.7.egg \ rdfextras \ sparql \ Evaluate.py", line 281, unRollRDFTermTerm (PropVal.property, queryProlog), the file "D: \ Python27 \ lib \ site-packages \ rdfextras-0.4-py2.7.egg \ rdfextras \ sparql \ evaluate.py", line 151, the original base = queryProlog in Convert. PrefixBindings [u] "Keyer: You can see that the obvious error is:" '
It is that you use the prefix name : Has_Usage but you have a lower prefix ie PREFIX is not defined. ; Http: //example.org/ns#> I think it might happen that you were trying to do with PREFIX xmlns: declaration?
import rdflib graph = rdflib.Graph () prefix = "" "PREFIX DC: PREFIX FoF: & lt; http: //xmlns.com/foaf/0.1/> PREFIX olia-ar: & lt; http: //purl.org/olia/arabic_khoja.owl#> prefix digitum : & Lt; http: //purl.org/dc/terms/>PREFIX rdfs: & lt; http: //www.w3.org/2000/01/rdf-schema#> PREFIX OWL: & lt; Http://www.w3.org/2002/07/owl#> PREFIX xsd: http: //www.w3.org/2001/XMLSchema#> PREFIX lexvo: & lt; http: // Lexvo org / id / iso639-3 /> PREFIX rdf: & lt; http: //www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX p1: & lt; http: // Dependent Stanford.edu/plugins/owl/protege#>PREFIX Base: & lt; http: //www.owl-ontologies.com/unnamed.owl#> PREFIX xmlns: & lt; http: // www .owl-ontologies com / unnamed.owl # & gt; "" "queryString = prefix +" \ n "+" "SELECT? Animal class WHERE {? Animals: Has_Usage "Ride"; Rdf: type? AnimalClass.} "" Graph.An Animal.owl ') result = graph.query (queryString) for the resulting line: print line error traceback (most recent call final): file" D: \ Python27 \ animal.py "line 22, results = graph.query (queryString ) File "build \ bdist.win32 \ egg \ rdflib \ graph.py", line 1007, query query_object, initBindings, initNs, ** kwargs) The file "D: \ Python27 \ lib \ site-package \ rdfextras-0.4- Py2.7.egg \ rdfextras \ sparql \ processor.py ", line 49, query loadContexts = loadContexts) file" D: \ Python27 \ lib \ site- Packages \ rdfextras-0.4-py2.7.egg \ rdfextras \ sparql \ algebra.py ", in line 358, none in TopEvaluate) file" D: \ Python27 \ lib \ site-packages \ rdfextras-0.4-py2.7 Corrected = low graph paragraph (right, prolol) file ".: Python 27 \ lib \ site-packages \ rdfextras-0.4-py2.7. Egg \ rdfextras \ sparql \ algebra.py ", line 63, ReduceGraphPattern bgp = BasicGraphPattern (list (AnilolTriplight (Triple, Preroll)), pre file" D: \ Python 27 \ lib \ site-packages \ rdfextras-0.4-py2. 7.egg \ rdfextras \ sparql \ evaluate.py ", line 301, item in unrecognized triple item For UnRollRDFTerm (item, queryProl): Convert file "D: \ Python 27 \ lib \ site-packages \ rdfextras-0.4-py2.7.egg \ rdfextras \ sparql \ Evaluate.py", line 281, unRollRDFTermTerm (PropVal.property, queryProlog), the file "D: \ Python27 \ lib \ site-packages \ rdfextras-0.4-py2.7.egg \ rdfextras \ sparql \ evaluate.py", line 151, the original base = queryProlog in Convert. PrefixBindings [u] "Keyer: You can see that the obvious error is:" '
It is that you use the prefix name : Has_Usage but you have a lower prefix ie PREFIX is not defined. ; Http: //example.org/ns#> I think it might happen that you were trying to do with PREFIX xmlns: declaration?
No comments:
Post a Comment