SPARQL parser for Java Code

后端 未结 2 1567
庸人自扰
庸人自扰 2021-01-04 22:52

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

2条回答
  •  旧巷少年郎
    2021-01-04 23:32

    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
    

    (see the Query java documentation)

    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.

提交回复
热议问题