Search in sources :

Example 1 with PlainFormat

use of org.apache.jena.sparql.resultset.PlainFormat in project jena by apache.

the class QueryExecUtils method outputResultSet.

@SuppressWarnings("deprecation")
public static void outputResultSet(ResultSet results, Prologue prologue, ResultsFormat outputFormat) {
    // Proper ResultSet formats.
    Lang lang = ResultsFormat.convert(outputFormat);
    if (lang != null) {
        ResultSetMgr.write(System.out, results, lang);
        System.out.flush();
        return;
    }
    // Old way.
    boolean done = false;
    if (prologue == null)
        prologue = new Prologue(globalPrefixMap);
    if (outputFormat.equals(ResultsFormat.FMT_UNKNOWN))
        outputFormat = ResultsFormat.FMT_TEXT;
    if (outputFormat.equals(ResultsFormat.FMT_NONE) || outputFormat.equals(ResultsFormat.FMT_COUNT)) {
        int count = ResultSetFormatter.consume(results);
        if (outputFormat.equals(ResultsFormat.FMT_COUNT)) {
            System.out.println("Count = " + count);
        }
        done = true;
    }
    if (outputFormat.equals(ResultsFormat.FMT_RDF_XML) || outputFormat.equals(ResultsFormat.FMT_RDF_N3) || outputFormat.equals(ResultsFormat.FMT_RDF_TTL)) {
        Model m = RDFOutput.encodeAsModel(results);
        m.setNsPrefixes(prologue.getPrefixMapping());
        m.setNsPrefix("rs", ResultSetGraphVocab.getURI());
        RDFDataMgr.write(System.out, m, Lang.TURTLE);
        done = true;
    }
    if (outputFormat.equals(ResultsFormat.FMT_RS_XML)) {
        ResultSetFormatter.outputAsXML(System.out, results);
        done = true;
    }
    if (outputFormat.equals(ResultsFormat.FMT_RS_JSON)) {
        ResultSetFormatter.outputAsJSON(System.out, results);
        done = true;
    }
    if (outputFormat.equals(ResultsFormat.FMT_RS_SSE)) {
        ResultSetFormatter.outputAsSSE(System.out, results, prologue);
        done = true;
    }
    if (outputFormat.equals(ResultsFormat.FMT_TEXT)) {
        ResultSetFormatter.out(System.out, results, prologue);
        done = true;
    }
    if (outputFormat.equals(ResultsFormat.FMT_TUPLES)) {
        PlainFormat pFmt = new PlainFormat(System.out, prologue);
        ResultSetApply a = new ResultSetApply(results, pFmt);
        a.apply();
        done = true;
    }
    if (outputFormat.equals(ResultsFormat.FMT_RS_CSV)) {
        ResultSetFormatter.outputAsCSV(System.out, results);
        done = true;
    }
    if (outputFormat.equals(ResultsFormat.FMT_RS_TSV)) {
        ResultSetFormatter.outputAsTSV(System.out, results);
        done = true;
    }
    if (outputFormat.equals(ResultsFormat.FMT_RS_BIO)) {
        ResultSetFormatter.outputAsBIO(System.out, results);
        done = true;
    }
    if (!done)
        System.err.println("Unknown format request: " + outputFormat);
    results = null;
    System.out.flush();
}
Also used : Prologue(org.apache.jena.sparql.core.Prologue) ResultSetApply(org.apache.jena.sparql.resultset.ResultSetApply) Model(org.apache.jena.rdf.model.Model) Lang(org.apache.jena.riot.Lang) PlainFormat(org.apache.jena.sparql.resultset.PlainFormat)

Aggregations

Model (org.apache.jena.rdf.model.Model)1 Lang (org.apache.jena.riot.Lang)1 Prologue (org.apache.jena.sparql.core.Prologue)1 PlainFormat (org.apache.jena.sparql.resultset.PlainFormat)1 ResultSetApply (org.apache.jena.sparql.resultset.ResultSetApply)1