func (v *DotLoader) loadDigraph(input lattice.Input, labels *digraph.Labels) (graph *digraph.Builder, err error) { r, closer := input() text, err := ioutil.ReadAll(r) closer() if err != nil { return nil, err } G := digraph.Build(100, 1000) dp := &dotParse{ b: newBaseLoader(v.dt, G), d: v, labels: labels, vids: make(map[string]int32), } // s, err := dot.Lexer.Scanner(text) // if err != nil { // return nil, err // } // for _, _, eof := s.Next(); !eof; _, _, eof = s.Next() {} err = dot.StreamParse(text, dp) if err != nil { return nil, err } return G, nil }
func (sg *SubGraph) AsIndices() *digraph.Indices { b := digraph.Build(len(sg.V), len(sg.E)) for vidx := range sg.V { u := &sg.V[vidx] b.AddVertex(u.Color) } for eidx := range sg.E { src := &b.V[sg.E[eidx].Src] targ := &b.V[sg.E[eidx].Targ] color := sg.E[eidx].Color b.AddEdge(src, targ, color) } return digraph.NewIndices(b, 1) }
func (v *VegLoader) loadDigraph(input lattice.Input, labels *digraph.Labels) (*digraph.Builder, error) { var errs ErrorList V, E, err := graphSize(input) if err != nil { return nil, err } errors.Logf("DEBUG", "Got graph size %v %v", V, E) G := digraph.Build(V, E) b := newBaseLoader(v.dt, G) in, closer := input() defer closer() err = processLines(in, func(line []byte) { if len(line) == 0 || !bytes.Contains(line, []byte("\t")) { return } line_type, data := parseLine(line) switch line_type { case "vertex": if err := v.loadVertex(labels, b, data); err != nil { errs = append(errs, err) } case "edge": if err := v.loadEdge(labels, b, data); err != nil { errs = append(errs, err) } default: errs = append(errs, errors.Errorf("Unknown line type %v", line_type)) } }) if err != nil { return nil, err } if len(errs) == 0 { return G, nil } return nil, errs }
func digraphCommonAncestor(patterns []lattice.Pattern) (lattice.Pattern, error) { // construct a in memory configuration for finding common subdigraphs of all patterns conf := &config.Config{ Cache: "", Output: "", Support: len(patterns), Samples: 5, Unique: false, } wlkr := fastmax.NewWalker(conf) wlkr.Reject = false // closing the walker releases the memory defer func() { err := wlkr.Close() if err != nil { log.Panic(err) } }() maxE := int(math.MaxInt32) maxV := int(math.MaxInt32) for _, pat := range patterns { sg := pat.(*digraph.SubgraphPattern).Pat if len(sg.E) < maxE { maxE = len(sg.E) } if len(sg.V) < maxV { maxV = len(sg.V) } } // init the datatype (we are now ready to mine) dt, err := digraph.NewDigraph(conf, &digraph.Config{ MinEdges: 0, MaxEdges: maxE, MinVertices: 0, MaxVertices: maxV, Mode: digraph.GIS | digraph.OverlapPruning | digraph.ExtFromEmb, }) if err != nil { return nil, err } var labels *dg.Labels = patterns[0].(*digraph.SubgraphPattern).Dt.Labels // construct the digraph from the patterns b := dg.Build(10, 10) offset := 0 for gid, pat := range patterns { sn := pat.(*digraph.SubgraphPattern) for i := range sn.Pat.V { vid := offset + i b.AddVertex(sn.Pat.V[i].Color) err := dt.NodeAttrs.Add(int32(vid), map[string]interface{}{"gid": gid}) if err != nil { return nil, err } } for i := range sn.Pat.E { b.AddEdge(&b.V[offset+sn.Pat.E[i].Src], &b.V[offset+sn.Pat.E[i].Targ], sn.Pat.E[i].Color) } offset += len(sn.Pat.V) } // Initialize the *Digraph with the graph G being used. err = dt.Init(b, labels) if err != nil { return nil, err } // errors.Logf("DEBUG", "patterns %v %v", len(patterns), G) // create the reporter fmtr := digraph.NewFormatter(dt, nil) collector := &reporters.Collector{make([]lattice.Node, 0, 10)} uniq, err := reporters.NewUnique(conf, fmtr, collector, "") if err != nil { return nil, err } // rptr := &reporters.Chain{[]miners.Reporter{reporters.NewLog(fmtr, false, "DEBUG", "common-ancestor"), uniq}} rptr := uniq // mine err = wlkr.Mine(dt, rptr, fmtr) if err != nil { return nil, err } // extract the largest common subdigraph maxLevel := collector.Nodes[0].Pattern().Level() maxPattern := collector.Nodes[0].Pattern() for _, n := range collector.Nodes { p := n.Pattern() if p.Level() > maxLevel { maxLevel = p.Level() maxPattern = p } } errors.Logf("DEBUG", "ancestor %v", maxPattern) return maxPattern, nil }