Search in sources :

Example 11 with Dataset

use of org.apache.jena.query.Dataset in project jena by apache.

the class QueryTest method compareDatasetResults.

private void compareDatasetResults(Dataset resultsActual, Query query) {
    if (results != null) {
        try {
            if (!results.isDataset())
                fail("Expected results are not a graph: " + testItem.getName());
            Dataset resultsExpected = results.getDataset();
            if (!IsoMatcher.isomorphic(resultsExpected.asDatasetGraph(), resultsActual.asDatasetGraph())) {
                printFailedDatasetTest(query, resultsExpected, resultsActual);
                fail("Results do not match: " + testItem.getName());
            }
        } catch (Exception ex) {
            String typeName = (query.isConstructType() ? "construct" : "describe");
            fail("Exception in result testing (" + typeName + "): " + ex);
        }
    }
}
Also used : Dataset(org.apache.jena.query.Dataset) QueryException(org.apache.jena.query.QueryException) IOException(java.io.IOException) JenaException(org.apache.jena.shared.JenaException)

Example 12 with Dataset

use of org.apache.jena.query.Dataset in project jena by apache.

the class sdbdump method execCmd.

@Override
protected void execCmd(List<String> args) {
    // This is a streamable syntax.
    String syntax = "N-QUADS";
    if (contains(argDeclSyntax))
        syntax = getArg(argDeclSyntax).getValue();
    Lang lang = RDFLanguages.nameToLang(syntax);
    try {
        if (modGraph.getGraphName() == null) {
            if (!RDFLanguages.isQuads(lang))
                cmdError("Not a 'quads' language (try 'N-Quads' or 'TriG')", true);
            Dataset dataset = getModStore().getDataset();
            RDFDataMgr.write(System.out, dataset, lang);
        } else {
            Model model = modGraph.getModel(getStore());
            RDFDataMgr.write(System.out, model, lang);
        }
    } catch (CmdException ex) {
        throw ex;
    } catch (Exception ex) {
        System.err.println("Exception: " + ex + " :: " + ex.getMessage());
        ex.printStackTrace(System.err);
    }
}
Also used : CmdException(jena.cmd.CmdException) Dataset(org.apache.jena.query.Dataset) Model(org.apache.jena.rdf.model.Model) Lang(org.apache.jena.riot.Lang) CmdException(jena.cmd.CmdException)

Example 13 with Dataset

use of org.apache.jena.query.Dataset in project jena by apache.

the class sdbload method loadOne.

private void loadOne(String filename, boolean replace) {
    Model model = null;
    Dataset dataset = null;
    PrefixMapping pmap;
    Lang lang = RDFLanguages.filenameToLang(filename);
    if (lang == null)
        throw new CmdException("Data syntax not recognized: " + filename);
    // --graph or not
    if (modGraph.getGraphName() != null) {
        model = modGraph.getModel(getStore());
        pmap = model;
    } else {
        dataset = SDBFactory.connectDataset(getStore());
        pmap = dataset.asDatasetGraph().getDefaultGraph().getPrefixMapping();
    }
    // For monitoring only.
    Graph monitorGraph = (model == null) ? null : model.getGraph();
    if (replace) {
        if (model != null)
            model.removeAll();
        else
            dataset.asDatasetGraph().clear();
    }
    boolean showProgress = isVerbose() || getModTime().timingEnabled();
    if (showProgress)
        output.print("Start load: %s", filename);
    StreamRDF stream = streamToStore(pmap, getStore());
    if (modGraph.getGraphName() != null) {
        Node gn = NodeFactory.createURI(modGraph.getGraphName());
        stream = StreamRDFLib.extendTriplesToQuads(gn, stream);
    }
    ProgressMonitor progress = null;
    if (showProgress) {
        progress = new ProgressMonitor(filename, 100_000, 10, output);
        stream = new ProgressStreamRDF(stream, progress);
    }
    if (progress != null)
        progress.start();
    // Load!
    RDFDataMgr.parse(stream, filename, lang);
    if (progress != null) {
        progress.finish();
        progress.finishMessage();
    }
}
Also used : ProgressMonitor(org.apache.jena.atlas.lib.ProgressMonitor) PrefixMapping(org.apache.jena.shared.PrefixMapping) Graph(org.apache.jena.graph.Graph) ModGraph(sdb.cmd.ModGraph) ProgressStreamRDF(org.apache.jena.riot.system.ProgressStreamRDF) CmdException(jena.cmd.CmdException) ProgressStreamRDF(org.apache.jena.riot.system.ProgressStreamRDF) StreamRDF(org.apache.jena.riot.system.StreamRDF) Dataset(org.apache.jena.query.Dataset) Node(org.apache.jena.graph.Node) Model(org.apache.jena.rdf.model.Model) Lang(org.apache.jena.riot.Lang)

Example 14 with Dataset

use of org.apache.jena.query.Dataset 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 15 with Dataset

use of org.apache.jena.query.Dataset in project jena by apache.

the class StoreUtils method containsGraph.

public static boolean containsGraph(Store store, Node graphNode) {
    String qs = "SELECT * { GRAPH " + FmtUtils.stringForNode(graphNode) + " { ?s ?p ?o }} LIMIT 1";
    Dataset ds = SDBFactory.connectDataset(store);
    try (QueryExecution qExec = QueryExecutionFactory.create(qs, ds)) {
        ResultSet rs = qExec.execSelect();
        return rs.hasNext();
    }
}
Also used : Dataset(org.apache.jena.query.Dataset) ResultSet(org.apache.jena.query.ResultSet) QueryExecution(org.apache.jena.query.QueryExecution)

Aggregations

Dataset (org.apache.jena.query.Dataset)725 Test (org.junit.Test)401 Model (org.apache.jena.rdf.model.Model)173 Ignore (org.junit.Ignore)93 URI (java.net.URI)80 Resource (org.apache.jena.rdf.model.Resource)70 QueryExecution (org.apache.jena.query.QueryExecution)53 ArrayList (java.util.ArrayList)46 QuerySolution (org.apache.jena.query.QuerySolution)46 ResultSet (org.apache.jena.query.ResultSet)45 WonNodeInformationService (won.protocol.service.WonNodeInformationService)28 Statement (org.apache.jena.rdf.model.Statement)26 Node (org.apache.jena.graph.Node)23 InputStream (java.io.InputStream)22 RDFNode (org.apache.jena.rdf.model.RDFNode)21 RdfUtils (won.protocol.util.RdfUtils)19 WonMessage (won.protocol.message.WonMessage)17 Literal (org.apache.jena.rdf.model.Literal)16 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)16 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)16