/** Write statistics */ static public void write(OutputStream output, StatsResults stats) { write(output, stats.getPredicates(), stats.getTypes(), stats.getCount()) ; }
public StatsResults results() { return new StatsResults(convert(predicates), convert(types), count); } }
public static Item format(StatsResults stats) { return format(stats.getPredicates(), stats.getTypes(), stats.getCount()) ; }
private StatsResults statsForDftGraph() { // StatsCollectorNodeId writes nodes for rdf:type (this is not good). return Txn.calculateWrite(dsg, ()-> { Iterator<Tuple<NodeId>> iter = triples.findAll() ; StatsCollectorNodeId stats = new StatsCollectorNodeId(nt) ; for ( ; iter.hasNext() ; ) { Tuple<NodeId> t = iter.next() ; stats.record(null, t.get(0), t.get(1), t.get(2)) ; } return stats.results() ; }) ; }
@Test public void stats_01() { StatsResults r = statsForDftGraph() ; assertEquals(1, r.getCount()) ; assertEquals(1, r.getPredicates().keySet().size()) ; }
static private void write(String filename, Map<Node, Integer> predicateStats, Map<Node, Integer> typeStats, long statsTotal) { // Write out the stats try (OutputStream statsOut = new BufferedOutputStream(new FileOutputStream(filename))) { write(statsOut, predicateStats, typeStats, statsTotal) ; } catch (IOException ex) { Log.warn(Stats.class, "Problem when writing stats file", ex) ; } }
/** Gather statistics, any graph */ public static StatsCollector gather(Graph graph) { StatsCollector stats = new StatsCollector() ; Iterator<Triple> iter = graph.find(Node.ANY, Node.ANY, Node.ANY) ; for ( ; iter.hasNext() ; ) { Triple t = iter.next(); stats.record(null, t.getSubject(), t.getPredicate(), t.getObject()) ; } return stats ; }
public StatsCollectorNodeId(NodeTable nodeTable) { super(findRDFType(nodeTable)); this.nodeTable = nodeTable; }
static private void write(OutputStream output, Map<Node, Integer> predicateStats, Map<Node, Integer> typeStats, long statsTotal) { Item item = format(predicateStats, typeStats, statsTotal) ; ItemWriter.write(output, item) ; }
private StatsResults statsForDftGraph() { // StatsCollectorNodeId writes nodes for rdf:type (this is not good). return Txn.calculateWrite(dsg, ()-> { Iterator<Tuple<NodeId>> iter = triples.findAll() ; StatsCollectorNodeId stats = new StatsCollectorNodeId(nt) ; for ( ; iter.hasNext() ; ) { Tuple<NodeId> t = iter.next() ; stats.record(null, t.get(0), t.get(1), t.get(2)) ; } return stats.results() ; }) ; }
/** Write statistics */ static public void write(String filename, StatsResults stats) { write(filename, stats.getPredicates(), stats.getTypes(), stats.getCount()) ; }
@Test public void stats_04() { StatsResults r = statsForGraph(null) ; assertEquals(3, r.getCount()) ; assertEquals(1, r.getPredicates().keySet().size()) ; }
@Override protected void exec() { DatasetGraphTDB dsg = TDBInternal.getDatasetGraphTDB(getDatasetGraph()); Node gn = getGraphName(); StatsResults results = stats(dsg, gn); Stats.write(System.out, results); } }
private StatsResults statsForGraph(NodeId gid) { // StatsCollectorNodeId writes nodes for rdf:type (this is not good). return Txn.calculateWrite(dsg, ()-> { Iterator<Tuple<NodeId>> iter = quads.find(gid, null, null, null) ; StatsCollectorNodeId stats = new StatsCollectorNodeId(nt) ; for ( ; iter.hasNext() ; ) { Tuple<NodeId> t = iter.next() ; stats.record(t.get(0), t.get(1), t.get(2), t.get(3)) ; } return stats.results() ; }) ; }
@Test public void stats_04() { StatsResults r = statsForGraph(null) ; assertEquals(3, r.getCount()) ; assertEquals(1, r.getPredicates().keySet().size()) ; }
@Override protected void exec() { DatasetGraphTDB dsg = TDBInternal.getDatasetGraphTDB(getDatasetGraph()); Node gn = getGraphName(); StatsResults results = stats(dsg, gn); Stats.write(System.out, results); } }
private StatsResults statsForGraph(NodeId gid) { // StatsCollectorNodeId writes nodes for rdf:type (this is not good). return Txn.calculateWrite(dsg, ()-> { Iterator<Tuple<NodeId>> iter = quads.find(gid, null, null, null) ; StatsCollectorNodeId stats = new StatsCollectorNodeId(nt) ; for ( ; iter.hasNext() ; ) { Tuple<NodeId> t = iter.next() ; stats.record(t.get(0), t.get(1), t.get(2), t.get(3)) ; } return stats.results() ; }) ; }
@Test public void stats_01() { StatsResults r = statsForDftGraph() ; assertEquals(1, r.getCount()) ; assertEquals(1, r.getPredicates().keySet().size()) ; }
@Test public void stats_03() { NodeId gid = nt.getNodeIdForNode(NodeFactory.createURI("g2")) ; StatsResults r = statsForGraph(gid) ; assertEquals(2, r.getCount()) ; assertEquals(1, r.getPredicates().keySet().size()) ; }
@Test public void stats_02() { NodeId gid = nt.getNodeIdForNode(NodeFactory.createURI("g1")) ; StatsResults r = statsForGraph(gid) ; assertEquals(1, r.getCount()) ; assertEquals(1, r.getPredicates().keySet().size()) ; }