Search in sources :

Example 1 with TopRewriter

use of com.sri.ai.grinder.rewriter.api.TopRewriter in project aic-expresso by aic-sri-international.

the class CompoundTheory method makeTopRewriter.

@Override
public TopRewriter makeTopRewriter() {
    List<TopRewriter> subRewriters = mapIntoList(subTheories, t -> t.getTopRewriter());
    TopRewriter topRewriter = TopRewriter.makeTopRewriterFromTopRewritersThatAreEitherFirstOfOrSwitches(subRewriters);
    return topRewriter;
}
Also used : TopRewriter(com.sri.ai.grinder.rewriter.api.TopRewriter)

Example 2 with TopRewriter

use of com.sri.ai.grinder.rewriter.api.TopRewriter in project aic-expresso by aic-sri-international.

the class ProceduralAttachments method registerProceduralAttachment.

/**
 * This method registers a procedural attachment top rewriter to a function with a given arity;
 * the check of functor and arity will be added to the given top rewriter, so it does not need to do that.
 * @param functor
 * @param proceduralAttachmentParameters
 * @param topRewriter
 * @param context
 * @return
 */
public static void registerProceduralAttachment(Expression functor, int arity, TopRewriter topRewriter, Context context) {
    TopRewriter proceduralAttachment = new FunctorSwitch(functor.toString(), arity, topRewriter);
    context.updateInplaceGlobalObject(PROCEDURAL_ATTACHEMENTS_KEY, EMPTY_REWRITER_MAKER, combine(proceduralAttachment));
}
Also used : TopRewriter(com.sri.ai.grinder.rewriter.api.TopRewriter) CombiningTopRewriter(com.sri.ai.grinder.rewriter.core.CombiningTopRewriter) FunctorSwitch(com.sri.ai.grinder.rewriter.core.FunctorSwitch)

Example 3 with TopRewriter

use of com.sri.ai.grinder.rewriter.api.TopRewriter in project aic-expresso by aic-sri-international.

the class ProceduralAttachments method registerProceduralAttachment.

/**
 * Same as {@link #registerProceduralAttachment(Expression, List, TopRewriter, Context)},
 * but for a symbol.
 * @param symbol
 * @param topRewriter
 * @param context
 * @return
 */
public static void registerProceduralAttachment(Expression symbol, TopRewriter topRewriter, Context context) {
    TopRewriter proceduralAttachment = new SymbolSwitch(symbol.toString(), topRewriter);
    context.updateInplaceGlobalObject(PROCEDURAL_ATTACHEMENTS_KEY, EMPTY_REWRITER_MAKER, combine(proceduralAttachment));
}
Also used : SymbolSwitch(com.sri.ai.grinder.rewriter.core.SymbolSwitch) TopRewriter(com.sri.ai.grinder.rewriter.api.TopRewriter) CombiningTopRewriter(com.sri.ai.grinder.rewriter.core.CombiningTopRewriter)

Example 4 with TopRewriter

use of com.sri.ai.grinder.rewriter.api.TopRewriter in project aic-expresso by aic-sri-international.

the class AbstractInterpreter method setBaseTopRewriter.

public void setBaseTopRewriter(TopRewriter baseTopRewriter) {
    Rewriter result = new Recursive(new Exhaustive(new TopRewriterUsingQuantifierEliminatorAndContextAssignments(baseTopRewriter)));
    setBaseRewriter(result);
}
Also used : Exhaustive(com.sri.ai.grinder.rewriter.core.Exhaustive) ForAllRewriter(com.sri.ai.grinder.library.boole.ForAllRewriter) MaxRewriter(com.sri.ai.grinder.library.number.MaxRewriter) ThereExistsRewriter(com.sri.ai.grinder.library.boole.ThereExistsRewriter) ProductRewriter(com.sri.ai.grinder.library.number.ProductRewriter) RedirectingRewriter(com.sri.ai.grinder.rewriter.help.RedirectingRewriter) Rewriter(com.sri.ai.grinder.rewriter.api.Rewriter) TopRewriter(com.sri.ai.grinder.rewriter.api.TopRewriter) SummationRewriter(com.sri.ai.grinder.library.number.SummationRewriter) Recursive(com.sri.ai.grinder.rewriter.core.Recursive)

Example 5 with TopRewriter

use of com.sri.ai.grinder.rewriter.api.TopRewriter in project aic-expresso by aic-sri-international.

the class ProceduralAttachmentsTest method runTest.

private void runTest(Expression input, Expression expected, Context context) {
    TopRewriter topRewriter;
    Rewriter evaluator;
    Expression output;
    topRewriter = new CombiningTopRewriter(new CommonSimplifier(), getProceduralAttachmentsTopRewriter(context));
    evaluator = new Recursive(new Exhaustive(topRewriter));
    output = evaluator.apply(input, context);
    println(output);
    assertEquals(expected, output);
}
Also used : CommonSimplifier(com.sri.ai.grinder.library.commonrewriters.CommonSimplifier) CombiningTopRewriter(com.sri.ai.grinder.rewriter.core.CombiningTopRewriter) Expression(com.sri.ai.expresso.api.Expression) Exhaustive(com.sri.ai.grinder.rewriter.core.Exhaustive) CombiningTopRewriter(com.sri.ai.grinder.rewriter.core.CombiningTopRewriter) ProceduralAttachments.getProceduralAttachmentsTopRewriter(com.sri.ai.grinder.library.proceduralattachment.ProceduralAttachments.getProceduralAttachmentsTopRewriter) Rewriter(com.sri.ai.grinder.rewriter.api.Rewriter) TopRewriter(com.sri.ai.grinder.rewriter.api.TopRewriter) CombiningTopRewriter(com.sri.ai.grinder.rewriter.core.CombiningTopRewriter) ProceduralAttachments.getProceduralAttachmentsTopRewriter(com.sri.ai.grinder.library.proceduralattachment.ProceduralAttachments.getProceduralAttachmentsTopRewriter) TopRewriter(com.sri.ai.grinder.rewriter.api.TopRewriter) Recursive(com.sri.ai.grinder.rewriter.core.Recursive)

Aggregations

TopRewriter (com.sri.ai.grinder.rewriter.api.TopRewriter)8 CombiningTopRewriter (com.sri.ai.grinder.rewriter.core.CombiningTopRewriter)4 Rewriter (com.sri.ai.grinder.rewriter.api.Rewriter)3 Test (org.junit.Test)3 Expression (com.sri.ai.expresso.api.Expression)2 Exhaustive (com.sri.ai.grinder.rewriter.core.Exhaustive)2 Recursive (com.sri.ai.grinder.rewriter.core.Recursive)2 TupleEqualityTopRewriter (com.sri.ai.grinder.theory.tuple.rewriter.TupleEqualityTopRewriter)2 TupleGetSetTopRewriter (com.sri.ai.grinder.theory.tuple.rewriter.TupleGetSetTopRewriter)2 ForAllRewriter (com.sri.ai.grinder.library.boole.ForAllRewriter)1 ThereExistsRewriter (com.sri.ai.grinder.library.boole.ThereExistsRewriter)1 CommonSimplifier (com.sri.ai.grinder.library.commonrewriters.CommonSimplifier)1 MaxRewriter (com.sri.ai.grinder.library.number.MaxRewriter)1 ProductRewriter (com.sri.ai.grinder.library.number.ProductRewriter)1 SummationRewriter (com.sri.ai.grinder.library.number.SummationRewriter)1 ProceduralAttachments.getProceduralAttachmentsTopRewriter (com.sri.ai.grinder.library.proceduralattachment.ProceduralAttachments.getProceduralAttachmentsTopRewriter)1 FirstOf (com.sri.ai.grinder.rewriter.core.FirstOf)1 FunctorSwitch (com.sri.ai.grinder.rewriter.core.FunctorSwitch)1 Switch (com.sri.ai.grinder.rewriter.core.Switch)1 SymbolSwitch (com.sri.ai.grinder.rewriter.core.SymbolSwitch)1