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 _read_graphs(self): self.graphs = dict() with codecs.open(self._database_file_name, 'r', 'utf-8') as f: lines = [line.strip() for line in f.readlines()] tgraph, graph_cnt = None, 0 for i, line in enumerate(lines): cols = line.split(' ') if cols[0] == 't': if tgraph is not None: self.graphs[graph_cnt] = tgraph graph_cnt += 1 tgraph = None if cols[-1] == '-1' or graph_cnt >= self._max_ngraphs: break tgraph = Graph(graph_cnt, is_undirected=self._is_undirected, eid_auto_increment=True) elif cols[0] == 'v': tgraph.add_vertex(cols[1], cols[2]) elif cols[0] == 'e': tgraph.add_edge(AUTO_EDGE_ID, cols[1], cols[2], cols[3]) # adapt to input files that do not end with 't # -1' if tgraph is not None: self.graphs[graph_cnt] = tgraph return self
def to_graph(self, gid=VACANT_GRAPH_ID, is_undirected=True): """Construct a graph according to the dfs code.""" g = Graph(gid, is_undirected=is_undirected, eid_auto_increment=True) for dfsedge in self: frm, to, (vlb1, elb, vlb2) = dfsedge.frm, dfsedge.to, dfsedge.vevlb if vlb1 != VACANT_VERTEX_LABEL: g.add_vertex(frm, vlb1) if vlb2 != VACANT_VERTEX_LABEL: g.add_vertex(to, vlb2) g.add_edge(AUTO_EDGE_ID, frm, to, elb) return g