Search in sources :

Example 1 with SPARQLParser

use of org.eclipse.rdf4j.query.parser.sparql.SPARQLParser in project incubator-rya by apache.

the class GeoTemporalTestUtils method getSps.

public static List<StatementPattern> getSps(final String query) throws Exception {
    final StatementPatternCollector collector = new StatementPatternCollector();
    new SPARQLParser().parseQuery(query, null).getTupleExpr().visit(collector);
    return collector.getStatementPatterns();
}
Also used : StatementPatternCollector(org.eclipse.rdf4j.query.algebra.helpers.StatementPatternCollector) SPARQLParser(org.eclipse.rdf4j.query.parser.sparql.SPARQLParser)

Example 2 with SPARQLParser

use of org.eclipse.rdf4j.query.parser.sparql.SPARQLParser in project incubator-rya by apache.

the class GeoTemporalTestUtils method getNodes.

private static List<QueryModelNode> getNodes(final String sparql) throws Exception {
    final NodeCollector collector = new NodeCollector();
    new SPARQLParser().parseQuery(sparql, null).getTupleExpr().visit(collector);
    return collector.getTupleExpr();
}
Also used : SPARQLParser(org.eclipse.rdf4j.query.parser.sparql.SPARQLParser)

Example 3 with SPARQLParser

use of org.eclipse.rdf4j.query.parser.sparql.SPARQLParser in project incubator-rya by apache.

the class GeoTemporalTestUtils method getFilters.

public static List<FunctionCall> getFilters(final String query) throws Exception {
    final FunctionCallCollector collector = new FunctionCallCollector();
    new SPARQLParser().parseQuery(query, null).getTupleExpr().visit(collector);
    return collector.getTupleExpr();
}
Also used : SPARQLParser(org.eclipse.rdf4j.query.parser.sparql.SPARQLParser)

Example 4 with SPARQLParser

use of org.eclipse.rdf4j.query.parser.sparql.SPARQLParser in project incubator-rya by apache.

the class ListFluoQueries method getPrettyPrintSparql.

private static String getPrettyPrintSparql(String sparql, int indent) throws Exception {
    SPARQLParser parser = new SPARQLParser();
    ParsedQuery pq = parser.parseQuery(sparql, null);
    SPARQLQueryRenderer render = new SPARQLQueryRenderer();
    String renderedQuery = render.render(pq);
    // remove extra quotes generated by query renderer
    String[] splitRender = renderedQuery.split("\"\"\"");
    StringBuilder builder = new StringBuilder();
    for (String s : splitRender) {
        builder.append(s).append("\"");
    }
    builder.replace(builder.length() - 1, builder.length(), "");
    // add indent to all lines following newline char
    String[] newLineRender = builder.toString().split("\n");
    builder = new StringBuilder();
    String prefix = getVariableIndent(indent);
    for (int i = 0; i < newLineRender.length; i++) {
        if (i != 0) {
            builder.append(prefix);
        }
        builder.append(newLineRender[i]).append("\n");
    }
    return builder.toString();
}
Also used : SPARQLParser(org.eclipse.rdf4j.query.parser.sparql.SPARQLParser) ParsedQuery(org.eclipse.rdf4j.query.parser.ParsedQuery) SPARQLQueryRenderer(org.eclipse.rdf4j.queryrender.sparql.SPARQLQueryRenderer)

Example 5 with SPARQLParser

use of org.eclipse.rdf4j.query.parser.sparql.SPARQLParser in project incubator-rya by apache.

the class QueryReportRenderer method prettyFormatSparql.

private String[] prettyFormatSparql(final String sparql) throws Exception {
    final SPARQLParser parser = new SPARQLParser();
    final SPARQLQueryRenderer renderer = new SPARQLQueryRenderer();
    final ParsedQuery pq = parser.parseQuery(sparql, null);
    final String prettySparql = renderer.render(pq);
    final String[] sparqlLines = StringUtils.split(prettySparql, '\n');
    return sparqlLines;
}
Also used : SPARQLParser(org.eclipse.rdf4j.query.parser.sparql.SPARQLParser) ParsedQuery(org.eclipse.rdf4j.query.parser.ParsedQuery) SPARQLQueryRenderer(org.eclipse.rdf4j.queryrender.sparql.SPARQLQueryRenderer)

Aggregations

SPARQLParser (org.eclipse.rdf4j.query.parser.sparql.SPARQLParser)262 ParsedQuery (org.eclipse.rdf4j.query.parser.ParsedQuery)245 Test (org.junit.Test)208 TupleExpr (org.eclipse.rdf4j.query.algebra.TupleExpr)162 ArrayList (java.util.ArrayList)99 ExternalTupleSet (org.apache.rya.indexing.external.tupleSet.ExternalTupleSet)99 SimpleExternalTupleSet (org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet)86 StatementPattern (org.eclipse.rdf4j.query.algebra.StatementPattern)82 QueryModelNode (org.eclipse.rdf4j.query.algebra.QueryModelNode)62 PCJOptimizer (org.apache.rya.indexing.pcj.matching.PCJOptimizer)46 QueryBindingSet (org.eclipse.rdf4j.query.algebra.evaluation.QueryBindingSet)43 RyaIRI (org.apache.rya.api.domain.RyaIRI)42 QueryEvaluationException (org.eclipse.rdf4j.query.QueryEvaluationException)40 RyaStatement (org.apache.rya.api.domain.RyaStatement)39 BindingSet (org.eclipse.rdf4j.query.BindingSet)37 Projection (org.eclipse.rdf4j.query.algebra.Projection)37 RyaType (org.apache.rya.api.domain.RyaType)35 HashSet (java.util.HashSet)27 StatementMetadata (org.apache.rya.api.domain.StatementMetadata)20 StatementMetadataNode (org.apache.rya.indexing.statement.metadata.matching.StatementMetadataNode)18