Search in sources :

Example 1 with InterpretedProverBuilder

use of suite.lp.search.InterpretedProverBuilder in project suite by stupidsing.

the class CommandDispatcher method dispatchCommand_.

private boolean dispatchCommand_(String input, Writer writer) throws IOException {
    PrintWriter pw = new PrintWriter(writer);
    boolean code = true;
    Pair<InputType, String> pair = new CommandUtil<>(InputType.values()).recognize(input);
    InputType type = pair.t0;
    input = pair.t1.trim();
    if (input.endsWith("#"))
        input = String_.range(input, 0, -1);
    Node node = Suite.parse(input.trim());
    switch(type) {
        case EVALUATE:
            pw.println(Formatter.dump(evaluateFunctional(node)));
            break;
        case EVALUATEDO:
            node = Suite.applyPerform(node, Atom.of("any"));
            pw.println(Formatter.dump(evaluateFunctional(node)));
            break;
        case EVALUATEDOCHARS:
            node = Suite.applyPerform(node, Suite.parse("[n^Chars]"));
            printEvaluated(writer, node);
            break;
        case EVALUATEDOSTR:
            node = Suite.applyPerform(node, Atom.of("string"));
            printEvaluated(writer, Suite.applyWriter(node));
            break;
        case EVALUATEEFI:
            InterpretFunEager efi = new InterpretFunEager();
            efi.setLazyify(opt.isLazy());
            pw.println(efi.eager(node));
            break;
        case EVALUATELFI0:
            pw.println(new InterpretFunLazy0().lazy(node).get());
            break;
        case EVALUATELFI:
            pw.println(new InterpretFunLazy().lazy(node).get());
            break;
        case EVALUATESTR:
            node = Suite.substitute("string of .0", node);
            printEvaluated(writer, Suite.applyWriter(node));
            break;
        case EVALUATETYPE:
            pw.println(Formatter.dump(Suite.evaluateFunType(opt.fcc(node))));
            break;
        case FACT:
            ruleSet.addRule(Rule.of(node));
            break;
        case OPTION:
            Source<String> source = To.source(("-" + input).split(" "));
            String option;
            while ((option = source.source()) != null) opt.processOption(option, source);
            break;
        case PRETTYPRINT:
            pw.println(new PrettyPrinter().prettyPrint(node));
            break;
        case QUERY:
            code = query(new InterpretedProverBuilder(opt.pc(ruleSet)), ruleSet, node);
            break;
        case QUERYCOMPILED:
            code = query(CompiledProverBuilder.level1(opt.pc(ruleSet)), ruleSet, node);
            break;
        case QUERYCOMPILED2:
            if (builderLevel2 == null)
                builderLevel2 = CompiledProverBuilder.level2(opt.pc(ruleSet));
            code = query(builderLevel2, ruleSet, node);
            break;
        case QUERYELABORATE:
            elaborate(node, new Prover(opt.pc(ruleSet))::prove);
            break;
        case QUERYSEWING:
            code = query(new SewingProverBuilder(opt.pc(ruleSet)), ruleSet, node);
            break;
        case QUERYSEWINGELAB:
            elaborate(node, n -> new SewingProverImpl(ruleSet).prover(n).test(new ProverConfig(ruleSet)));
            break;
        case RESET:
            ruleSet = Suite.newRuleSet();
            importFiles(List.of());
    }
    pw.flush();
    return code;
}
Also used : InterpretFunLazy(suite.fp.InterpretFunLazy) SewingProverBuilder(suite.lp.search.SewingProverBuilder) InterpretFunLazy0(suite.fp.InterpretFunLazy0) Node(suite.node.Node) Prover(suite.lp.doer.Prover) InterpretFunEager(suite.fp.InterpretFunEager) SewingProverImpl(suite.lp.sewing.impl.SewingProverImpl) PrettyPrinter(suite.node.pp.PrettyPrinter) InterpretedProverBuilder(suite.lp.search.InterpretedProverBuilder) ProverConfig(suite.lp.Configuration.ProverConfig) PrintWriter(java.io.PrintWriter)

Example 2 with InterpretedProverBuilder

use of suite.lp.search.InterpretedProverBuilder in project suite by stupidsing.

the class ProverTest method test.

private boolean test(RuleSet rs, String lp) {
    ProverConfig pc = new ProverConfig();
    boolean b0 = Suite.proveLogic(new InterpretedProverBuilder(pc), rs, lp);
    boolean b1 = Suite.proveLogic(new SewingProverBuilder2(pc), rs, lp);
    if (b0 == b1)
        return b0;
    else
        return Fail.t("different prove result");
}
Also used : InterpretedProverBuilder(suite.lp.search.InterpretedProverBuilder) ProverConfig(suite.lp.Configuration.ProverConfig) SewingProverBuilder2(suite.lp.search.SewingProverBuilder2)

Example 3 with InterpretedProverBuilder

use of suite.lp.search.InterpretedProverBuilder in project suite by stupidsing.

the class RbTreeTest method test.

@Test
public void test() throws IOException {
    RuleSet rs = Suite.newRuleSet(List.of("auto.sl", "rbt.sl"));
    String gs = // 
    "" + // 
    "rbt-insert-list (6, 7, 8, 9, 10, 1, 2, 3, 4, 5,) ()/.t \n" + // 
    ", rbt-get .t 8" + ", rbt-member .t 4";
    for (Builder builder : List.of(new InterpretedProverBuilder(), new SewingProverBuilder2())) assertTrue(Suite.proveLogic(builder, rs, gs));
}
Also used : RuleSet(suite.lp.kb.RuleSet) InterpretedProverBuilder(suite.lp.search.InterpretedProverBuilder) InterpretedProverBuilder(suite.lp.search.InterpretedProverBuilder) Builder(suite.lp.search.ProverBuilder.Builder) SewingProverBuilder2(suite.lp.search.SewingProverBuilder2) Test(org.junit.Test)

Aggregations

InterpretedProverBuilder (suite.lp.search.InterpretedProverBuilder)3 ProverConfig (suite.lp.Configuration.ProverConfig)2 SewingProverBuilder2 (suite.lp.search.SewingProverBuilder2)2 PrintWriter (java.io.PrintWriter)1 Test (org.junit.Test)1 InterpretFunEager (suite.fp.InterpretFunEager)1 InterpretFunLazy (suite.fp.InterpretFunLazy)1 InterpretFunLazy0 (suite.fp.InterpretFunLazy0)1 Prover (suite.lp.doer.Prover)1 RuleSet (suite.lp.kb.RuleSet)1 Builder (suite.lp.search.ProverBuilder.Builder)1 SewingProverBuilder (suite.lp.search.SewingProverBuilder)1 SewingProverImpl (suite.lp.sewing.impl.SewingProverImpl)1 Node (suite.node.Node)1 PrettyPrinter (suite.node.pp.PrettyPrinter)1