Package adams.parser
Class TwitterFilter
- java.lang.Object
-
- adams.core.logging.LoggingObject
-
- adams.core.logging.CustomLoggingLevelObject
-
- adams.core.option.AbstractOptionHandler
-
- adams.parser.AbstractExpressionEvaluator<T>
-
- adams.parser.AbstractSymbolEvaluator<Boolean>
-
- adams.parser.TwitterFilter
-
- All Implemented Interfaces:
adams.core.Destroyable
,adams.core.GlobalInfoSupporter
,adams.core.logging.LoggingLevelHandler
,adams.core.logging.LoggingSupporter
,adams.core.option.OptionHandler
,adams.core.SizeOfHandler
,adams.parser.GrammarSupplier
,Serializable
public class TwitterFilter extends adams.parser.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
| numexpr < numexpr
| numexpr <= numexpr
| numexpr = numexpr
| numexpr > numexpr
| numexpr >= numexpr
| numexpr <> numexpr
| retweet
| isretweeted
| langcode <match> pattern
| country <match> pattern
| countrycode <match> pattern
| place <match> pattern
| source <match> pattern
| text <match> pattern
| user <match> pattern
| screenname <match> pattern
| hashtag <match> pattern
| usermention <match> pattern
| statuslang <match> pattern
| if[else] ( boolexpr:test , boolexpr:test_true , boolexpr:test_false )
| has ( parameter )
;
numexpr ::= num
| longitude
| latitude
| favcount
;
parameter ::= langcode
| country
| countrycode
| place
| source
| text
| user
| longitude
| latitude
;
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.
-logging-level <OFF|SEVERE|WARNING|INFO|CONFIG|FINE|FINER|FINEST> (property: loggingLevel) The logging level for outputting errors and debugging output. default: WARNING
-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$
- Author:
- FracPete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description TwitterFilter()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description 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, destroy, finishInit, getDefaultLoggingLevel, getOptionManager, loggingLevelTipText, newOptionManager, reset, setLoggingLevel, toCommandLine, toString
-
Methods inherited from class adams.core.logging.LoggingObject
configureLogger, getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled, sizeOf
-
-
-
-
Method Detail
-
globalInfo
public String globalInfo()
Returns a string describing the object.- Specified by:
globalInfo
in interfaceadams.core.GlobalInfoSupporter
- Specified by:
globalInfo
in classadams.core.option.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 classadams.parser.AbstractExpressionEvaluator<Boolean>
- Returns:
- the default expression
-
expressionTipText
public String expressionTipText()
Returns the tip text for this property.- Specified by:
expressionTipText
in classadams.parser.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 classadams.parser.AbstractSymbolEvaluator<Boolean>
- Parameters:
name
- the name of the symbolvalue
- 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.
-
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 evaluatesymbols
- 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
-
-