use of org.apache.jena.atlas.io.IndentedWriter in project jena by apache.
the class TestFmtUtils method formatPattern_2_triples.
@Test
public void formatPattern_2_triples() {
BasicPattern basicPattern = new BasicPattern();
basicPattern.add(getTriple());
basicPattern.add(getTriple2());
ByteArrayOutputStream os = new ByteArrayOutputStream();
try (IndentedWriter iw = new IndentedWriter(os)) {
SerializationContext sc = new SerializationContext();
FmtUtils.formatPattern(iw, basicPattern, sc);
}
assertEquals("<n1> <n2> \"l3\" .\n" + "<nb1> <nb2> \"lb3\" .", new String(os.toByteArray()));
}
use of org.apache.jena.atlas.io.IndentedWriter in project jena by apache.
the class Query method serialize.
/**
* Output the query
*
* @param out OutputStream
* @param syntax Syntax URI
*/
public void serialize(OutputStream out, Syntax syntax) {
IndentedWriter writer = new IndentedWriter(out);
serialize(writer, syntax);
writer.flush();
try {
out.flush();
} catch (Exception ex) {
}
}
use of org.apache.jena.atlas.io.IndentedWriter in project jena by apache.
the class QueryOutputUtils method printQuad.
public static void printQuad(Query query, boolean printOptimized) {
IndentedWriter out = IndentedWriter.stdout;
// Flush done
printQuad(out, query, printOptimized);
}
use of org.apache.jena.atlas.io.IndentedWriter in project jena by apache.
the class AbstractTestJoin method print.
protected static void print(String msg, JoinKey joinKey, Table left, Table right, ExprList conditions, Table expected, Table actual) {
System.err.flush();
System.out.flush();
IndentedWriter out = IndentedWriter.stderr;
out.println("Test : " + msg);
out.println("Joinkey: " + joinKey);
print(out, "Left:", left);
print(out, "Right:", right);
if (conditions != null)
out.println("Conditions: " + conditions);
print(out, "Expected:", expected);
print(out, "Actual:", actual);
out.println();
out.flush();
}
use of org.apache.jena.atlas.io.IndentedWriter in project jena by apache.
the class ExProg2 method main.
public static void main(String[] args) {
Model model = createModel();
Query query = QueryFactory.make();
query.setQuerySelectType();
// See also ExProg1
ElementGroup elg = new ElementGroup();
Var varTitle = Var.alloc("title");
Var varX = Var.alloc("x");
Triple t1 = new Triple(varX, DC.title.asNode(), varTitle);
elg.addTriplePattern(t1);
// Adds a filter. Need to wrap variable in a NodeVar.
Expr expr = new E_Regex(new ExprVar(varTitle), "sparql", "i");
ElementFilter filter = new ElementFilter(expr);
elg.addElementFilter(filter);
// Attach the group to query.
query.setQueryPattern(elg);
// Choose what we want - SELECT ?title
query.addResultVar(varTitle);
// Print query with line numbers
// Prefix mapping just helps serialization
query.getPrefixMapping().setNsPrefix("dc", DC.getURI());
query.serialize(new IndentedWriter(System.out, true));
System.out.println();
try (QueryExecution qexec = QueryExecutionFactory.create(query, model)) {
// Assumption: it's a SELECT query.
ResultSet rs = qexec.execSelect();
// The order of results is undefined.
System.out.println("Titles: ");
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 instanceof Literal) {
Literal titleStr = (Literal) x;
System.out.println(" " + titleStr);
} else
System.out.println("Strange - not a literal: " + x);
}
}
}
Aggregations