[英]Is there a way to back translate a SPARQL query parse-tree to a query string using python's rdflib module?
With python's rdflib I can parse a SPARQL query string and translate its algebraic form with following syntax:使用 python 的 rdflib,我可以解析 SPARQL 查询字符串并使用以下语法翻译其代数形式:
statement = "Select ?s ?p ?o where {?s ?p ?o.}"
query_tree = parser.parseQuery(statement) # query parse-tree
q_algebra = algebra.translateQuery(query_tree) # query algebra
algebra.pprintAlgebra(q_algebra)
This is how the algebra tree of above query looks like:这是上面查询的代数树的样子:
SelectQuery(
p = Project(
p = BGP(
triples = [(rdflib.term.Variable('s'), rdflib.term.Variable('p'), rdflib.term.Variable('o'))]
_vars = {rdflib.term.Variable('s'), rdflib.term.Variable('p'), rdflib.term.Variable('o')}
)
PV = [rdflib.term.Variable('s'), rdflib.term.Variable('p'), rdflib.term.Variable('o')]
_vars = {rdflib.term.Variable('s'), rdflib.term.Variable('p'), rdflib.term.Variable('o')}
)
datasetClause = None
PV = [rdflib.term.Variable('s'), rdflib.term.Variable('p'), rdflib.term.Variable('o')]
_vars = {rdflib.term.Variable('s'), rdflib.term.Variable('p'), rdflib.term.Variable('o')}
)
After updating the query algebra by eg using algebra.traverse(q_algebra, update_function)
I want to get a query string again.通过例如使用algebra.traverse(q_algebra, update_function)
更新查询代数后,我想再次获取查询字符串。 I searched quiet a lot through the rdflib module but could not find a way how to back translate the algebra.我通过 rdflib 模块搜索了很多,但找不到如何反向翻译代数的方法。 Is there a function that takes the SPARQL query algebra as an input and returns a SPARQL query string?是否有将 SPARQL 查询代数作为输入并返回 SPARQL 查询字符串的 function?
No, and thanks to you Greenfish for providing this functionality in rdflib 6.0.0 yourself at https://github.com/RDFLib/rdflib/pull/1322不,感谢 Greenfish 在https://github.com/RDFLib/rdflib/pull/1322自己在 rdflib 6.0.0 中提供此功能
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.