Search in sources :

Example 1 with SPARQLQueryRenderer

use of org.openrdf.queryrender.sparql.SPARQLQueryRenderer in project incubator-rya by apache.

the class RyaClientExample method prettyFormatSparql.

private static 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);
    return StringUtils.split(prettySparql, '\n');
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) ParsedQuery(org.openrdf.query.parser.ParsedQuery) SPARQLQueryRenderer(org.openrdf.queryrender.sparql.SPARQLQueryRenderer)

Example 2 with SPARQLQueryRenderer

use of org.openrdf.queryrender.sparql.SPARQLQueryRenderer 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.openrdf.query.parser.sparql.SPARQLParser) ParsedQuery(org.openrdf.query.parser.ParsedQuery) SPARQLQueryRenderer(org.openrdf.queryrender.sparql.SPARQLQueryRenderer)

Example 3 with SPARQLQueryRenderer

use of org.openrdf.queryrender.sparql.SPARQLQueryRenderer in project incubator-rya by apache.

the class FluoAndHistoricPcjsDemo method prettyFormatSparql.

private static 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);
    return StringUtils.split(prettySparql, '\n');
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) ParsedQuery(org.openrdf.query.parser.ParsedQuery) SPARQLQueryRenderer(org.openrdf.queryrender.sparql.SPARQLQueryRenderer)

Example 4 with SPARQLQueryRenderer

use of org.openrdf.queryrender.sparql.SPARQLQueryRenderer 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.openrdf.query.parser.sparql.SPARQLParser) ParsedQuery(org.openrdf.query.parser.ParsedQuery) SPARQLQueryRenderer(org.openrdf.queryrender.sparql.SPARQLQueryRenderer)

Example 5 with SPARQLQueryRenderer

use of org.openrdf.queryrender.sparql.SPARQLQueryRenderer in project incubator-rya by apache.

the class StreamsQueryFormatter method format.

/**
 * Pretty formats a {@link StreamsQuery}.
 *
 * @param query - The query to format. (not null)
 * @return The pretty formatted string.
 * @throws Exception A problem was encountered while pretty formatting the SPARQL.
 */
public static String format(final StreamsQuery query) throws Exception {
    requireNonNull(query);
    // Pretty format the SPARQL query.
    final ParsedQuery parsedQuery = new SPARQLParser().parseQuery(query.getSparql(), null);
    final String prettySparql = new SPARQLQueryRenderer().render(parsedQuery);
    final String[] lines = prettySparql.split("\n");
    // Create the formatted string.
    query.getQueryId();
    query.isActive();
    String.format(" QueryId: %s", query.getQueryId());
    final StringBuilder builder = new StringBuilder();
    builder.append(" Query ID: ").append(query.getQueryId()).append("\n");
    builder.append("Is Active: ").append(query.isActive()).append("\n");
    builder.append("Is Insert: ").append(query.isInsert()).append("\n");
    builder.append("   SPARQL: ").append(lines[0]).append("\n");
    for (int i = 1; i < lines.length; i++) {
        builder.append("           ").append(lines[i]).append("\n");
    }
    return builder.toString();
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) ParsedQuery(org.openrdf.query.parser.ParsedQuery) SPARQLQueryRenderer(org.openrdf.queryrender.sparql.SPARQLQueryRenderer)

Aggregations

ParsedQuery (org.openrdf.query.parser.ParsedQuery)6 SPARQLParser (org.openrdf.query.parser.sparql.SPARQLParser)6 SPARQLQueryRenderer (org.openrdf.queryrender.sparql.SPARQLQueryRenderer)6 ReportItem (org.apache.rya.indexing.pcj.fluo.client.util.Report.ReportItem)1 VariableOrder (org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder)1