def _generate_1edge_frequent_subgraphs(self): vlb_counter = collections.Counter() vevlb_counter = collections.Counter() vlb_counted = set() vevlb_counted = set() for g in self.graphs.values(): for v in g.vertices.values(): if (g.gid, v.vlb) not in vlb_counted: vlb_counter[v.vlb] += 1 vlb_counted.add((g.gid, v.vlb)) for to, e in v.edges.items(): vlb1, vlb2 = v.vlb, g.vertices[to].vlb if self._is_undirected and vlb1 > vlb2: vlb1, vlb2 = vlb2, vlb1 if (g.gid, (vlb1, e.elb, vlb2)) not in vevlb_counter: vevlb_counter[(vlb1, e.elb, vlb2)] += 1 vevlb_counted.add((g.gid, (vlb1, e.elb, vlb2))) # add frequent vertices. for vlb, cnt in vlb_counter.items(): if cnt >= self._min_support: g = Graph(gid=next(self._counter), is_undirected=self._is_undirected) g.add_vertex(0, vlb) self._frequent_size1_subgraphs.append(g) if self._min_num_vertices <= 1: self._report_size1(g, support=cnt) else: continue if self._min_num_vertices > 1: self._counter = itertools.count()
def to_graph(self, gid=-1): """Construct a graph according to the dfs code.""" g = Graph(gid) for dfsedge in self: frm, to, (vlb1, elb, vlb2) = dfsedge.frm, dfsedge.to, dfsedge.vevlb g.add_vertex(frm, vlb1) g.add_vertex(to, vlb2) g.add_edge(frm, to, elb) return g