org.apache.jena.sparql.serializer.SerializationContext Java Examples

The following examples show how to use org.apache.jena.sparql.serializer.SerializationContext. 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: tarql.java    From tarql with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void processResults(TarqlQueryExecution ex) throws IOException {
	if (testQuery && ex.getFirstQuery().getConstructTemplate() != null) {
		IndentedWriter out = new IndentedWriter(System.out); 
		new FmtTemplate(out, new SerializationContext(ex.getFirstQuery())).format(ex.getFirstQuery().getConstructTemplate());
		out.flush();
	}
	if (ex.getFirstQuery().isSelectType()) {
		System.out.println(ResultSetFormatter.asText(ex.execSelect()));
	} else if (ex.getFirstQuery().isAskType()) {
		System.out.println(ResultSetFormatter.asText(ex.execSelect()));
	} else if (ex.getFirstQuery().isConstructType()) {
		resultTripleIterator = resultTripleIterator.andThen(ex.execTriples());
	} else {
		cmdError("Only query forms CONSTRUCT, SELECT and ASK are supported");
	}
}
 
Example #2
Source File: SPARQLExtQuerySerializer.java    From sparql-generate with Apache License 2.0 6 votes vote down vote up
private void printSubGenerate(SPARQLExtQuery q) {
    if (!q.isGenerateType()) {
        throw new IllegalArgumentException("FROM GENERATE: expecting a generate query");
    }
    out.incIndent(INDENT);
    QuerySerializerFactory factory = SerializerRegistry.get().getQuerySerializerFactory(SPARQLExt.SYNTAX);
    SPARQLExtQueryVisitor visitor = (SPARQLExtQueryVisitor) factory.create(SPARQLExt.SYNTAX, new SerializationContext(q.getPrologue()), out);

    visitor.startVisit(q);
    visitor.visitGenerateClause(q);
    visitor.visitDatasetDecl(q);
    visitor.visitBindingClauses(q);
    visitor.visitQueryPattern(q);
    visitor.visitGroupBy(q);
    visitor.visitHaving(q);
    visitor.visitOrderBy(q);
    visitor.visitOffset(q);
    visitor.visitLimit(q);
    visitor.visitPostSelect(q);
    visitor.visitValues(q);
    visitor.finishVisit(q);

    out.decIndent(INDENT);
}
 
Example #3
Source File: SPARQLExtQuerySerializer.java    From sparql-generate with Apache License 2.0 6 votes vote down vote up
private static void outputValuesOneRow(IndentedWriter out, List<Var> variables, Binding row, SerializationContext cxt) {
    // A value may be null for UNDEF
    for (Var var : variables) {
        out.print(" ");
        Node value = row.get(var);
        if (value == null) {
            out.print("UNDEF");
        } else {
            // Context for bnodes.
            // Bnodes don't occur in legal syntax but a rewritten query may
            // have them.  The output will not be legal SPARQL.
            // ARQ (SPARQL with extensions) does parse blankd nodes in VALUES. 
            SPARQLExtFmtUtils.printNode(out, value, cxt);
        }
    }
}
 
Example #4
Source File: SPARQLExtFmtUtils.java    From sparql-generate with Apache License 2.0 5 votes vote down vote up
public static void formatPattern(IndentedWriter out, BasicPattern pattern, SerializationContext sCxt) {
    boolean first = true;
    for (Triple triple : pattern) {
        if (!first) {
            out.print("\n");
        }
        printTriple(out, triple, sCxt);
        out.print(" .");
        first = false;
    }
}
 
Example #5
Source File: Node_Extended.java    From sparql-generate with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public String toString() {
    IndentedLineBuffer buff = new IndentedLineBuffer();
    buff.print("?" + label + " := ");
    SerializationContext context = new SerializationContext();
    SPARQLExtFmtUtils.printNode(buff, this, context);
    return buff.toString();
}
 
Example #6
Source File: SPARQLExtQuerySerializer.java    From sparql-generate with Apache License 2.0 5 votes vote down vote up
static void appendURIList(Query query, IndentedWriter sb, List<Node> vars) {
    SerializationContext cxt = new SerializationContext(query);
    boolean first = true;
    for (Node node : vars) {
        if (!first) {
            sb.print(" ");
        }
        SPARQLExtFmtUtils.printNode(sb, node, cxt);
        first = false;
    }
}
 
Example #7
Source File: SPARQLExtQuerySerializer.java    From sparql-generate with Apache License 2.0 5 votes vote down vote up
public SPARQLExtQuerySerializer(IndentedWriter out, SerializationContext context) {
    this.out = out;
    this.context = context;
    this.fmtTemplate = new SPARQLExtFormatterTemplate(out, context);
    this.fmtExpr = new SPARQLExtFmtExprSPARQL(out, context);
    this.fmtElement = new SPARQLExtFormatterElement(out, context);
}
 
Example #8
Source File: SPARQLExtFmtUtils.java    From sparql-generate with Apache License 2.0 5 votes vote down vote up
public static void fmtSPARQL(IndentedWriter iOut, ExprList exprs, SerializationContext pmap) {
    SPARQLExtFmtExprSPARQL fmt = new SPARQLExtFmtExprSPARQL(iOut, pmap);
    String sep = "";
    for (Expr expr : exprs) {
        iOut.print(sep);
        sep = " , ";
        fmt.format(expr);
    }
}
 
Example #9
Source File: SPARQLExtFmtUtils.java    From sparql-generate with Apache License 2.0 5 votes vote down vote up
public static void printTriple(IndentedWriter out, Triple triple, SerializationContext sCxt) {
    printNode(out, triple.getSubject(), sCxt);
    out.print(" ");
    printNode(out, triple.getPredicate(), sCxt);
    out.print(" ");
    printNode(out, triple.getObject(), sCxt);
}
 
Example #10
Source File: SPARQLExtFmtExprSPARQL.java    From sparql-generate with Apache License 2.0 5 votes vote down vote up
public SPARQLGenerateFmtExprARQVisitor(IndentedWriter writer, SerializationContext cxt) {
	out = writer;
	if (cxt == null) {
		context = new SerializationContext();
	} else {
		context = cxt;
	}
}
 
Example #11
Source File: SPARQLExtFormatterElement.java    From sparql-generate with Apache License 2.0 5 votes vote down vote up
@Override
public void visit(ElementSubExtQuery el) {
    SPARQLExtQuery q = el.getQuery();
    if (!q.isGenerateType() && !q.isTemplateType() && !q.isPerformType()) {
        throw new IllegalArgumentException("Sub-query is expected to be a generate, template, or perform query");
    }
    out.incIndent(INDENT);
    QuerySerializerFactory factory = SerializerRegistry.get().getQuerySerializerFactory(SPARQLExt.SYNTAX);
    SPARQLExtQueryVisitor visitor = (SPARQLExtQueryVisitor) factory.create(SPARQLExt.SYNTAX, new SerializationContext(q.getPrologue()), out);

    visitor.startVisit(q);
    if (q.isGenerateType()) {
        visitor.visitGenerateClause(q);
    } else if (q.isTemplateType()) {
        visitor.visitTemplateClause(q);
    } else if (q.isPerformType()) {
        visitor.visitPerformClause(q);
    }
    visitor.visitDatasetDecl(q);
    visitor.visitBindingClauses(q);
    visitor.visitQueryPattern(q);
    visitor.visitGroupBy(q);
    visitor.visitHaving(q);
    visitor.visitOrderBy(q);
    visitor.visitOffset(q);
    visitor.visitLimit(q);
    visitor.visitPostSelect(q);
    visitor.visitValues(q);
    visitor.finishVisit(q);

    out.print(" .");
    out.decIndent(INDENT);
    out.newline();
}
 
Example #12
Source File: SPARQLExtFmtExprSPARQL.java    From sparql-generate with Apache License 2.0 4 votes vote down vote up
public SPARQLExtFmtExprSPARQL(IndentedWriter writer, SerializationContext cxt) {
	super(writer, cxt);
	visitor = new SPARQLGenerateFmtExprARQVisitor(writer, cxt);
}
 
Example #13
Source File: SPARQLExtPathWriter.java    From sparql-generate with Apache License 2.0 4 votes vote down vote up
PathWriterWorker(IndentedWriter indentedWriter, SerializationContext context) {
    this.out = indentedWriter;
    this.context = context;
}
 
Example #14
Source File: SPARQLExtPathWriter.java    From sparql-generate with Apache License 2.0 4 votes vote down vote up
public static void write(IndentedWriter out, Path path, SerializationContext context) {
    PathWriterWorker w = new PathWriterWorker(out, context);
    path.visit(w);
    out.flush();
}
 
Example #15
Source File: SPARQLExtFormatterElement.java    From sparql-generate with Apache License 2.0 4 votes vote down vote up
@Override
public void visit(ElementData el) {
    QuerySerializer.outputDataBlock(out, el.getVars(), el.getRows(), new SerializationContext(context.getPrologue()));
}
 
Example #16
Source File: SPARQLExtFormatterElement.java    From sparql-generate with Apache License 2.0 4 votes vote down vote up
public SPARQLExtFormatterElement(IndentedWriter out, SerializationContext context) {
    super(out, context);
}
 
Example #17
Source File: SPARQLExtFormatterTemplate.java    From sparql-generate with Apache License 2.0 4 votes vote down vote up
public SPARQLExtFormatterTemplate(IndentedWriter out, SerializationContext context) {
    super(out, context);
}
 
Example #18
Source File: SPARQLExtFormatterBase.java    From sparql-generate with Apache License 2.0 4 votes vote down vote up
protected SPARQLExtFormatterBase(IndentedWriter _out, SerializationContext _context) {
    out = _out;
    context = _context;
}
 
Example #19
Source File: ConsoleStreamRDF.java    From sparql-generate with Apache License 2.0 4 votes vote down vote up
public ConsoleStreamRDF(PrintStream out, PrefixMapping pm) {
    this.out = out;
    this.pm = pm;
    context = new SerializationContext(pm);
}
 
Example #20
Source File: SPARQLStar.java    From RDFstarTools with Apache License 2.0 4 votes vote down vote up
@Override
      public QueryVisitor create(Syntax syntax, SerializationContext context, IndentedWriter writer) {
	return wrappedFactory.create(syntax, context, writer);
}
 
Example #21
Source File: SPARQLExt.java    From sparql-generate with Apache License 2.0 4 votes vote down vote up
@Override
public QueryVisitor create(Syntax syntax, Prologue prologue, IndentedWriter writer) {
    SerializationContext context = new SerializationContext(prologue, new NodeToLabelMapBNode("bn", false));
    return new SPARQLExtQuerySerializer(writer, context);
}
 
Example #22
Source File: SPARQLExt.java    From sparql-generate with Apache License 2.0 4 votes vote down vote up
@Override
public QueryVisitor create(Syntax syntax, SerializationContext context, IndentedWriter writer) {
    return new SPARQLExtQuerySerializer(writer, context);
}
 
Example #23
Source File: ResultSetWritersSPARQLStar.java    From RDFstarTools with Apache License 2.0 4 votes vote down vote up
protected TextOutput createTextOutput() {
	final SerializationContext sc = new SerializationContext( (Prologue)null );
    return new TextOutputStar( sc );
}
 
Example #24
Source File: TextOutputStar.java    From RDFstarTools with Apache License 2.0 votes vote down vote up
public TextOutputStar(SerializationContext cxt) { super(cxt); }