org.openrdf.query.parser.QueryParser Java Examples
The following examples show how to use
org.openrdf.query.parser.QueryParser.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: QueryRewriter.java From neo4j-sparql-extension with GNU General Public License v3.0 | 6 votes |
/** * Rewrite a given query to add inference. * * @param ql the query language used for the query * @param query the query to rewrite * @param baseuri a base URI to use for the query * @return rewritten query that includes inference * @throws MalformedQueryException if the query is malformed * @throws RepositoryException if there was a problem while rewriting */ public Query rewrite(QueryLanguage ql, String query, String baseuri) throws MalformedQueryException, RepositoryException { // parse query using Sesame QueryParserFactory f = QueryParserRegistry.getInstance().get(ql); QueryParser parser = f.getParser(); ParsedQuery parsed = parser.parseQuery(query, baseuri); // get SPARQL algebra expression from parsed query TupleExpr expr = parsed.getTupleExpr(); // rewrite query using visitor pattern RuleTransformationVisitor visitor = new RuleTransformationVisitor(rules); expr.visit(visitor); // return new query based on rewritten algebra expression return getExprQuery(parsed, expr); }
Example #2
Source File: SPARQLRewriter.java From quetzal with Eclipse Public License 2.0 | 6 votes |
private List<Rule> parse(String rulesString) throws Exception { String[] rules = rulesString.split("###"); List<Rule> result = new LinkedList<Rule>(); for (String rule : rules) { SPARQLParserFactory fac = new SPARQLParserFactory(); QueryParser parser = fac.getParser(); ParsedQuery query = parser.parseQuery(rule, null); Rule r = new Rule(query); result.add(r); } return result; }
Example #3
Source File: SPARQLRewriter.java From quetzal with Eclipse Public License 2.0 | 5 votes |
public String rewrite(String selectQuery) throws Exception { SPARQLParserFactory fac = new SPARQLParserFactory(); QueryParser parser = fac.getParser(); ParsedTupleQuery query = (ParsedTupleQuery) parser.parseQuery(selectQuery, null); resolutionEngine.unfold(query); SPARQLQueryRenderer renderer = new SPARQLQueryRenderer(); String renderedQuery = renderer.render(query); return renderedQuery; }