use of org.apache.jena.sparql.core.DatasetGraph in project jena by apache.
the class BuilderGraph method buildDataset.
public static DatasetGraph buildDataset(DatasetGraph dsg, ItemList list) {
BuilderLib.checkTag(list, Tags.tagDataset);
list = list.cdr();
for (Item item : list) {
if (!item.isTagged(Tags.tagGraph)) {
// Not (graph ...) so it's (quad), short form quad or an error.
Quad q = BuilderGraph.buildQuad(item.getList(), "Expected (graph ...) or a quad () as elements of a dataset");
dsg.add(q);
continue;
}
Node name = null;
ItemList graphContent = item.getList().cdr();
if (!graphContent.isEmpty() && graphContent.car().isNode()) {
name = graphContent.car().getNode();
graphContent = graphContent.cdr();
}
Graph g;
if (name == null) {
g = dsg.getDefaultGraph();
if (g == null) {
g = GraphFactory.createDefaultGraph();
dsg.setDefaultGraph(g);
}
} else {
g = dsg.getGraph(name);
if (g == null) {
g = GraphFactory.createDefaultGraph();
dsg.addGraph(name, g);
}
}
BuilderGraph.buildGraph(g, graphContent);
}
return dsg;
}
use of org.apache.jena.sparql.core.DatasetGraph in project jena by apache.
the class WriterGraph method writeDataset.
// ---- Workers
private static void writeDataset(IndentedWriter out, DatasetGraph ds, SerializationContext naming) {
WriterLib.start(out, Tags.tagDataset, NL);
writeGraph(out, ds.getDefaultGraph(), naming);
out.ensureStartOfLine();
for (Iterator<Node> iter = ds.listGraphNodes(); iter.hasNext(); ) {
Node node = iter.next();
out.ensureStartOfLine();
Graph g = ds.getGraph(node);
writeGraph(out, g, node, naming);
}
WriterLib.finish(out, Tags.tagDataset);
out.ensureStartOfLine();
}
use of org.apache.jena.sparql.core.DatasetGraph in project jena by apache.
the class TestDatasetGraphInMemoryBasic method orderingOfNodesFromFindIsCorrect.
@Test
public void orderingOfNodesFromFindIsCorrect() {
final DatasetGraph dsg = DatasetGraphFactory.createTxnMem();
final Node p = parseNode(":p");
final Triple triple = parseTriple("(:s :p :o)");
dsg.getDefaultGraph().add(triple);
final Iterator<Triple> iter = dsg.getDefaultGraph().find(null, p, null);
assertTrue(some(iter, triple::equals));
final Node p1 = parseNode(":p1");
final Quad quad = parseQuad("(:g1 :s1 :p1 :o1)");
dsg.add(quad);
final Iterator<Quad> iter2 = dsg.find(null, null, p1, null);
assertTrue(some(iter2, quad::equals));
Iter.print(err, iter2);
}
use of org.apache.jena.sparql.core.DatasetGraph in project jena by apache.
the class TestDatasetGraphInMemoryBasic method prefixesAreManaged.
@Test
public void prefixesAreManaged() {
final Node graphName = createURI("http://example/g");
final DatasetGraph dsg = emptyDataset();
dsg.addGraph(graphName, createGraphMem());
final Dataset dataset = DatasetFactory.wrap(dsg);
Model model = dataset.getNamedModel(graphName.getURI());
final String testPrefix = "example";
final String testURI = "http://example/";
model.setNsPrefix(testPrefix, testURI);
assertEquals(testURI, model.getNsPrefixURI(testPrefix));
model.close();
model = dataset.getNamedModel(graphName.getURI());
final String nsURI = dataset.getNamedModel(graphName.getURI()).getNsPrefixURI(testPrefix);
assertNotNull(nsURI);
assertEquals(testURI, nsURI);
}
use of org.apache.jena.sparql.core.DatasetGraph in project jena by apache.
the class AbstractDatasetGraphTests method quad_04.
@Test
public void quad_04() {
DatasetGraph dsg = emptyDataset();
assertNotNull(dsg);
Quad quad1 = SSE.parseQuad("(quad <g> <s> <p> <o1>)");
Quad quad2 = SSE.parseQuad("(quad <g> <s> <p> <o2>)");
dsg.add(quad1);
dsg.add(quad2);
Iterator<Quad> iter = dsg.find(NodeFactory.createURI("g"), NodeFactory.createURI("s"), null, null);
assertTrue(iter.hasNext());
Set<Quad> x = Iter.iter(iter).toSet();
assertEquals(2, x.size());
assertTrue(x.contains(quad1));
assertTrue(x.contains(quad2));
}
Aggregations