Search in sources :

Example 1 with PerSet

use of primal.persistent.PerSet in project suite by stupidsing.

the class Chr method chrThen.

private Streamlet<State> chrThen(Streamlet<State> states, Node then) {
    var generalizer = new Generalizer();
    Atom a = atom(".a"), b = atom(".b");
    if (Binder.bind(then, generalizer.generalize(Suite.substitute(".0 = .1", a, b)))) {
        // built-in syntactic equality
        var from = generalizer.getVariable(a);
        var to = generalizer.getVariable(b);
        states = states.map(new Fun<>() {

            public State apply(State state) {
                var factsByPrototype1 = PerMap.<Prototype, PerSet<Node>>empty();
                for (var e : state.factsByPrototype) factsByPrototype1 = factsByPrototype1.put(e.k, replace(e.v));
                return new State(factsByPrototype1);
            }

            private PerSet<Node> replace(PerSet<Node> facts) {
                var facts1 = PerSet.<Node>empty();
                for (var node : facts) facts1 = facts1.replace(rw.replace(from, to, node));
                return facts1;
            }
        });
    }
    return states.map(state -> {
        var prototype = Prototype.of(then);
        var facts = getFacts(state, prototype);
        return setFacts(state, prototype, facts.replace(then));
    });
}
Also used : Generalizer(suite.lp.doer.Generalizer) Prototype(suite.lp.kb.Prototype) Node(suite.node.Node) PerSet(primal.persistent.PerSet) Atom(suite.node.Atom) Fun(primal.fp.Funs.Fun)

Aggregations

Fun (primal.fp.Funs.Fun)1 PerSet (primal.persistent.PerSet)1 Generalizer (suite.lp.doer.Generalizer)1 Prototype (suite.lp.kb.Prototype)1 Atom (suite.node.Atom)1 Node (suite.node.Node)1