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);
}
}
}
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);
}
}
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();
}
}
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);
}
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();
}
}
Aggregations