Class LogicExpression<E>

java.lang.Object
edu.washington.cs.knowitall.logic.LogicExpression<E>
Type Parameters:
E - the type of the base expressions
All Implemented Interfaces:
com.google.common.base.Predicate<E>, Predicate<E>

public class LogicExpression<E> extends Object implements com.google.common.base.Predicate<E>
A logic expression engine that operates over user specified objects.
  • Field Details

  • Constructor Details

  • Method Details

    • compile

      public static <E> LogicExpression<E> compile(List<Expression<E>> expressions)
      Compile an infix list of tokens into an expression tree.
      Parameters:
      rpn - a list of tokens in infix form.
      Returns:
      an expression tree.
    • compile

      public static <E> LogicExpression<E> compile(String input, com.google.common.base.Function<String,Expression.Arg<E>> factoryDelegate)
      Helper factory method to instantiate a LogicExpression.
      Parameters:
      input - The string to parse.
      factoryDelegate - The factory to build tokens.
      Returns:
      a new LogicExpression
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • isEmpty

      public boolean isEmpty()
      If the expression is empty, it returns true for all inputs.
      Returns:
      true iff the expression is empty.
    • apply

      public boolean apply(E entity)
      Specified by:
      apply in interface com.google.common.base.Predicate<E>
    • buildAst

      public static <E> Expression.Apply<E> buildAst(List<Expression<E>> rpn)
      Compile a rpn list of tokens into an expression tree.
      Parameters:
      rpn - a list of tokens in infix form.
      Returns:
      an expression tree.
    • getArgs

      public List<String> getArgs()
      Return a list of the arguments contained in the expression.
      Returns:
    • getArgs

      private void getArgs(Expression.Apply<?> apply, List<String> args)
      Private helper method to recursively find arguments.
      Parameters:
      apply - the expression tree to search.
      args - the resulting list of arguments.
    • rpn

      Converts an infix logic representation into a postfix logic representation.
      Parameters:
      tokens - a list of tokens in infix form.
      Returns:
      a list of tokens in postfix (rpn) form.
      Throws:
      LogicException.CompileLogicException
    • main

      public static void main(String[] args)
      Iteractively interpret logic statements from stdin such as "true | (true & false)".
      Parameters:
      args -