Search in sources :

Example 1 with Generalizer

use of suite.lp.doer.Generalizer in project suite by stupidsing.

the class Assembler method assemble.

public Bytes assemble(String in0) {
    Set<Character> whitespaces = Collections.singleton('\n');
    Fun<String, List<Run>> gct = CommentPreprocessor.groupCommentPreprocessor(whitespaces);
    Fun<String, List<Run>> lct = CommentPreprocessor.lineCommentPreprocessor(whitespaces);
    String in1 = Preprocess.transform(List.of(gct, lct), in0).t0;
    Generalizer generalizer = new Generalizer();
    List<String> lines = List.of(in1.split("\n"));
    Pair<String, String> pe;
    int start = 0;
    while (!(pe = String_.split2(lines.get(start), "=")).t1.isEmpty()) {
        generalizer.getVariable(Atom.of(pe.t0)).bound(Suite.parse(pe.t1));
        start++;
    }
    List<Pair<Reference, Node>> lnis = // 
    Read.from(// 
    List_.right(lines, start)).map(line -> {
        Pair<String, String> pt = String_.split2(line, "\t");
        String label = pt.t0;
        String command = pt.t1;
        Reference reference = String_.isNotBlank(label) ? generalizer.getVariable(Atom.of(label)) : null;
        Node instruction = generalizer.generalize(Suite.parse(command));
        return Pair.of(reference, instruction);
    }).toList();
    return assemble(generalizer, lnis);
}
Also used : Read(suite.streamlet.Read) SewingProverBuilder2(suite.lp.search.SewingProverBuilder2) Fun(suite.util.FunUtil.Fun) ArrayList(java.util.ArrayList) Node(suite.node.Node) CommentPreprocessor(suite.parser.CommentPreprocessor) String_(suite.util.String_) Preprocess(suite.text.Preprocess) Run(suite.text.Preprocess.Run) Binder(suite.lp.doer.Binder) RuleSet(suite.lp.kb.RuleSet) Generalizer(suite.lp.doer.Generalizer) Reference(suite.node.Reference) Suite(suite.Suite) Trail(suite.lp.Trail) Finder(suite.lp.search.ProverBuilder.Finder) Set(java.util.Set) TermOp(suite.node.io.TermOp) Bytes(suite.primitive.Bytes) BytesBuilder(suite.primitive.Bytes.BytesBuilder) List_(suite.util.List_) To(suite.util.To) Tree(suite.node.Tree) Pair(suite.adt.pair.Pair) List(java.util.List) Atom(suite.node.Atom) Int(suite.node.Int) Collections(java.util.Collections) Fail(suite.util.Fail) Reference(suite.node.Reference) Node(suite.node.Node) Generalizer(suite.lp.doer.Generalizer) ArrayList(java.util.ArrayList) List(java.util.List) Pair(suite.adt.pair.Pair)

Example 2 with Generalizer

use of suite.lp.doer.Generalizer in project suite by stupidsing.

the class CompileGeneralizerImpl method generalizer.

@Override
public Generalize_ generalizer(Node node) {
    VariableMapper<Reference> mapper = cc.mapper();
    Generalizer generalizer = new Generalizer();
    Generalize_ generalize = cc.cloner(generalizer.generalize(node))::apply;
    Map<Reference, Atom> indices = new IdentityHashMap<>();
    for (Atom variableName : generalizer.getVariableNames()) indices.put(generalizer.getVariable(variableName), variableName);
    vm = mapper.mapKeys(indices::get);
    return generalize;
}
Also used : Generalizer(suite.lp.doer.Generalizer) Reference(suite.node.Reference) IdentityHashMap(java.util.IdentityHashMap) Atom(suite.node.Atom)

Example 3 with Generalizer

use of suite.lp.doer.Generalizer in project suite by stupidsing.

the class SewingProverImpl method compileCpsRules.

private Cps compileCpsRules(Prototype prototype, List<Rule> rules, TraceLevel traceLevel) {
    Streamlet<Cps> cpss = Read.from(rules).map(rule -> {
        Generalizer generalizer = new Generalizer();
        Node head = generalizer.generalize(rule.head);
        Node tail = generalizer.generalize(rule.tail);
        return compileCpsRule(head, tail);
    });
    Cps cps0 = orCps(cpss);
    return saveEnvCps(cps0);
}
Also used : Generalizer(suite.lp.doer.Generalizer) Node(suite.node.Node)

Example 4 with Generalizer

use of suite.lp.doer.Generalizer in project suite by stupidsing.

the class SewingProverImpl method compileTrRules.

private Trampoline compileTrRules(Prototype prototype, List<Rule> rules, TraceLevel traceLevel) {
    Streamlet<Trampoline> trs = Read.from(rules).map(rule -> {
        Generalizer generalizer = new Generalizer();
        Node head = generalizer.generalize(rule.head);
        Node tail = generalizer.generalize(rule.tail);
        return compileTrRule(head, tail);
    });
    Trampoline tr0 = orTr(trs);
    Trampoline tr1 = cutBegin(tr0);
    Trampoline tr2 = saveEnvTr(tr1);
    return log(tr2, traceLevel);
}
Also used : Generalizer(suite.lp.doer.Generalizer) Node(suite.node.Node)

Example 5 with Generalizer

use of suite.lp.doer.Generalizer 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)

Aggregations

Generalizer (suite.lp.doer.Generalizer)14 Node (suite.node.Node)11 Reference (suite.node.Reference)7 Trail (suite.lp.Trail)6 ArrayList (java.util.ArrayList)5 Atom (suite.node.Atom)5 Tree (suite.node.Tree)4 List (java.util.List)3 Suite (suite.Suite)3 Pair (suite.adt.pair.Pair)3 RuleSet (suite.lp.kb.RuleSet)3 Fun (suite.util.FunUtil.Fun)3 Test (org.junit.Test)2 ProverConfig (suite.lp.Configuration.ProverConfig)2 Binder (suite.lp.doer.Binder)2 ProverFactory (suite.lp.doer.ProverFactory)2 Prototype (suite.lp.kb.Prototype)2 SewingProverImpl (suite.lp.sewing.impl.SewingProverImpl)2 Dict (suite.node.Dict)2 TermOp (suite.node.io.TermOp)2