Search in sources :

Example 1 with ResultsFormat

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

the class QueryCommandAssembler method open.

@Override
public Object open(Assembler a, Resource root, Mode mode) {
    // Query
    Resource queryDesc = getUniqueResource(root, AssemblerVocab.pQuery);
    Query query = (Query) a.open(a, queryDesc, mode);
    // Dataset
    Resource datasetDesc = getUniqueResource(root, AssemblerVocab.pDataset);
    Dataset dataset = (Dataset) a.open(a, datasetDesc, mode);
    // Output format
    String s = GraphUtils.getStringValue(root, AssemblerVocab.pOutputFormat);
    if (s == null)
        s = "text";
    ResultsFormat format = ResultsFormat.lookup(s);
    QueryExecution qExec = QueryExecutionFactory.create(query, dataset);
    return new QExec(query, qExec, format);
}
Also used : Query(org.apache.jena.query.Query) Dataset(org.apache.jena.query.Dataset) Resource(org.apache.jena.rdf.model.Resource) ResultsFormat(org.apache.jena.sparql.resultset.ResultsFormat) QueryExecution(org.apache.jena.query.QueryExecution)

Example 2 with ResultsFormat

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

the class TestItem method getResults.

/**
     * Load results as a SPARQLResult. If the results are a model, no conversion
     * to a result set is attempted here.
     */
public SPARQLResult getResults() {
    if (resultFile == null)
        return null;
    ResultsFormat format = ResultsFormat.guessSyntax(resultFile);
    if (ResultsFormat.isRDFGraphSyntax(format)) {
        Model m = FileManager.get().loadModel(resultFile);
        return new SPARQLResult(m);
    }
    if (ResultsFormat.isDatasetSyntax(format)) {
        Dataset d = RDFDataMgr.loadDataset(resultFile);
        return new SPARQLResult(d);
    }
    // Attempt to handle as a resulset or boolean result.s
    SPARQLResult x = ResultSetFactory.result(resultFile);
    return x;
}
Also used : Dataset(org.apache.jena.query.Dataset) Model(org.apache.jena.rdf.model.Model) SPARQLResult(org.apache.jena.sparql.resultset.SPARQLResult) ResultsFormat(org.apache.jena.sparql.resultset.ResultsFormat)

Aggregations

Dataset (org.apache.jena.query.Dataset)2 ResultsFormat (org.apache.jena.sparql.resultset.ResultsFormat)2 Query (org.apache.jena.query.Query)1 QueryExecution (org.apache.jena.query.QueryExecution)1 Model (org.apache.jena.rdf.model.Model)1 Resource (org.apache.jena.rdf.model.Resource)1 SPARQLResult (org.apache.jena.sparql.resultset.SPARQLResult)1