我在阿拉伯语中开发了自己的本体,现在我想使用 rdflib 和 sparql 来做一些sparql请求。问题是当我在我的本体上不使用阿拉伯语的情况下提出请求时我得到了没有问题的答案,但是当我想使用阿拉伯语语言对属性做出特定请求时,我遇到了一些错误:(。
任何人都知道我该如何处理。我做错了什么!!!
这是我的代码:
graph =rdflib.Graph()
filename = r'JO Ontology modified 09 june 2014 with properties.owl'
graph.load(filename, format='xml')
qres = graph.query(
"PREFIX OntoJO:<http://www.owl-ontologies.com/Ontology1400008538.owl#>" +
"SELECT ?path " +
"WHERE { ?lois_ordinaires OntoJO:ministere_lord ?ministere_lord ."+
"?lois_ordinaires OntoJO:a_un_chemin ?y ."+
" ?y OntoJO:chemin ?path ."+
"FILTER(regex(?ministere_lord,'وزارة المالية'))}", )
for row in qres:
print row[0]
错误:
File "C:\Users\Mehdi\workspace\My_work\Test\Recherche.py", line 38, in main
"FILTER(regex(?ministere_lord,'وزارة المالية'))}", )
File "build\bdist.win-amd64\egg\rdflib\graph.py", line 920, in query
File "C:\Python27\lib\site-packages\rdfextras-0.4-py2.7.egg\rdfextras\sparql\components.py", line 168, in __new__
return unicode.__new__(cls, value)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd9 in position 0: ordinal not in range(128)
答案 0 :(得分:0)
我找到了正确的语法:)。
我只是改变了这一行:
"FILTER(regex(?ministere_lord,'وزارة المالية'))}", )
这一个:
"FILTER (regex(?ministere_lord,'""" +u"وزارة المالية"+ """')) }""" , )
所以sparql请求是:
graph =rdflib.Graph()
filename = r'JO Ontology modified 09 june 2014 with properties.owl'
graph.load(filename, format='xml')
qres = graph.query(
""" PREFIX OntoJO:<http://www.owl-ontologies.com/Ontology1400008538.owl#>
SELECT ?path
WHERE { ?lois_ordinaires OntoJO:ministere_lord ?ministere_lord .
?lois_ordinaires OntoJO:a_un_chemin ?y .
?y OntoJO:chemin ?path .
FILTER (regex(?ministere_lord,'""" +u"وزارة المالية"+ """'))
}""" , )