Search in sources :

Example 1 with Trail

use of suite.lp.Trail in project suite by stupidsing.

the class Chr method chrIf.

private Streamlet<State> chrIf(Streamlet<State> states, Trail trail, Node if_) {
    Prototype prototype = Prototype.of(if_);
    Fun<State, Streamlet<State>> fun = state -> {
        ISet<Node> facts = getFacts(state, prototype);
        Predicate<Node> bindFun = bindFun(trail, if_);
        return facts.streamlet().filter(bindFun).map(node -> setFacts(state, prototype, facts.remove(node)));
    };
    return states.concatMap(fun);
}
Also used : Reference(suite.node.Reference) Suite(suite.Suite) Trail(suite.lp.Trail) Prover(suite.lp.doer.Prover) Read(suite.streamlet.Read) Predicate(java.util.function.Predicate) Collection(java.util.Collection) IMap(suite.immutable.IMap) ISet(suite.immutable.ISet) TermOp(suite.node.io.TermOp) To(suite.util.To) Fun(suite.util.FunUtil.Fun) Tree(suite.node.Tree) ArrayList(java.util.ArrayList) Node(suite.node.Node) Pair(suite.adt.pair.Pair) List(java.util.List) Rewrite(suite.node.util.Rewrite) Streamlet(suite.streamlet.Streamlet) Atom(suite.node.Atom) Prototype(suite.lp.kb.Prototype) Binder(suite.lp.doer.Binder) Generalizer(suite.lp.doer.Generalizer) Fail(suite.util.Fail) Prototype(suite.lp.kb.Prototype) Streamlet(suite.streamlet.Streamlet) ISet(suite.immutable.ISet) Predicate(java.util.function.Predicate)

Example 2 with Trail

use of suite.lp.Trail in project suite by stupidsing.

the class Chr method chr.

private Streamlet<State> chr(State state, Rule rule) {
    Generalizer generalizer = new Generalizer();
    Trail trail = new Trail();
    Streamlet<State> states = Read.each(state);
    for (Node if_ : rule.ifs) states = chrIf(states, trail, generalizer.generalize(if_));
    for (Node given : rule.givens) states = chrGiven(states, trail, generalizer.generalize(given));
    states = chrWhen(states, generalizer.generalize(rule.when));
    for (Node then : rule.thens) states = chrThen(states, generalizer.generalize(then));
    return states;
}
Also used : Generalizer(suite.lp.doer.Generalizer) Trail(suite.lp.Trail) Node(suite.node.Node)

Example 3 with Trail

use of suite.lp.Trail in project suite by stupidsing.

the class FunTypeTest method checkType.

private void checkType(String fps, String bindTo, String ts) {
    Trail trail = new Trail();
    Node type = getType(fps);
    assertTrue(Binder.bind(type, SewingGeneralizerImpl.generalize(Suite.parse(bindTo)), trail));
    assertTrue(Comparer.comparer.compare(Suite.parse(ts), type) == 0);
}
Also used : Trail(suite.lp.Trail) Node(suite.node.Node)

Example 4 with Trail

use of suite.lp.Trail in project suite by stupidsing.

the class Rewrite method rewrite.

public Node rewrite(Source<Node[]> source, Node node) {
    Trail trail = new Trail();
    return rewrite(node0 -> {
        Node node1;
        if (!(node0 instanceof Reference)) {
            int pit = trail.getPointInTime();
            Node[] ft = source.source();
            if (Binder.bind(node0, ft[0], trail))
                node1 = ft[1];
            else {
                trail.unwind(pit);
                node1 = node0;
            }
        } else
            node1 = node0;
        return node1;
    }, node);
}
Also used : Trail(suite.lp.Trail) Reference(suite.node.Reference) Node(suite.node.Node)

Example 5 with Trail

use of suite.lp.Trail in project suite by stupidsing.

the class ClonerFactoryTest method test.

private void test(String pattern, String match) {
    for (ClonerFactory cf : new ClonerFactory[] { new CompileClonerImpl(), new SewingClonerImpl() }) {
        Node node = new Generalizer().generalize(Suite.parse(pattern));
        Clone_ p = cf.cloner(node);
        assertTrue(Binder.bind(p.apply(cf.mapper().env()), Suite.parse(match), new Trail()));
    }
}
Also used : Trail(suite.lp.Trail) CompileClonerImpl(suite.lp.compile.impl.CompileClonerImpl) SewingClonerImpl(suite.lp.sewing.impl.SewingClonerImpl) Node(suite.node.Node) Clone_(suite.lp.doer.ClonerFactory.Clone_)

Aggregations

Trail (suite.lp.Trail)11 Node (suite.node.Node)10 Reference (suite.node.Reference)6 Generalizer (suite.lp.doer.Generalizer)5 Tree (suite.node.Tree)4 ArrayList (java.util.ArrayList)3 Pair (suite.adt.pair.Pair)3 IMap (suite.immutable.IMap)2 ISet (suite.immutable.ISet)2 Prototype (suite.lp.kb.Prototype)2 Atom (suite.node.Atom)2 TermOp (suite.node.io.TermOp)2 Fun (suite.util.FunUtil.Fun)2 ArrayDeque (java.util.ArrayDeque)1 Collection (java.util.Collection)1 List (java.util.List)1 Predicate (java.util.function.Predicate)1 Suite (suite.Suite)1 FunpTree (suite.funp.P0.FunpTree)1 Activation (suite.instructionexecutor.InstructionUtil.Activation)1