/** Create a TDB graph using a specifc index builder - mainly for testing */ public static GraphTriplesTDB createGraph(IndexBuilder indexBuilder, Location location) { DatasetGraphTDB ds = _createDatasetGraph(indexBuilder, location, tripleIndexes, quadIndexes) ; return (GraphTriplesTDB)ds.getDefaultGraph() ; }
@Test public void load_graph_02() { DatasetGraphTDB dsg = TDBFactory.createDatasetGraph() ; TDBLoader.load(dsg.getDefaultGraphTDB(), DIR+"data-2.nt", false) ; assertEquals(1, dsg.getDefaultGraph().size()) ; }
@Override public Collection<Node> listSubjects(Node property, Node object) { Collection<Node> nodes = new ArrayList<Node>(); if(bnodePrefix != null && object.isURI() && object.getURI().startsWith(bnodePrefix)){ object = NodeFactory.createAnon(new AnonId(object.getURI().substring(bnodePrefix.length()))); } ExtendedIterator<Triple> it = indexingDataset.getDefaultGraph().find(null, property, object); while(it.hasNext()){ Node subject = it.next().getSubject(); //STANBOL-765: we need also to transform bnodes to URIs for the //RDFBackend implementation if(bnodePrefix != null && subject.isBlank()){ StringBuilder sb = new StringBuilder(bnodePrefix); sb.append(subject.getBlankNodeId().getLabelString()); subject = NodeFactory.createURI(sb.toString()); } nodes.add(subject); } it.close(); return nodes; } /**
@Override public Collection<Node> listObjects(Node subject, Node property) { Collection<Node> nodes = new ArrayList<Node>(); if(bnodePrefix != null && subject.isURI() && subject.getURI().startsWith(bnodePrefix)){ subject = NodeFactory.createAnon(new AnonId(subject.getURI().substring(bnodePrefix.length()))); } ExtendedIterator<Triple> it = indexingDataset.getDefaultGraph().find(subject, property, null); while(it.hasNext()){ //STANBOL-765: we need also to transform bnodes to URIs for the //RDFBackend implementation Node object = it.next().getObject(); if(bnodePrefix != null && object.isBlank()){ StringBuilder sb = new StringBuilder(bnodePrefix); sb.append(object.getBlankNodeId().getLabelString()); object = NodeFactory.createURI(sb.toString()); } nodes.add(object); } it.close(); return nodes; } @Override
@Override public Collection<Node> listSubjects(Node property, Node object) { Collection<Node> nodes = new ArrayList<Node>(); if(bnodePrefix != null && object.isURI() && object.getURI().startsWith(bnodePrefix)){ object = NodeFactory.createAnon(new AnonId(object.getURI().substring(bnodePrefix.length()))); } ExtendedIterator<Triple> it = indexingDataset.getDefaultGraph().find(null, property, object); while(it.hasNext()){ Node subject = it.next().getSubject(); //STANBOL-765: we need also to transform bnodes to URIs for the //RDFBackend implementation if(bnodePrefix != null && subject.isBlank()){ StringBuilder sb = new StringBuilder(bnodePrefix); sb.append(subject.getBlankNodeId().getLabelString()); subject = NodeFactory.createURI(sb.toString()); } nodes.add(subject); } it.close(); return nodes; } /**
@Override public Collection<Node> listObjects(Node subject, Node property) { Collection<Node> nodes = new ArrayList<Node>(); if(bnodePrefix != null && subject.isURI() && subject.getURI().startsWith(bnodePrefix)){ subject = NodeFactory.createAnon(new AnonId(subject.getURI().substring(bnodePrefix.length()))); } ExtendedIterator<Triple> it = indexingDataset.getDefaultGraph().find(subject, property, null); while(it.hasNext()){ //STANBOL-765: we need also to transform bnodes to URIs for the //RDFBackend implementation Node object = it.next().getObject(); if(bnodePrefix != null && object.isBlank()){ StringBuilder sb = new StringBuilder(bnodePrefix); sb.append(object.getBlankNodeId().getLabelString()); object = NodeFactory.createURI(sb.toString()); } nodes.add(object); } it.close(); return nodes; } @Override
ExtendedIterator<Triple> outgoing = null; try { // There may still be exceptions while reading triples outgoing = indexingDataset.getDefaultGraph().find(resource, null, null); found = outgoing.hasNext(); while(outgoing.hasNext()){ //iterate over the statements for that resource
ExtendedIterator<Triple> outgoing = null; try { // There may still be exceptions while reading triples outgoing = indexingDataset.getDefaultGraph().find(resource, null, null); found = outgoing.hasNext(); while(outgoing.hasNext()){ //iterate over the statements for that resource
@Test public void load_graph_01() { DatasetGraphTDB dsg = TDBFactory.createDatasetGraph() ; TDBLoader.load(dsg, DIR+"data-2.nt", false) ; assertEquals(1, dsg.getDefaultGraph().size()) ; }
@Test public void load_dataset_01() { DatasetGraphTDB dsg = TDBFactory.createDatasetGraph() ; TDBLoader.load(dsg, DIR+"data-1.nq", false) ; assertTrue(dsg.getDefaultGraph().isEmpty()) ; assertEquals(1, dsg.getGraph(g).size()) ; }
@Test public void load_dataset_02() { DatasetGraphTDB dsg = TDBFactory.createDatasetGraph() ; InputStream in = IO.openFile(DIR+"data-1.nq") ; TDBLoader.load(dsg, in, false) ; assertTrue(dsg.getDefaultGraph().isEmpty()) ; assertEquals(1, dsg.getGraph(g).size()) ; }
assertEquals(0, dsg.getDefaultGraph().size()) ; assertEquals(1, dsg.getGraph(g).size()) ; List<Triple> x = Iter.toList(dsg.getDefaultGraph().find(null, null, null)) ; assertEquals(0, x.size()) ;