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;
}
use of org.apache.jena.graph.Graph in project jena by apache.
the class TestAPI method testARQConstructQuad_bnodes.
@Test
public void testARQConstructQuad_bnodes() {
String queryString = "PREFIX : <http://example/> CONSTRUCT { :s :p :o GRAPH _:a { :s :p :o1 } } WHERE { }";
Query q = QueryFactory.create(queryString, Syntax.syntaxARQ);
QueryExecution qExec = QueryExecutionFactory.create(q, d);
Dataset ds = qExec.execConstructDataset();
assertEquals(1, Iter.count(ds.asDatasetGraph().listGraphNodes()));
Node n = ds.asDatasetGraph().listGraphNodes().next();
assertTrue(n.isBlank());
Graph g = ds.asDatasetGraph().getGraph(n);
assertNotNull(g);
assertFalse(g.isEmpty());
}
Aggregations