adams.parser
Class TwitterFilter

java.lang.Object
  extended by adams.core.ConsoleObject
      extended by adams.core.option.AbstractOptionHandler
          extended by adams.parser.AbstractExpressionEvaluator<T>
              extended by adams.parser.AbstractSymbolEvaluator<Boolean>
                  extended by adams.parser.TwitterFilter
All Implemented Interfaces:
Debuggable, Destroyable, OptionHandler, SizeOfHandler, GrammarSupplier, Serializable

public class TwitterFilter
extends AbstractSymbolEvaluator<Boolean>

Evaluates Twitter filter expressions.

The expressions use the following grammar:

expr_list ::= expr_list expr | expr;
expr ::= ( expr )
| boolexpr
;

boolexpr ::= BOOLEAN
| ( boolexpr )
| not boolexpr
| boolexpr and boolexpr
| boolexpr or boolexpr
| boolexpr xor boolexpr

| langcode <match> pattern
| country <match> pattern
| countrycode <match> pattern
| place <match> pattern
| source <match> pattern
| text <match> pattern
| user <match> pattern

| ifelse ( boolexpr:test , boolexpr:test_true , boolexpr:test_false )
;

The '<match>' operator can be one of the following:
1. '=' - exact match (the twitter field must be the exact 'pattern' string)
2. ':' - substring match (the 'pattern' can occur anywhere in the twitter field)
3. '~' - regular expression match (the 'pattern' is a regular expression that the twitter field must match)

Please note, all strings are converted to lower case before the filter is applied.

Valid options are:

-D <int> (property: debugLevel)
    The greater the number the more additional info the scheme may output to
    the console (0 = off).
    default: 0
    minimum: 0
 
-env <java.lang.String> (property: environment)
    The class to use for determining the environment.
    default: adams.env.Environment
 
-expression <java.lang.String> (property: expression)
    The filter expression to evaluate.
    default: text~\".*\"
 
-symbol <adams.core.base.BaseString> [-symbol ...] (property: symbols)
    The symbols to initialize the parser with, key-value pairs: name=value.
    default:
 

Version:
$Revision: 4584 $
Author:
FracPete (fracpete at waikato dot ac dot nz)
See Also:
Serialized Form

Field Summary
 
Fields inherited from class adams.parser.AbstractSymbolEvaluator
m_Symbols
 
Fields inherited from class adams.parser.AbstractExpressionEvaluator
m_Environment, m_Expression
 
Fields inherited from class adams.core.option.AbstractOptionHandler
m_DebugLevel, m_OptionManager
 
Constructor Summary
TwitterFilter()
           
 
Method Summary
protected  Boolean doEvaluate(HashMap symbols)
          Performs the actual evaluation.
static boolean evaluate(String expr, HashMap symbols)
          Parses and evaluates the given expression.
 String expressionTipText()
          Returns the tip text for this property.
protected  String getDefaultExpression()
          Returns the default expression to use.
 String getGrammar()
          Returns a string representation of the grammar.
 String globalInfo()
          Returns a string describing the object.
protected  Object initializeSymbol(String name, String value)
          Initializes the symbol.
static void main(String[] args)
          Runs the evaluator from command-line.
 
Methods inherited from class adams.parser.AbstractSymbolEvaluator
defineOptions, evaluate, getSymbols, initialize, initializeSymbols, setSymbols, symbolsTipText
 
Methods inherited from class adams.parser.AbstractExpressionEvaluator
environmentTipText, forCommandLine, forName, getEnvironment, getExpression, runEvaluator, setEnvironment, setExpression
 
Methods inherited from class adams.core.option.AbstractOptionHandler
cleanUpOptions, debug, debug, debugLevelTipText, destroy, finishInit, getDebugLevel, getOptionManager, isDebugOn, newOptionManager, reset, setDebugLevel, toCommandLine, toString
 
Methods inherited from class adams.core.ConsoleObject
getDebugging, getSystemErr, getSystemOut, sizeOf
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TwitterFilter

public TwitterFilter()
Method Detail

globalInfo

public String globalInfo()
Returns a string describing the object.

Specified by:
globalInfo in class AbstractOptionHandler
Returns:
a description suitable for displaying in the gui

getGrammar

public String getGrammar()
Returns a string representation of the grammar.

Returns:
the grammar, null if not available

getDefaultExpression

protected String getDefaultExpression()
Returns the default expression to use.

Specified by:
getDefaultExpression in class AbstractExpressionEvaluator<Boolean>
Returns:
the default expression

expressionTipText

public String expressionTipText()
Returns the tip text for this property.

Specified by:
expressionTipText in class AbstractExpressionEvaluator<Boolean>
Returns:
tip text for this property suitable for displaying in the GUI or for listing the options.

initializeSymbol

protected Object initializeSymbol(String name,
                                  String value)
Initializes the symbol.

Specified by:
initializeSymbol in class AbstractSymbolEvaluator<Boolean>
Parameters:
name - the name of the symbol
value - the string representation of the symbol
Returns:
the object representation of the symbol

doEvaluate

protected Boolean doEvaluate(HashMap symbols)
                      throws Exception
Performs the actual evaluation.

Specified by:
doEvaluate in class AbstractSymbolEvaluator<Boolean>
Parameters:
symbols - the symbols to use
Returns:
the evaluation, or null in case of error
Throws:
Exception - if evaluation fails

evaluate

public static boolean evaluate(String expr,
                               HashMap symbols)
                        throws Exception
Parses and evaluates the given expression. Returns the result of the boolean expression, based on the given values of the symbols.

Parameters:
expr - the expression to evaluate
symbols - the symbol/value mapping
Returns:
the evaluated result
Throws:
Exception - if something goes wrong

main

public static void main(String[] args)
Runs the evaluator from command-line.

Parameters:
args - the command-line options, use "-help" to list them


Copyright © 2013 University of Waikato, Hamilton, NZ. All Rights Reserved.