Class LogicExpressionParser<E>

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

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

    • doubleQuoteStringLiteralRegex

      public static final Pattern doubleQuoteStringLiteralRegex
    • singleQuoteStringLiteralRegex

      public static final Pattern singleQuoteStringLiteralRegex
    • regexLiteralRegex

      public static final Pattern regexLiteralRegex
    • literalPatterns

      private static final List<Pattern> literalPatterns
  • Constructor Details

    • LogicExpressionParser

      public LogicExpressionParser()
  • Method Details

    • parse

      public LogicExpression<E> parse(String string)
      Create a LogicExpression object from the supplied string.
      Parameters:
      string -
      Returns:
    • apply

      public LogicExpression<E> apply(String string)
      Specified by:
      apply in interface com.google.common.base.Function<String,LogicExpression<E>>
      Specified by:
      apply in interface Function<String,LogicExpression<E>>
    • factory

      public abstract Expression.Arg<E> factory(String argument)
      The factory method creates an argument from the supplied token string.
      Parameters:
      argument - a string representation of a token
      Returns:
      an evaluatable representation of a token
    • readToken

      public String readToken(String remainder)
      The readToken method reads a token from the remaining LogicExpression string. A token may contain a string. If it contains parentheses, the token will last until the parentheses are balanced. And invalid input: '&', |, or unbalanced ) will mark the end of a token. This is a default implementation that may be overriden.
      Parameters:
      remainder - the remaining text to tokenize
      Returns:
      a token from the beginning on `remaining`
    • tokenize

      public List<Expression<E>> tokenize(String input) throws LogicException.TokenizeLogicException
      Convert an infix string logic representation to an infix list of tokens.
      Parameters:
      input - an infix string logic representation.
      factory - a delegate that converts a string representation of an argument into a token object. @return
      Throws:
      LogicException.TokenizeLogicException