Search in sources :

Example 26 with IndentedWriter

use of org.apache.jena.atlas.io.IndentedWriter in project jena by apache.

the class sse_query method exec.

@Override
protected void exec() {
    Op op = modAlgebra.getOp();
    if (op == null) {
        System.err.println("No query expression to execute");
        throw new TerminationException(9);
    }
    Dataset dataset = modDataset.getDataset();
    // Check there is a dataset.
    if (dataset == null)
        dataset = DatasetFactory.createGeneral();
    modTime.startTimer();
    DatasetGraph dsg = dataset.asDatasetGraph();
    if (printOp || printPlan) {
        if (printOp) {
            divider();
            IndentedWriter out = new IndentedWriter(System.out, true);
            op.output(out);
            out.flush();
        }
        if (printPlan) {
            QueryIterator qIter = Algebra.exec(op, dsg);
            Plan plan = new PlanOp(op, null, qIter);
            divider();
            IndentedWriter out = new IndentedWriter(System.out, false);
            plan.output(out);
            out.flush();
        }
    // return ;
    }
    // Do not optimize.  Execute as-is.
    QueryExecUtils.execute(op, dsg, modResults.getResultsFormat());
    long time = modTime.endTimer();
    if (modTime.timingEnabled())
        System.out.println("Time: " + modTime.timeStr(time));
}
Also used : IndentedWriter(org.apache.jena.atlas.io.IndentedWriter) PlanOp(org.apache.jena.sparql.engine.PlanOp) Op(org.apache.jena.sparql.algebra.Op) TerminationException(org.apache.jena.cmd.TerminationException) QueryIterator(org.apache.jena.sparql.engine.QueryIterator) ModDataset(arq.cmdline.ModDataset) Dataset(org.apache.jena.query.Dataset) PlanOp(org.apache.jena.sparql.engine.PlanOp) Plan(org.apache.jena.sparql.engine.Plan) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph)

Example 27 with IndentedWriter

use of org.apache.jena.atlas.io.IndentedWriter in project jena by apache.

the class ModContext method verbose.

public void verbose(PrintStream stream) {
    IndentedWriter out = new IndentedWriter(stream);
    verbose(out);
    out.flush();
}
Also used : IndentedWriter(org.apache.jena.atlas.io.IndentedWriter)

Example 28 with IndentedWriter

use of org.apache.jena.atlas.io.IndentedWriter in project jena by apache.

the class ShaclcWriter method print.

/**
 * Write shapes in <a href="https://w3c.github.io/shacl/shacl-compact-syntax/">SHACL Compact Syntax</a> (July 2020).
 */
public static void print(OutputStream output, Shapes shapes) {
    IndentedWriter out = new IndentedWriter(output);
    out.setUnitIndent(4);
    print(out, shapes);
}
Also used : IndentedWriter(org.apache.jena.atlas.io.IndentedWriter)

Example 29 with IndentedWriter

use of org.apache.jena.atlas.io.IndentedWriter in project jena by apache.

the class ShexPrintable method print.

public default void print() {
    IndentedWriter iOut = IndentedWriter.clone(IndentedWriter.stdout);
    NodeFormatter nFmt = new NodeFormatterTTL(null, PrefixMapFactory.create(SSE.getPrefixMapRead()));
    print(iOut, nFmt);
}
Also used : IndentedWriter(org.apache.jena.atlas.io.IndentedWriter) NodeFormatter(org.apache.jena.riot.out.NodeFormatter) NodeFormatterTTL(org.apache.jena.riot.out.NodeFormatterTTL)

Example 30 with IndentedWriter

use of org.apache.jena.atlas.io.IndentedWriter in project jena by apache.

the class ExQuerySelect1 method main.

public static void main(String[] args) {
    // Create the data.
    // This wil be the background (unnamed) graph in the dataset.
    Model model = createModel();
    // First part or the query string
    String prolog = "PREFIX dc: <" + DC.getURI() + ">";
    // Query string.
    String queryString = prolog + NL + "SELECT ?title WHERE {?x dc:title ?title}";
    Query query = QueryFactory.create(queryString);
    // Print with line numbers
    query.serialize(new IndentedWriter(System.out, true));
    System.out.println();
    try (QueryExecution qexec = QueryExecutionFactory.create(query, model)) {
        // Or QueryExecutionFactory.create(queryString, model) ;
        System.out.println("Titles: ");
        // Assumption: it's a SELECT query.
        ResultSet rs = qexec.execSelect();
        // The order of results is undefined.
        for (; rs.hasNext(); ) {
            QuerySolution rb = rs.nextSolution();
            // Get title - variable names do not include the '?' (or '$')
            RDFNode x = rb.get("title");
            // Check the type of the result value
            if (x.isLiteral()) {
                Literal titleStr = (Literal) x;
                System.out.println("    " + titleStr);
            } else
                System.out.println("Strange - not a literal: " + x);
        }
    }
}
Also used : IndentedWriter(org.apache.jena.atlas.io.IndentedWriter)

Aggregations

IndentedWriter (org.apache.jena.atlas.io.IndentedWriter)57 SerializationContext (org.apache.jena.sparql.serializer.SerializationContext)5 TerminationException (org.apache.jena.cmd.TerminationException)4 Node (org.apache.jena.graph.Node)4 PrefixMapping (org.apache.jena.shared.PrefixMapping)4 CmdException (org.apache.jena.cmd.CmdException)3 Triple (org.apache.jena.graph.Triple)3 Syntax (org.apache.jena.query.Syntax)3 IOException (java.io.IOException)2 ServletOutputStream (javax.servlet.ServletOutputStream)2 Pair (org.apache.jena.atlas.lib.Pair)2 RiotException (org.apache.jena.riot.RiotException)2 RiotNotFoundException (org.apache.jena.riot.RiotNotFoundException)2 NodeFormatter (org.apache.jena.riot.out.NodeFormatter)2 NodeFormatterTTL (org.apache.jena.riot.out.NodeFormatterTTL)2 JenaException (org.apache.jena.shared.JenaException)2 ARQException (org.apache.jena.sparql.ARQException)2 Var (org.apache.jena.sparql.core.Var)2 Plan (org.apache.jena.sparql.engine.Plan)2 Expr (org.apache.jena.sparql.expr.Expr)2