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<java.lang.String,LogicExpression<E>>
,java.util.function.Function<java.lang.String,LogicExpression<E>>
public abstract class LogicExpressionParser<E> extends java.lang.Object implements com.google.common.base.Function<java.lang.String,LogicExpression<E>>
A logic expression engine that operates over user specified objects.
-
-
Field Summary
Fields Modifier and Type Field Description static java.util.regex.Pattern
doubleQuoteStringLiteralRegex
private static java.util.List<java.util.regex.Pattern>
literalPatterns
static java.util.regex.Pattern
regexLiteralRegex
static java.util.regex.Pattern
singleQuoteStringLiteralRegex
-
Constructor Summary
Constructors Constructor Description LogicExpressionParser()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description LogicExpression<E>
apply(java.lang.String string)
abstract Expression.Arg<E>
factory(java.lang.String argument)
The factory method creates an argument from the supplied token string.LogicExpression<E>
parse(java.lang.String string)
Create a LogicExpression object from the supplied string.java.lang.String
readToken(java.lang.String remainder)
The readToken method reads a token from the remaining LogicExpression string.java.util.List<Expression<E>>
tokenize(java.lang.String input)
Convert an infix string logic representation to an infix list of tokens.
-
-
-
Field Detail
-
doubleQuoteStringLiteralRegex
public static final java.util.regex.Pattern doubleQuoteStringLiteralRegex
-
singleQuoteStringLiteralRegex
public static final java.util.regex.Pattern singleQuoteStringLiteralRegex
-
regexLiteralRegex
public static final java.util.regex.Pattern regexLiteralRegex
-
literalPatterns
private static final java.util.List<java.util.regex.Pattern> literalPatterns
-
-
Method Detail
-
parse
public LogicExpression<E> parse(java.lang.String string)
Create a LogicExpression object from the supplied string.- Parameters:
string
-- Returns:
-
apply
public LogicExpression<E> apply(java.lang.String string)
- Specified by:
apply
in interfacecom.google.common.base.Function<java.lang.String,LogicExpression<E>>
- Specified by:
apply
in interfacejava.util.function.Function<java.lang.String,LogicExpression<E>>
-
factory
public abstract Expression.Arg<E> factory(java.lang.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 java.lang.String readToken(java.lang.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 &, |, 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 java.util.List<Expression<E>> tokenize(java.lang.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
-
-