Java代码的SPARQL解析器 [英] SPARQL parser for Java Code

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

问题描述

有没有简单的方法来解析java变量中的sparql查询,比如python中的Fyzz?如何使用Jena或芝麻API?

Is any easy way to parse sparql query in variables for java, like Fyzz in python? How can Jena or sesame APIs been used?

推荐答案

您可以使用Apache Jena的 ARQ 非常简单,无论是语法还是代数级别。 QueryFactory.create(queryString)将提供查询的java表示。然后捅:

You can parse and manipulate SPARQL in java using Apache Jena's ARQ pretty simply, at either the syntax or algebra level. QueryFactory.create(queryString) will provide a java representation of the query. Then poke around:

Query query = QueryFactory.create(queryString);
query.isSelectType() && query.isQueryResultStar(); // of the form SELECT *?
query.getDatasetDescription(); // FROM / FROM NAMED bits
query.getQueryPattern(); // The meat of the query, the WHERE bit
...etc etc..
Op op = Algebra.compile(query); // Get the algebra for the query

(参见查询java文档

尝试从教程'使用ARQ操纵SPARQL'开始。这将让您了解如何表示查询,以及如何从中提取信息(访问者特别有用)。虽然最初的语法级别是最熟悉的,但对于许多任务,代数工作得更好它对应于查询实际执行的操作。

Try starting with the tutorial 'Manipulating SPARQL using ARQ'. That will give you a feel for how queries are represented, and how to pull things out from them (visitors are especially useful). Although initially the syntax level is most familiar, for many tasks the algebra works better since it corresponds to what a query actually does.

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

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