Example #1
0
File: mine.go Project: timtadh/sfp
func (w *Walker) Next(cur lattice.Node) (lattice.Node, error) {
	kids, err := cur.Children()
	if err != nil {
		return nil, err
	}
	if false {
		errors.Logf("DEBUG", "cur %v kids %v", cur, len(kids))
	}
	_, next, err := walker.Transition(cur, kids, w.weight, false)
	return next, err
}
Example #2
0
File: mine.go Project: timtadh/sfp
func Next(ctx interface{}, cur lattice.Node) (lattice.Node, error) {
	kids, err := cur.Children()
	if err != nil {
		return nil, err
	}
	parents, err := cur.Parents()
	if err != nil {
		return nil, err
	}
	adjs := append(kids, parents...)
	errors.Logf("DEBUG", "cur %v parents %v kids %v adjs %v", cur, len(parents), len(kids), len(adjs))
	_, next, err := walker.Transition(cur, adjs, weight, false)
	return next, err
}
Example #3
0
File: mine.go Project: timtadh/sfp
func (m *Miner) mine() (err error) {
	seen, err := m.Config.BytesIntMultiMap("stack-seen")
	if err != nil {
		return err
	}
	add := func(stack []lattice.Node, n lattice.Node) ([]lattice.Node, error) {
		err := seen.Add(n.Pattern().Label(), 1)
		if err != nil {
			return nil, err
		}
		return append(stack, n), nil
	}
	pop := func(stack []lattice.Node) ([]lattice.Node, lattice.Node) {
		return stack[:len(stack)-1], stack[len(stack)-1]
	}
	stack := make([]lattice.Node, 0, 10)
	stack, err = add(stack, m.Dt.Root())
	if err != nil {
		return err
	}
	for len(stack) > 0 {
		var n lattice.Node
		stack, n = pop(stack)
		if m.Dt.Acceptable(n) {
			err = m.Rptr.Report(n)
			if err != nil {
				return err
			}
		}
		kids, err := n.Children()
		if err != nil {
			return err
		}
		for _, k := range kids {
			if has, err := seen.Has(k.Pattern().Label()); err != nil {
				return err
			} else if !has {
				stack, err = add(stack, k)
				if err != nil {
					return err
				}
			}
		}
	}
	return nil
}
Example #4
0
File: mine.go Project: timtadh/sfp
func Next(w *walker.Walker, cur lattice.Node) (lattice.Node, error) {
	kids, err := cur.Children()
	if err != nil {
		return nil, err
	}
	parents, err := cur.Parents()
	if err != nil {
		return nil, err
	}
	adjs := append(kids, parents...)
	errors.Logf("DEBUG", "cur %v parents %v kids %v adjs %v", cur, len(parents), len(kids), len(adjs))
	prs, err := transPrs(w, cur, adjs)
	if err != nil {
		return nil, err
	}
	adjs = append(adjs, cur)
	prs = append(prs, selfPr(prs))
	i := stats.WeightedSample(prs)
	return adjs[i], nil
}
Example #5
0
File: mine.go Project: timtadh/sfp
func (w *Walker) Next(cur lattice.Node) (lattice.Node, error) {
	errors.Logf("DEBUG", "cur %v", cur)
	return uniform(cur.Children())
}