@Override public int size() { int result = (int)graph.size(); return result; }
@Override public long size() { return getLeft().size(); }
@Override public long size() { return getR().size(); }
@Override protected final long add(QuadWritable value) { g.add(value.get()); return g.size(); }
@Override protected final long add(QuadWritable value) { g.add(value.get()); return g.size(); }
@SuppressWarnings("deprecation") @Override protected final long writeOutput(Writer writer) { if (this.g.size() == 0) return 0; RDFDataMgr.write(writer, this.g, RDFWriterRegistry.defaultSerialization(this.getRdfLanguage())); // Clear the dataset graph @SuppressWarnings("unchecked") List<Node> graphNames = IteratorUtils.toList(this.g.listGraphNodes()); for (Node graphName : graphNames) { this.g.removeGraph(graphName); } this.g.getDefaultGraph().clear(); return this.g.size(); }
@Override protected Model makeSuccessMessage(CrawlConnectionCommandSuccessEvent successEvent) { crawlStopWatch.stop(); Duration crawlDuration = Duration.ofMillis(crawlStopWatch.getLastTaskTimeMillis()); Dataset conversation = successEvent.getCrawledData(); return WonRdfUtils.MessageUtils .textMessage("Finished crawl in " + getDurationString(crawlDuration) + " seconds. The dataset has " + conversation.asDatasetGraph().size() + " rdf graphs."); }
@SuppressWarnings("deprecation") @Override protected final long writeOutput(Writer writer) { if (this.g.size() == 0) return 0; RDFDataMgr.write(writer, this.g, RDFWriterRegistry.defaultSerialization(this.getRdfLanguage())); // Clear the dataset graph @SuppressWarnings("unchecked") List<Node> graphNames = IteratorUtils.toList(this.g.listGraphNodes()); for (Node graphName : graphNames) { this.g.removeGraph(graphName); } this.g.getDefaultGraph().clear(); return this.g.size(); }
private void referToEarlierMessages(EventListenerContext ctx, EventBus bus, Connection con, String crawlAnnouncement, MessageFinder messageFinder, MessageReferrer messageReferrer, TextMessageMaker textMessageMaker) { Model messageModel = WonRdfUtils.MessageUtils .textMessage(crawlAnnouncement); bus.publish(new ConnectionMessageCommandEvent(con, messageModel)); // initiate crawl behaviour CrawlConnectionCommandEvent command = new CrawlConnectionCommandEvent(con.getNeedURI(), con.getConnectionURI()); CrawlConnectionDataBehaviour crawlConnectionDataBehaviour = new CrawlConnectionDataBehaviour(ctx, command, Duration.ofSeconds(60)); final StopWatch crawlStopWatch = new StopWatch(); crawlStopWatch.start("crawl"); AgreementProtocolState state = WonConversationUtils.getAgreementProtocolState(con.getConnectionURI(), ctx.getLinkedDataSource()); crawlStopWatch.stop(); Duration crawlDuration = Duration.ofMillis(crawlStopWatch.getLastTaskTimeMillis()); messageModel = WonRdfUtils.MessageUtils .textMessage("Finished crawl in " + getDurationString(crawlDuration) + " seconds. The dataset has " + state.getConversationDataset().asDatasetGraph().size() + " rdf graphs."); getEventListenerContext().getEventBus().publish(new ConnectionMessageCommandEvent(con, messageModel)); messageModel = makeReferringMessage(state, messageFinder, messageReferrer, textMessageMaker); getEventListenerContext().getEventBus().publish(new ConnectionMessageCommandEvent(con, messageModel)); crawlConnectionDataBehaviour.activate(); }
@Test public void dataset_1() { // This must parse to <g> DatasetGraph dsg = parseToDataset("<x> <p> <s> <g> ."); assertEquals(1, dsg.size()); assertEquals(1, dsg.getGraph(NodeFactory.createURI("g")).size()); assertEquals(0, dsg.getDefaultGraph().size()); }
@Test public void dataset5() { String graphName = "http://example/" ; Triple triple = SSE.parseTriple("(<x> <y> <z>)") ; Dataset ds = graphLocation.getDataset() ; Graph g2 = ds.asDatasetGraph().getGraph(org.apache.jena.graph.NodeFactory.createURI(graphName)) ; // Graphs only exists if they have a triple in them g2.add(triple) ; assertTrue(ds.containsNamedModel(graphName)) ; List<String> x = Iter.toList(ds.listNames()) ; List<String> y = Arrays.asList(graphName) ; assertEquals(x,y) ; assertEquals(1, ds.asDatasetGraph().size()) ; } }
@Test public void dataset5() { String graphName = "http://example/" ; Triple triple = SSE.parseTriple("(<x> <y> <z>)") ; Dataset ds = graphLocation.getDataset() ; Graph g2 = ds.asDatasetGraph().getGraph(org.apache.jena.graph.NodeFactory.createURI(graphName)) ; // Graphs only exists if they have a triple in them g2.add(triple) ; assertTrue(ds.containsNamedModel(graphName)) ; List<String> x = Iter.toList(ds.listNames()) ; List<String> y = Arrays.asList(graphName) ; assertEquals(x,y) ; assertEquals(1, ds.asDatasetGraph().size()) ; } }
@Test public void filtered2() { Predicate<Quad> filter = x->x.getGraph().equals(g2); Txn.executeRead(basedsg, ()->{ DatasetGraph dsg = new DatasetGraphFilteredView(basedsg, filter, Collections.singleton(g1)); long x0 = Iter.count(dsg.find(null, null, null, null)); assertEquals(2,x0); long x1 = Iter.count(dsg.find(g2, null, null, null)); assertEquals(2,x1); long x2 = Iter.count(dsg.find(null, s2, null, null)); assertEquals(2,x2); long x3 = Iter.count(dsg.find(g1, null, null, null)); assertEquals(0,x3); assertEquals(1, dsg.size()); }); }
@Test public void dataset4() { String graphName = "http://example/" ; Triple triple = SSE.parseTriple("(<x> <y> <z>)") ; Node gn = org.apache.jena.graph.NodeFactory.createURI(graphName) ; Dataset ds = graphLocation.getDataset() ; // ?? See TupleLib. ds.asDatasetGraph().deleteAny(gn, null, null, null) ; Graph g2 = ds.asDatasetGraph().getGraph(gn) ; // if ( true ) // { // PrintStream ps = System.err ; // ps.println("Dataset names: ") ; // Iter.print(ps, ds.listNames()) ; // } // Graphs only exists if they have a triple in them assertFalse(ds.containsNamedModel(graphName)) ; List<String> names = Iter.toList(ds.listNames()) ; assertEquals(0, names.size()) ; assertEquals(0, ds.asDatasetGraph().size()) ; }
@Test public void filtered3() { Predicate<Quad> filter = x->x.getSubject().equals(s2); Txn.executeRead(basedsg, ()->{ DatasetGraph dsg = new DatasetGraphFilteredView(basedsg, filter, Collections.singleton(g1)); long x0 = Iter.count(dsg.find(null, null, null, null)); assertEquals(2,x0); long x1 = Iter.count(dsg.find(g2, null, null, null)); assertEquals(2,x1); long x2 = Iter.count(dsg.find(null, s2, null, null)); assertEquals(2,x2); long x3 = Iter.count(dsg.find(g1, s2, null, null)); assertEquals(0,x3); assertEquals(1, dsg.size()); }); }
@Test public void filtered4() { Predicate<Quad> filter = x->x.getSubject().equals(s2); Txn.executeRead(basedsg, ()->{ DatasetGraph dsg = new DatasetGraphFilteredView(basedsg, filter, Arrays.asList(g1, g2)); long x0 = Iter.count(dsg.find(null, null, null, null)); assertEquals(2,x0); long x1 = Iter.count(dsg.find(g2, null, null, null)); assertEquals(2,x1); long x2 = Iter.count(dsg.find(null, s2, null, null)); assertEquals(2,x2); long x3 = Iter.count(dsg.find(g1, s2, null, null)); assertEquals(0,x3); assertEquals(2, dsg.size()); }); }
@Test public void testARQConstructQuad_Duplicate_2() { String queryString = "CONSTRUCT { GRAPH ?g1 {?s ?p ?o} } WHERE { ?s ?p ?o. GRAPH ?g1 {?s1 ?p1 ?o1} }"; Query q = QueryFactory.create(queryString, Syntax.syntaxARQ); QueryExecution qExec = QueryExecutionFactory.create(q, d); Dataset result = qExec.execConstructDataset(); DatasetGraph expected = DatasetGraphFactory.create(); expected.add(g1.asNode(), s.asNode(), p.asNode(), o.asNode()); assertEquals(1, result.asDatasetGraph().size()); assertTrue(IsoMatcher.isomorphic( expected, result.asDatasetGraph()) ); }
@Test public void testDifference() { final Graph g1 = parseGraph("(graph (triple <s1> <p1> <o1> ))"); final DatasetGraph dsg1 = DatasetGraphFactory.create(g1); final Node graphName1 = NodeFactory.createBlankNode(); dsg1.addGraph(graphName1, g1); final Graph g2 = parseGraph("(graph (triple <s2> <p2> <o2> ))"); final DatasetGraph dsg2 = DatasetGraphFactory.create(g2); final Node graphName2 = NodeFactory.createBlankNode(); dsg2.addGraph(graphName2, g2); DatasetGraph dsg = testInstance(dsg1, dsg2, Context.emptyContext); assertEquals(1, dsg.size()); assertTrue(g1.isIsomorphicWith(dsg.getGraph(graphName1))); assertTrue(g1.isIsomorphicWith(dsg.getDefaultGraph())); assertTrue(dsg.getGraph(graphName2).isEmpty()); }
@Test public void testUnion() { final Graph g1 = parseGraph("(graph (triple <s1> <p1> <o1> ))"); final DatasetGraph dsg1 = DatasetGraphFactory.create(g1); final Node graphName1 = NodeFactory.createBlankNode(); dsg1.addGraph(graphName1, g1); final Graph g2 = parseGraph("(graph (triple <s2> <p2> <o2> ))"); final DatasetGraph dsg2 = DatasetGraphFactory.create(g2); final Node graphName2 = NodeFactory.createBlankNode(); dsg2.addGraph(graphName2, g2); DatasetGraph dsg = testInstance(dsg1, dsg2, Context.emptyContext); assertEquals(2, dsg.size()); assertTrue(g1.isIsomorphicWith(dsg.getGraph(graphName1))); assertTrue(g2.isIsomorphicWith(dsg.getGraph(graphName2))); g1.find().mapWith(dsg.getDefaultGraph()::contains).forEachRemaining(Assert::assertTrue); g2.find().mapWith(dsg.getDefaultGraph()::contains).forEachRemaining(Assert::assertTrue); } }
@Test public void testIntersection() { final Graph g1 = parseGraph("(graph (triple <s1> <p1> <o1> ))"); final DatasetGraph dsg1 = DatasetGraphFactory.create(g1); final Node graphName1 = NodeFactory.createBlankNode(); dsg1.addGraph(graphName1, g1); final Graph g2 = parseGraph("(graph (triple <s2> <p2> <o2> ))"); final DatasetGraph dsg2 = DatasetGraphFactory.create(g2); final Node graphName2 = NodeFactory.createBlankNode(); dsg2.addGraph(graphName2, g2); final Node graphName3 = NodeFactory.createBlankNode(); dsg1.addGraph(graphName3, g1); dsg2.addGraph(graphName3, g1); DatasetGraph dsg = testInstance(dsg1, dsg2, Context.emptyContext); assertEquals(1, dsg.size()); assertTrue(dsg.getDefaultGraph().isEmpty()); assertTrue(dsg.getGraph(graphName1).isEmpty()); assertTrue(dsg.getGraph(graphName2).isEmpty()); assertTrue(g1.isIsomorphicWith(dsg.getGraph(graphName3))); } }