use of org.apache.jena.graph.Graph 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.graph.Graph in project jena by apache.
the class RDFDataMgr method loadGraph.
/** Create a memory Graph and read in some data
* @see #read(Graph,String,Lang)
*/
public static Graph loadGraph(String uri, Lang lang) {
Graph g = createGraph();
read(g, uri, lang);
return g;
}
use of org.apache.jena.graph.Graph in project jena by apache.
the class RDFDataMgr method read.
/** Read triples into a model with chars from a StringReader.
* @param model Destination for the RDF read.
* @param in InputStream
* @param base Base URI
* @param lang Language syntax
*/
public static void read(Model model, StringReader in, String base, Lang lang) {
Graph g = model.getGraph();
StreamRDF dest = StreamRDFLib.graph(g);
parseFromReader(dest, in, base, lang, (Context) null);
}
use of org.apache.jena.graph.Graph in project jena by apache.
the class DatasetGraphCollection method delete.
@Override
public void delete(Quad quad) {
Graph g = fetchGraph(quad.getGraph());
if (g == null)
throw new JenaException("No such graph: " + quad.getGraph());
g.delete(quad.asTriple());
}
use of org.apache.jena.graph.Graph in project jena by apache.
the class DynamicDatasets method dynamicDataset.
/** Given a DatasetGraph and a query, form a DatasetGraph that
* is the dynamic dataset from the collection of graphs from the dataset
* that go to make up the default graph (union) and named graphs.
*/
public static DatasetGraph dynamicDataset(Collection<Node> defaultGraphs, Collection<Node> namedGraphs, DatasetGraph dsg, boolean defaultUnionGraph) {
Graph dft = new GraphUnionRead(dsg, defaultGraphs);
DatasetGraph dsg2 = new DatasetGraphMapLink(dft);
// The named graphs.
for (Node gn : namedGraphs) {
Graph g = GraphOps.getGraph(dsg, gn);
if (g != null)
dsg2.addGraph(gn, g);
}
if (dsg.getContext() != null)
dsg2.getContext().putAll(dsg.getContext());
if (defaultUnionGraph && defaultGraphs.size() == 0) {
// Create a union graph - there were no defaultGraphs explicitly named.
Graph unionGraph = new GraphUnionRead(dsg, namedGraphs);
dsg2.setDefaultGraph(unionGraph);
}
// read-only, <urn:x-arq:DefaultGraph> and <urn:x-arq:UnionGraph> processing.
dsg2 = new DynamicDatasetGraph(dsg2);
// Record what we've done.
// c.f. "ARQConstants.sysDatasetDescription" which is used to pass in a DatasetDescription
dsg2.getContext().set(ARQConstants.symDatasetDefaultGraphs, defaultGraphs);
dsg2.getContext().set(ARQConstants.symDatasetNamedGraphs, namedGraphs);
return dsg2;
}
Aggregations