解析SPARQL查询 [英] Parsing SPARQL queries

查看:97
本文介绍了解析SPARQL查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要测试数百万个SPARQL查询的某些结构属性,为此,我需要WHERE语句的结构.我目前正在尝试使用fyzz来执行此操作,但是不幸的是它的文档不是很有用.解析查询很容易,问题在于我无法恢复该语句的结构.例如:

I need to test for a certain structural property of a couple million SPARQL queries, and for that I need the structure of the WHERE statement. I'm currently trying to use fyzz to do this, but unfortunately its documentation is not very useful. Parsing queries is easy, the problem is that i haven't been able to recover the structure of the statement. For example:

>>> from fyzz import parse
>>> a=parse("SELECT * WHERE {?x a ?y . {?x a ?z}}")
>>> b=parse("SELECT * WHERE {?x a ?y OPTIONAL {?x a ?z}}")
>>> a.where==b.where
True
>>> a.where
[(SparqlVar('x'), ('', 'a'), SparqlVar('y')), (SparqlVar('x'), ('', 'a'), SparqlVar('y'))]

有没有一种方法可以恢复fyzz中的实际解析树,而不仅仅是三元组或其他可以让我做到这一点的工具? RDFLib过去似乎有一个野牛SPARQL解析器,但是我在rdflibrdfextras.sparql软件包中找不到它.

Is there a way to recover the actual parse tree in fyzz instead of just the triples, or some other tool which would let me do this? RDFLib seems to have had a bison SPARQL parser in the past, but I can't find it in the rdflib or rdfextras.sparql packages.

谢谢

推荐答案

另一个工具是roqet,该工具打包在 rasqal .它是一个命令行工具,用于返回已解析的树.例如:

Another tool is roqet a tool that is packaged within rasqal. It is a command line tool that returns the parsed tree. For instance:

roqet -i laqrs -d structure -n -e "SELECT * WHERE {?x a ?y OPTIONAL {?x a ?z}}"

将输出..

Query:
query verb: SELECT
query bound variables (3): x, y, z
query Group graph pattern[0] {
  sub-graph patterns (2) {
    Basic graph pattern[1] #0 {
      triples {
        triple #0 { triple(variable(x), uri<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>, variable(y)) }
      }
    }
    Optional graph pattern[2] #1 {
      sub-graph patterns (1) {
        Basic graph pattern[3] #0 {
          triples {
            triple #0 { triple(variable(x), uri<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>, variable(z)) }
          }
        }
      }
    }
  }
}

在其他答案中查看您的评论,我认为这不是您所需要的.而且我认为您不会在SPARQL解析器中找到答案.查询中的对象(或三元模式)评估发生在Query Engines内部,在设计良好的系统中,该对象与查询解析是隔离的.

Looking at your comment in the other answer I don't think this is what yo need. And I don't think you will find an answer looking inside SPARQL parsers. The object (or triple pattern) evaluation in a query happens inside Query Engines that, in well designed systems, is isolated from query parsing.

例如,在4store中,您可以使用选项-vvv(非常详细)查看4s-query命令,您将在其中看到有关如何执行查询以及如何对每个三重模式评估执行替换的输出.

For instance, in 4store you could look at the 4s-query command with the option -vvv (very verbose) where you would see an output of how the query was executed and how substitutions were performed for each triple pattern evaluation.

这篇关于解析SPARQL查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆