Class LyreDSL


  • public final class LyreDSL
    extends Object
    Static functions allowing for a functional style DSL for constructing LyreExpressions.
    Author:
    David B. Bracewell
    • Field Detail

      • $_

        public static final LyreExpression $_
        Returns the current Object being processed. Note that one-argument methods in Lyre (e.g. lower, isUpper, etc.) have an implied `$_` argument if none is given.
            Usage:  $_
         
      • FALSE

        public static final LyreExpression FALSE
        Returns a constant false value
            Usage:  false
         
      • MATCH_ALL

        public static final LyreExpression MATCH_ALL
        Returns a constant true value for any object
            Usage:  ~
         
      • NAN

        public static final LyreExpression NAN
        Returns a constant NaN value
            Usage:  NaN
         
      • NEGATIVE_INFINITY

        public static final LyreExpression NEGATIVE_INFINITY
        Returns a constant Negative Infinity value
            Usage:  -INF
         
      • NULL

        public static final LyreExpression NULL
        Returns a constant null value.
            Usage:  null
         
      • POSITIVE_INFINITY

        public static final LyreExpression POSITIVE_INFINITY
        Returns a constant Positive Infinity value
            Usage:  INF
         
      • TRUE

        public static final LyreExpression TRUE
        Returns a constant true value
            Usage:  true
         
      • binary

        public static final LyreExpression binary
        Converts a list of values into binary features over the current HString.
            Usage: binary{'prefix'}(expression)
            e.g.: binary{'WORD'}(@TOKEN) -- create bag-of-words binary features over the tokens on the current HString
                                            with each feature having the prefix "WORD"
            e.g.: binary(@TOKEN) -- create bag-of-words binary features over the tokens on the current HString
            e.g.: binary{'BOW'} -- create bag-of-words binary features over the current HString with the prefix "BOW"
            e.g.: binary -- create bag-of-words binary features over the current HString
         
      • exists

        public static final LyreExpression exists
        Predicate checking if the current Object is null. CharSequences are also checked for being blank and Collections are checked whether they are empty or not.
            Usage:  isEmpty
         
      • frequency

        public static final LyreExpression frequency
        Converts a list of values into features with raw counts (i.e. frequency).
            Usage: frequency{'prefix'}(expression)
            e.g.: frequency{'WORD'}(@TOKEN) -- create bag-of-words with raw counts features over the tokens on the current HString
                                            with each feature having the prefix "WORD"
            e.g.: frequency(@TOKEN) -- create bag-of-words binary features over the tokens on the current HString
            e.g.: frequency{'BOW'} -- create bag-of-words binary features over the current HString with the prefix "BOW"
            e.g.: frequency -- create bag-of-words binary features over the current HString
         
      • hasStopWord

        public static final LyreExpression hasStopWord
        Predicate checking if the current HString contains a stop word
            Usage:  hasStopWord
         
      • isAlphaNumeric

        public static final LyreExpression isAlphaNumeric
        Predicate checking if the current HString contains all alphanumeric characters
            Usage:  isAlphaNumeric
         
      • isContentWord

        public static final LyreExpression isContentWord
        Predicate checking if the current HString is a content word
            Usage:  isContentWord
         
      • isDigit

        public static final LyreExpression isDigit
        Predicate checking if the current HString is a digit
            Usage:  isDigit
         
      • isLetter

        public static final LyreExpression isLetter
        Predicate checking if the current HString is all letters
            Usage:  isLetter
         
      • isLower

        public static final LyreExpression isLower
        Predicate checking if the current HString is lower case
            Usage:  isLower
         
      • isPunctuation

        public static final LyreExpression isPunctuation
        Predicate checking if the current HString is all punctuation
            Usage:  isPunctuation
         
      • isStopWord

        public static final LyreExpression isStopWord
        Predicate checking if the current HString is a stop word
            Usage:  isStopWord
         
      • isUpper

        public static final LyreExpression isUpper
        Predicate checking if the current HString is upper case
            Usage:  isUpper
         
      • isWhitespace

        public static final LyreExpression isWhitespace
        Returns TRUE if the given object is whitespace
            Usage:  isWhitespace
         
      • l1

        public static final LyreExpression l1
        Converts a list of values into features with L1-normalized counts.
            Usage: L1{'prefix'}(expression)
            e.g.: L1{'WORD'}(@TOKEN) -- create bag-of-words with L1-normalized counts features over the tokens on the current HString
                                            with each feature having the prefix "WORD"
            e.g.: L1(@TOKEN) -- create bag-of-words binary features over the tokens on the current HString
            e.g.: L1{'BOW'} -- create bag-of-words binary features over the current HString with the prefix "BOW"
            e.g.: L1 -- create bag-of-words binary features over the current HString
         
      • lemma

        public static final LyreExpression lemma
        Gets the lemmatized form of the current HString.
            Usage:  lemma
         
      • len

        public static final LyreExpression len
        Determines the length of the current Object (characters if CharSequence, elements if Collection)
            Usage:  len
         
      • llen

        public static final LyreExpression llen
        Determines the size of the current Object treating it as a list
            Usage:  llen
         
      • lower

        public static final LyreExpression lower
        Gets the lower-cased string form of the current HString.
            Usage:  lower
         
      • pos

        public static final LyreExpression pos
        Returns the part-of-speech of the current HString.
            usage: pos
         
      • sentences

        public static final LyreExpression sentences
        Returns all SENTENCES of the given type overlapping with the current HString
            Usage:  @ANNOTATION_TYPE
            e.g.: @SENTENCE
         
      • stem

        public static final LyreExpression stem
        Gets the stemmed form of the current HString.
            Usage:  stem
         
      • string

        public static final LyreExpression string
        Gets the string form of the current Object.
            Usage:  string
         
      • tlen

        public static final LyreExpression tlen
        Determines the length of the current Object (characters if CharSequence, elements if Collection)
            Usage:  len
         
      • tokens

        public static final LyreExpression tokens
        Returns all TOKENS of the given type overlapping with the current HString
            Usage:  @ANNOTATION_TYPE
            e.g.: @TOKEN
         
      • trim

        public static final LyreExpression trim
        Trims stopwords from the current HString
            Usage: trim()
         
      • upos

        public static final LyreExpression upos
        Returns the universal part-of-speech of the current HString.
            usage: upos
         
      • upper

        public static final LyreExpression upper
        Gets the upper-cased string form of the current HString.
            Usage:  upper
         
    • Constructor Detail

      • LyreDSL

        public LyreDSL()
    • Method Detail

      • all

        public static LyreExpression all​(@NonNull
                                         @NonNull LyreExpression list,
                                         @NonNull
                                         @NonNull LyreExpression predicate)
        Returns true if all items in the given list evaluates to *true* for the given predicate expression.
            usage: all( list_expression, predicate_expression )
            e.g.: all( @TOKEN, #VERB ) -- returns true if all token on the current HString is a verb
         
        Parameters:
        list - the list of items to apply the predicate to
        predicate - the predicate to use for testing
        Returns:
        the LyreExpression
      • and

        public static LyreExpression and​(@NonNull
                                         @NonNull LyreExpression left,
                                         @NonNull
                                         @NonNull LyreExpression right)
        Returns true when the left-hand and right-hand expressions evaluate to true
            Usage:  expresion && expresion
            e.g.: isContentWord && len > 3 -- returns true if the current HString is a content word and has 3 or more characters
         
        Parameters:
        left - the left-hand expresion to evaluate as a predicate
        right - the right-hand expresion to evaluate as a predicate
        Returns:
        the LyreExpression
      • andPipe

        public static LyreExpression andPipe​(@NonNull
                                             @NonNull LyreExpression... expressions)
        Sequentially processes each expression with the output of the previous expression or the input object for the first expression.
            Usage: expression1 &> expression2 &> ... &> expression
         
        Parameters:
        expressions - The expressions to chain together.
        Returns:
        the lyre expression
      • annotation

        public static LyreExpression annotation​(@NonNull
                                                @NonNull AnnotationType type)
        Returns all annotations of the given type overlapping with the current HString
            Usage:  @ANNOTATION_TYPE
            e.g.: @PHRASE_CHUNK
         
        Parameters:
        type - the annotation type
        Returns:
        the LyreExpression
      • annotation

        public static LyreExpression annotation​(@NonNull
                                                @NonNull AnnotationType type,
                                                String tag)
        Returns all annotations of the given type overlapping with the current HString
            Usage:  @ANNOTATION_TYPE
            e.g.: @PHRASE_CHUNK
         
        Parameters:
        type - the annotation type
        tag - the tag to filter the annotations on
        Returns:
        the LyreExpression
      • annotation

        public static LyreExpression annotation​(@NonNull
                                                @NonNull AnnotationType type,
                                                @NonNull
                                                @NonNull LyreExpression expression)
        Returns all annotations of the given type overlapping with the HString resulting from the given expression.
            Usage:  @ANNOTATION_TYPE(expression)
            e.g.: @TOKEN(@PHRASE_CHUNK) -- returns a list of tokens over the phrase chunks on the current HString
         
        Parameters:
        type - the annotation type
        expression - the expression returning the HString from which annotations will be extracted.
        Returns:
        the LyreExpression
      • annotation

        public static LyreExpression annotation​(@NonNull
                                                @NonNull AnnotationType type,
                                                @NonNull
                                                @NonNull LyreExpression expression,
                                                String tag)
        Returns all annotations of the given type overlapping with the HString resulting from the given expression.
            Usage:  @ANNOTATION_TYPE(expression)
            e.g.: @TOKEN(@PHRASE_CHUNK) -- returns a list of tokens over the phrase chunks on the current HString
         
        Parameters:
        type - the annotation type
        expression - the expression returning the HString from which annotations will be extracted.
        tag - the tag to filter the annotations on
        Returns:
        the LyreExpression
      • any

        public static LyreExpression any​(@NonNull
                                         @NonNull LyreExpression list,
                                         @NonNull
                                         @NonNull LyreExpression predicate)
        Returns true if any item in the given list evaluates to *true* for the given predicate expression.
            usage: any( list_expression, predicate_expression )
            e.g.: any( @TOKEN, #VERB ) -- returns true if any token on the current HString is a verb
         
        Parameters:
        list - the list of items to apply the predicate to
        predicate - the predicate to use for testing
        Returns:
        the LyreExpression
      • apply

        public static LyreExpression apply​(@NonNull
                                           @NonNull LyreExpression object,
                                           @NonNull
                                           @NonNull LyreExpression operator)
        Applies the right-hand expression on the object resulting from the left-hand expression.
            Usage:  object_expression ~= operator_expression
            e.g.: 'abcdef' ~= /a/b/ -- will apply the regular expression substitution /a/b/ to the literal
                  'abcdef'
         
        Parameters:
        object - the expression returning the object the operator should be applied on
        operator - the operator to apply to the object
        Returns:
        the LyreExpression
      • array

        public static LyreExpression array​(@NonNull
                                           @NonNull LyreExpression... elements)
        Creates an array of expressions.
            usage: [ expression1, expresion2, ..., expressionN ]
            e.g.: ['a', 'b', 'c'] -- returns a list of the given literal values.
        
            Advanced Usage Example: $_ ~= [ @PHRASE_CHUNK, @ENTITY ]
            -- Applies the list of expressions to the current token resulting in a list of the phrase chunks and
            -- entities on the current HString
        
            Advanced Usage Example: $_ ~= [ concat('W=', lower), concat('isDigit=', isDigit) ]
            -- Applies the list of expressions to the current token resulting in a list of Strings as follows:
            -- given $_ = 'test' the resulting array would be [ 'W=test', 'isDigit=false' ]
         
        Parameters:
        elements - the array elements
        Returns:
        the LyreExpression
      • attribute

        public static LyreExpression attribute​(@NonNull
                                               @NonNull AttributeType<?> type)
        Returns the value of the given AttributeType on the current HString.
            Usage:  $ATTRIBUTE_TYPE
            e.g.: $PART_OF_SPEECH
         
        Parameters:
        type - the attribute type
        Returns:
        the LyreExpression
      • attribute

        public static LyreExpression attribute​(@NonNull
                                               @NonNull AttributeType<?> type,
                                               @NonNull
                                               @NonNull LyreExpression expression)
        Returns the value of the given AttributeType on the HString resulting from the given expression
            Usage:  $ATTRIBUTE_TYPE(expression)
            e.g.: $PART_OF_SPEECH(@PHRASE_CHUNK) --return the part-of-speech of the phrase chunk annotations
         
        Parameters:
        type - the attribute type
        expression - the expression returning the HString from which the attribute value will be extracted.
        Returns:
        the LyreExpression
      • binary

        public static LyreExpression binary​(String prefix,
                                            @NonNull
                                            @NonNull LyreExpression expression)
        Converts a list of values into binary features.
            Usage: binary{'prefix'}(expression)
            e.g.: binary{'WORD'}(@TOKEN) -- create bag-of-words binary features over the tokens on the current HString
                                            with each feature having the prefix "WORD"
            e.g.: binary(@TOKEN) -- create bag-of-words binary features over the tokens on the current HString
            e.g.: binary{'BOW'} -- create bag-of-words binary features over the current HString with the prefix "BOW"
            e.g.: binary -- create bag-of-words binary features over the current HString
         
        Parameters:
        prefix - the feature prefix (null is acceptable)
        expression - the expression returning the objects to convert into features
        Returns:
        the LyreExpression
      • binary

        public static LyreExpression binary​(String prefix)
        Converts a list of values into binary features over the current HString.
            Usage: binary{'prefix'}(expression)
            e.g.: binary{'WORD'}(@TOKEN) -- create bag-of-words binary features over the tokens on the current HString
                                            with each feature having the prefix "WORD"
            e.g.: binary(@TOKEN) -- create bag-of-words binary features over the tokens on the current HString
            e.g.: binary{'BOW'} -- create bag-of-words binary features over the current HString with the prefix "BOW"
            e.g.: binary -- create bag-of-words binary features over the current HString
         
        Parameters:
        prefix - the feature prefix (null is acceptable)
        Returns:
        the LyreExpression
      • binary

        public static LyreExpression binary​(@NonNull
                                            @NonNull LyreExpression expression)
        Converts a list of values into binary features.
            Usage: binary{'prefix'}(expression)
            e.g.: binary{'WORD'}(@TOKEN) -- create bag-of-words binary features over the tokens on the current HString
                                            with each feature having the prefix "WORD"
            e.g.: binary(@TOKEN) -- create bag-of-words binary features over the tokens on the current HString
            e.g.: binary{'BOW'} -- create bag-of-words binary features over the current HString with the prefix "BOW"
            e.g.: binary -- create bag-of-words binary features over the current HString
         
        Parameters:
        expression - the expression returning the objects to convert into features
        Returns:
        the LyreExpression
      • context

        public static LyreExpression context​(@NonNull
                                             @NonNull LyreExpression expression,
                                             int relative_position)
        Gets a contextual (previous or next) token for the given HString at the given position (relative).
            Usage: cxt( hstring_expression, relative_position )
            e.g.: cxt( $_, -1) -- gets the token left of the current HString
            e.g.: cxt( $_, 10) -- gets the token 10 to the right of the current HString
         
        Parameters:
        expression - the expression returning the HString to get the context of
        relative_position - the relative position
        Returns:
        the LyreExpression
      • context

        public static LyreExpression context​(@NonNull
                                             @NonNull LyreExpression expression,
                                             @NonNull
                                             @NonNull LyreExpression relative_position)
        Gets a contextual (previous or next) token for the given HString at the given position (relative).
            Usage: cxt( hstring_expression, relative_position )
            e.g.: cxt( $_, -1) -- gets the token left of the current HString
            e.g.: cxt( $_, 10) -- gets the token 10 to the right of the current HString
         
        Parameters:
        expression - the expression returning the HString to get the context of
        relative_position - the relative position
        Returns:
        the LyreExpression
      • count

        public static LyreExpression count​(@NonNull
                                           @NonNull LyreExpression expression)
        Counts the items resulting from the given expression (treated as a list) and applies a Frequency ValueCalculator to the result. Accepts OBJECT, HSTRING, and STRING expressions.
            Usage: count(expression, valueCalculator)
            e.g.: count(@TOKEN, 'Binary') -- creates binary counts of all tokens in the HString
            e.g.: count(ngram(2, @TOKEN)) -- creates frequency counts of all bigrams in the HString
         
        Parameters:
        expression - the expression returning the objects to convert into counts
        Returns:
        the LyreExpression
      • count

        public static LyreExpression count​(@NonNull
                                           @NonNull LyreExpression expression,
                                           @NonNull
                                           @NonNull LyreExpression valueCalculator)
        Counts the items resulting from the given expression (treated as a list) and applies the given ValueCalculator to the result. Accepts OBJECT, HSTRING, and STRING expressions.
            Usage: count(expression, valueCalculator)
            e.g.: count(@TOKEN, 'Binary') -- creates binary counts of all tokens in the HString
            e.g.: count(ngram(2, @TOKEN)) -- creates frequency counts of all bigrams in the HString
         
        Parameters:
        expression - the expression returning the objects to convert into counts
        valueCalculator - the ValueCalculator to use to adjust the values
        Returns:
        the LyreExpression
      • count

        public static LyreExpression count​(@NonNull
                                           @NonNull LyreExpression expression,
                                           @NonNull
                                           @NonNull ValueCalculator valueCalculator)
        Counts the items resulting from the given expression (treated as a list) and applies the given ValueCalculator to the result. Accepts OBJECT, HSTRING, and STRING expressions.
            Usage: count(expression, valueCalculator)
            e.g.: count(@TOKEN, 'Binary') -- creates binary counts of all tokens in the HString
            e.g.: count(ngram(2, @TOKEN)) -- creates frequency counts of all bigrams in the HString
         
        Parameters:
        expression - the expression returning the objects to convert into counts
        valueCalculator - the ValueCalculator to use to adjust the values
        Returns:
        the LyreExpression
      • dep

        public static LyreExpression dep​(@NonNull
                                         @NonNull RelationDirection direction)
        Gets the annotation(s) having a dependency relation in the given direction (INCOMING or OUTGOING).
            Usage:  @>dep -- annotations from outgoing dependency of given relation
            Usage:  @ -- return the annotation(s) that the annotations reaching from the current token via a dependency relation.
         
        Parameters:
        direction - the direction of the relation (INCOMING or OUTGOING)
        Returns:
        the LyreExpression
      • dep

        public static LyreExpression dep​(@NonNull
                                         @NonNull RelationDirection direction,
                                         String relation)
        Gets the annotation(s) having the following dependency relation in the given direction (INCOMING or OUTGOING).
            Usage:  @>dep{'relation'} -- annotations from outgoing dependency of given relation
            Usage:  @{nsubj} -- return the annotation that the current token has an nsubj relation with
         
        Parameters:
        direction - the direction of the relation (INCOMING or OUTGOING)
        relation - the desired dependency relation
        Returns:
        the LyreExpression
      • dep

        public static LyreExpression dep​(@NonNull
                                         @NonNull RelationDirection direction,
                                         @NonNull
                                         @NonNull LyreExpression expression)
        Gets the annotation(s) having the following dependency relation in the given direction (INCOMING or OUTGOING).
            Usage:  @>dep{'relation'} -- annotations from outgoing dependency of given relation
            Usage:  @{nsubj} -- return the annotation that the current token has an nsubj relation with
         
        Parameters:
        direction - the direction of the relation (INCOMING or OUTGOING)
        expression - the expression returning the HString to extract dependency relations over
        Returns:
        the LyreExpression
      • dep

        public static LyreExpression dep​(@NonNull
                                         @NonNull RelationDirection direction,
                                         String relation,
                                         @NonNull
                                         @NonNull LyreExpression expression)
        Gets the annotation(s) having the following dependency relation in the given direction (INCOMING or OUTGOING).
            Usage:  @>dep{'relation'}( expression ) -- annotations from outgoing dependency of given relation
            Usage:  @{nsubj}( @PHRASE_CHUNK ) -- return the annotation that the phrase chunks on the current token
                                                have an nsubj relation with
         
        Parameters:
        direction - the direction of the relation (INCOMING or OUTGOING)
        relation - the desired dependency relation
        expression - the expression returning the HString to extract dependency relations over
        Returns:
        the LyreExpression
      • eq

        public static LyreExpression eq​(@NonNull
                                        @NonNull LyreExpression left,
                                        @NonNull
                                        @NonNull LyreExpression right)
        Checks if the left and right expression are equal using .equals, checking for content equality for HStrings and literals, and using Tag.isInstance(Tag) for tags.
            Usage: left_expression = right_expresison
            e.g.: $_ = 'man' -- checks if the current object is equal to man
         
        Parameters:
        left - the left hand expression
        right - the right hand expression
        Returns:
        the LyreExpression
      • eq

        public static LyreExpression eq​(LyreExpression left,
                                        double value)
        Checks if the left and right expression are equal using .equals, checking for content equality for HStrings and literals, and using Tag.isInstance(Tag) for tags.
            Usage: left_expression = right_expresison
            e.g.: $_ = 'man' -- checks if the current object is equal to man
         
        Parameters:
        left - the left hand expression
        value - the right hand value
        Returns:
        the LyreExpression
      • exists

        public static LyreExpression exists​(@NonNull
                                            @NonNull LyreExpression expression)
        Predicate checking if the Object returned from the given expression exists meaning it is not null and not a blank CharSequence or empty list.
            Usage:  exists( expression )
            e.g.: exists( @ENTITY ) -- checks if the result of the entity annotation is an empty or null list
         
        Parameters:
        expression - the expression returning an HString to check is empty
        Returns:
        the LyreExpression
      • feature

        public static LyreExpression feature​(@NonNull
                                             @NonNull ValueCalculator calculator)
        Converts a list of values into features.
        Parameters:
        calculator - the ValueCalculator for calculating feature values
        Returns:
        the LyreExpression
      • feature

        public static LyreExpression feature​(@NonNull
                                             @NonNull ValueCalculator calculator,
                                             @NonNull
                                             @NonNull LyreExpression expression)
        Converts a list of values into features.
        Parameters:
        calculator - the ValueCalculator for calculating feature values
        expression - the expression returning the objects to convert into features
        Returns:
        the LyreExpression
      • feature

        public static LyreExpression feature​(String prefix,
                                             @NonNull
                                             @NonNull ValueCalculator calculator)
        Converts a list of values into features.
        Parameters:
        prefix - the feature prefix (null is acceptable)
        calculator - the ValueCalculator for calculating feature values
        Returns:
        the LyreExpression
      • feature

        public static LyreExpression feature​(String prefix,
                                             @NonNull
                                             @NonNull ValueCalculator calculator,
                                             @NonNull
                                             @NonNull LyreExpression expression)
        Converts a list of values into features.
        Parameters:
        prefix - the feature prefix (null is acceptable)
        calculator - the ValueCalculator for calculating feature values
        expression - the expression returning the objects to convert into features
        Returns:
        the LyreExpression
      • filter

        public static LyreExpression filter​(@NonNull
                                            @NonNull LyreExpression list,
                                            @NonNull
                                            @NonNull LyreExpression predicate)
        filters a list keeping only those elements that given predicate evaluates true for.
            Usage: filter( list_expression, predicate_expression )
            e.g.: filter( @TOKEN, isContentWord ) -- keep all tokens on the current HString that are content words
         
        Parameters:
        list - the list
        predicate - the predicate
        Returns:
        the lyre expression
      • first

        public static LyreExpression first​(@NonNull
                                           @NonNull LyreExpression list)
        Return the first element of a list expression or null if none.
            Usage: first( list_expression )
            e.g.: first( @ENTITY ) -- return the first entity annotation on this HString
         
        Parameters:
        list - the list expression
        Returns:
        the LyreExpression
      • flatten

        public static LyreExpression flatten​(@NonNull
                                             @NonNull LyreExpression list)
        Flattens all elements in a list recursively.
            Usage: flatten( list_expression )
            e.g.: flatten( map(@TOKEN, [ 'p1=' + $_[:-1], 'p2=' + $_[:-2] ] )  ) -- create a flattened list of unigram
                   and bigram prefixes of all tokens on the current HString.
         
        Parameters:
        list - the list
        Returns:
        the LyreExpression
      • frequency

        public static LyreExpression frequency​(String prefix,
                                               @NonNull
                                               @NonNull LyreExpression expression)
        Converts a list of values into features with raw counts (i.e. frequency).
            Usage: frequency{'prefix'}(expression)
            e.g.: frequency{'WORD'}(@TOKEN) -- create bag-of-words with raw counts features over the tokens on the current HString
                                            with each feature having the prefix "WORD"
            e.g.: frequency(@TOKEN) -- create bag-of-words binary features over the tokens on the current HString
            e.g.: frequency{'BOW'} -- create bag-of-words binary features over the current HString with the prefix "BOW"
            e.g.: frequency -- create bag-of-words binary features over the current HString
         
        Parameters:
        prefix - the feature prefix (null is acceptable)
        expression - the expression returning the objects to convert into features
        Returns:
        the LyreExpression
      • frequency

        public static LyreExpression frequency​(String prefix)
        Converts a list of values into features with raw counts (i.e. frequency).
            Usage: frequency{'prefix'}(expression)
            e.g.: frequency{'WORD'}(@TOKEN) -- create bag-of-words with raw counts features over the tokens on the current HString
                                            with each feature having the prefix "WORD"
            e.g.: frequency(@TOKEN) -- create bag-of-words binary features over the tokens on the current HString
            e.g.: frequency{'BOW'} -- create bag-of-words binary features over the current HString with the prefix "BOW"
            e.g.: frequency -- create bag-of-words binary features over the current HString
         
        Parameters:
        prefix - the feature prefix (null is acceptable)
        Returns:
        the LyreExpression
      • frequency

        public static LyreExpression frequency​(@NonNull
                                               @NonNull LyreExpression expression)
        Converts a list of values into features with raw counts (i.e. frequency).
            Usage: frequency{'prefix'}(expression)
            e.g.: frequency{'WORD'}(@TOKEN) -- create bag-of-words with raw counts features over the tokens on the current HString
                                            with each feature having the prefix "WORD"
            e.g.: frequency(@TOKEN) -- create bag-of-words binary features over the tokens on the current HString
            e.g.: frequency{'BOW'} -- create bag-of-words binary features over the current HString with the prefix "BOW"
            e.g.: frequency -- create bag-of-words binary features over the current HString
         
        Parameters:
        expression - the expression returning the objects to convert into features
        Returns:
        the LyreExpression
      • get

        public static LyreExpression get​(@NonNull
                                         @NonNull LyreExpression list,
                                         int index)
        Gets the i-th element in the given list or null if the index is invalid
            Usage: get( index, list_expression )
            e.g.: get(@TOKEN, 0) -- get the first token
            e.g.: get(@TOKEN, 10) -- get the 10th token
         
        Parameters:
        list - the container
        index - the index
        Returns:
        the LyreExpression
      • get

        public static LyreExpression get​(@NonNull
                                         @NonNull LyreExpression listExpression,
                                         @NonNull
                                         @NonNull LyreExpression index)
        Gets the i-th element in the given list or null if the index is invalid
            Usage: get( index, list_expression )
            e.g.: get(@TOKEN, 0) -- get the first token
            e.g.: get(@TOKEN, 10) -- get the 10th token
         
        Parameters:
        listExpression - the container
        index - the index
        Returns:
        the LyreExpression
      • gt

        public static LyreExpression gt​(@NonNull
                                        @NonNull LyreExpression left,
                                        @NonNull
                                        @NonNull LyreExpression right)
        Checks if the left-hand expression is greater than the right-hand expression. Will default to string comparisons for non-numeric values.
            Usage: left_expression > right_expresison
            e.g.: $CONFIDENCE > 0.9 -- checks if the numeric confidence attributes is greater than 0.9
         
        Parameters:
        left - the left hand expression
        right - the right hand expression
        Returns:
        the LyreExpression
      • gt

        public static LyreExpression gt​(@NonNull
                                        @NonNull LyreExpression left,
                                        double value)
        Checks if the left-hand expression is greater than the right-hand expression. Will default to string comparisons for non-numeric values.
            Usage: left_expression > right_expresison
            e.g.: $CONFIDENCE > 0.9 -- checks if the numeric confidence attributes is greater than 0.9
         
        Parameters:
        left - the left hand expression
        value - the right hand value
        Returns:
        the LyreExpression
      • gte

        public static LyreExpression gte​(@NonNull
                                         @NonNull LyreExpression left,
                                         @NonNull
                                         @NonNull LyreExpression right)
        Checks if the left-hand expression is greater than or equal to the right-hand expression. Will default to string comparisons for non-numeric values.
            Usage: left_expression >= right_expresison
            e.g.: $CONFIDENCE >= 0.9 -- checks if the numeric confidence attributes is greater than or equal  to 0.9
         
        Parameters:
        left - the left hand expression
        right - the right hand expression
        Returns:
        the LyreExpression
      • gte

        public static LyreExpression gte​(@NonNull
                                         @NonNull LyreExpression left,
                                         double value)
        Checks if the left-hand expression is greater than or equal to the right-hand expression. Will default to string comparisons for non-numeric values.
            Usage: left_expression >= right_expresison
            e.g.: $CONFIDENCE >= 0.9 -- checks if the numeric confidence attributes is greater than or equal  to 0.9
         
        Parameters:
        left - the left hand expression
        value - the right hand value
        Returns:
        the LyreExpression
      • has

        public static LyreExpression has​(@NonNull
                                         @NonNull LyreExpression container,
                                         @NonNull
                                         @NonNull LyreExpression expression)
        Checks if any annotations on the HString resulting from the left-hand expression evaluates to true using the right-hand expression.
            Usage:  hstring_expression in predicate_expression -- does the HString from the hstring_expression have an
                                                                  annotation matching the predicate_expression
            e.g.:  $_ has #NP(@PHRASE_CHUNK) -- return true if the current HString contains a phrase chunk with POS NP
         
        Parameters:
        container - the expression returning the container (HString) to search in
        expression - the expression to evaluate the HString with
        Returns:
        the LyreExpression
      • hasStopWord

        public static LyreExpression hasStopWord​(@NonNull
                                                 @NonNull LyreExpression expression)
        Predicate checking if the HString returned from the given expression contains a stop word
            Usage:  hasStopWord( expression )
            e.g.: hasStopWord( @TOKEN ) -- check if the tokens on the current HString are stop words
         
        Parameters:
        expression - the expression returning an HString to check if it has a stop word.
        Returns:
        the LyreExpression
      • ifThen

        public static LyreExpression ifThen​(@NonNull
                                            @NonNull LyreExpression condition,
                                            @NonNull
                                            @NonNull LyreExpression whenTrue,
                                            @NonNull
                                            @NonNull LyreExpression whenFalse)
        IF then function to perform a given true or false expression based on a given condition.
            Usage:  if(condition_expression, true_expression, false_expression)
            e.g.: if(isDigit, '[:digit:]', $_) --return the literal value '[:digit:]' when the current HString is a digit
                  or the HString itself when not a digit.
         
        Parameters:
        condition - the condition expression
        whenTrue - the expression to apply when the condition evaluates to true
        whenFalse - the expression to apply when the condition evaluates to false
        Returns:
        the LyreExpression
      • in

        public static LyreExpression in​(@NonNull
                                        @NonNull LyreExpression object,
                                        @NonNull
                                        @NonNull LyreExpression container)
        Checks if the left-hand object is "in" the right-hand object, where in means "contains".
            Usage:  object_expression in container_expression -- is te object from the object_expression contained in the container
                                                                 from the container_expression
            e.g.: 'a' in 'hat' -- return true if 'a' is the string 'hat'
            e.g.: 'dog' in ['cat', 'dog', 'bird'] -- return true if 'dog's in the list ['cat', 'dog', 'bird']
         
        Parameters:
        object - the expression that returns the object to search for
        container - the expression returning the container to search in
        Returns:
        the LyreExpression
      • interleave

        public static LyreExpression interleave​(@NonNull
                                                @NonNull AnnotationType... types)
        Returns all annotations of the given types in interleaved fashion (see HString.interleaved(AnnotationType...)**
            Usage:  interleave( ANNOTATION_TYPE1, ANNOTATION_TYPE2, ..., ANNOTATION_TYPEN )
            e.g.: interleave( PHRASE_CHUNK, TOKEN ) -- return a list of annotations first trying to get phrase chunks and
                                                       falling back to tokens if not found
         
        Parameters:
        types - the annotation types to interleave
        Returns:
        the LyreExpression
      • iob

        public static LyreExpression iob​(@NonNull
                                         @NonNull LyreExpression type)
        Generates IOB-formatted tags for the given expression
            Usage: iob{ANNOTATION TYPE}( expression )
            e.g.: iob{PHRASE_CHUNK} -- generates iob formatted chunk part-of-speech tags over the current HString
            e.g.: iob{PHRASE_CHUNK}(@SENTENCE) -- generates iob formatted chunk part-of-speech tags over the sentences in
                                                    current HString
         
        Parameters:
        type - the annotation type
        Returns:
        the LyreExpression
      • iob

        public static LyreExpression iob​(@NonNull
                                         @NonNull AnnotationType type)
        Generates IOB-formatted tags for the given expression
            Usage: iob{ANNOTATION TYPE}( expression )
            e.g.: iob{PHRASE_CHUNK} -- generates iob formatted chunk part-of-speech tags over the current HString
            e.g.: iob{PHRASE_CHUNK}(@SENTENCE) -- generates iob formatted chunk part-of-speech tags over the sentences in
                                                    current HString
         
        Parameters:
        type - the annotation type
        Returns:
        the LyreExpression
      • iob

        public static LyreExpression iob​(@NonNull
                                         @NonNull AnnotationType type,
                                         @NonNull
                                         @NonNull LyreExpression expression)
        Generates IOB-formatted tags for the given expression
            Usage: iob('ANNOTATION_TYPE', expression )
            e.g.: iob('PHRASE_CHUNK')-- generates iob formatted chunk part-of-speech tags over the current HString
            e.g.: iob('PHRASE_CHUNK', @SENTENCE)-- generates iob formatted chunk part-of-speech tags over the sentences in
                                                    current HString
         
        Parameters:
        type - the annotation type
        expression - the expression returning the Annotations to generate IOB tags for
        Returns:
        the LyreExpression
      • iob

        public static LyreExpression iob​(@NonNull
                                         @NonNull LyreExpression type,
                                         @NonNull
                                         @NonNull LyreExpression expression)
        Generates IOB-formatted tags for the given expression
            Usage: iob('ANNOTATION_TYPE', expression )
            e.g.: iob('PHRASE_CHUNK')-- generates iob formatted chunk part-of-speech tags over the current HString
            e.g.: iob('PHRASE_CHUNK', @SENTENCE)-- generates iob formatted chunk part-of-speech tags over the sentences in
                                                    current HString
         
        Parameters:
        type - the annotation type
        expression - the expression returning the Annotations to generate IOB tags for
        Returns:
        the LyreExpression
      • isAlphaNumeric

        public static LyreExpression isAlphaNumeric​(@NonNull
                                                    @NonNull LyreExpression expression)
        Predicate checking if the HString returned from the given expression contains all alphanumeric characters
            Usage:  isAlphaNumeric( expression )
            e.g.: isAlphaNumeric( @TOKEN ) -- check if the tokens on the current HString are alphanumeric
         
        Parameters:
        expression - the expression returning an HString to check for all alphanumeric characters.
        Returns:
        the LyreExpression
      • isContentWord

        public static LyreExpression isContentWord​(@NonNull
                                                   @NonNull LyreExpression expression)
        Predicate checking if the HString returned from the given expression is a content word
            Usage:  isContentWord( expression )
            e.g.: isContentWord( @TOKEN ) -- check if the tokens on the current HString are content words
         
        Parameters:
        expression - the expression returning an HString to check is a content word.
        Returns:
        the LyreExpression
      • isDigit

        public static LyreExpression isDigit​(@NonNull
                                             @NonNull LyreExpression expression)
        Predicate checking if the HString returned from the given expression is a digit
            Usage:  isDigit( expression )
            e.g.: isDigit( @TOKEN ) -- check if the tokens on the current HString are digits
         
        Parameters:
        expression - the expression returning an HString to check is a digit.
        Returns:
        the LyreExpression
      • isLetter

        public static LyreExpression isLetter​(@NonNull
                                              @NonNull LyreExpression expression)
        Predicate checking if the HString returned from the given expression is all letters
            Usage:  isLetter( expression )
            e.g.: isLetter( @TOKEN ) -- check if the tokens on the current HString are all letters
         
        Parameters:
        expression - the expression returning an HString to check is all letters.
        Returns:
        the LyreExpression
      • isLower

        public static LyreExpression isLower​(@NonNull
                                             @NonNull LyreExpression expression)
        Predicate checking if the HString returned from the given expression is lower case
            Usage:  isLetter( expression )
            e.g.: isLetter( @TOKEN ) -- check if the tokens on the current HString are are lower case
         
        Parameters:
        expression - the expression returning an HString to check is lower case
        Returns:
        the LyreExpression
      • isPunctuation

        public static LyreExpression isPunctuation​(@NonNull
                                                   @NonNull LyreExpression expression)
        Predicate checking if the HString returned from the given expression is all punctuation
            Usage:  isPunctuation( expression )
            e.g.: isPunctuation( @TOKEN ) -- check if the tokens on the current HString are all punctuation
         
        Parameters:
        expression - the expression returning an HString to check is all punctuation.
        Returns:
        the LyreExpression
      • isStopWord

        public static LyreExpression isStopWord​(@NonNull
                                                @NonNull LyreExpression expression)
        Predicate checking if the HString returned from the given expression is a stop word
            Usage:  isStopWord( expression )
            e.g.: isStopWord( @TOKEN ) -- check if the tokens on the current HString are stop words
         
        Parameters:
        expression - the expression returning an HString to check is a stop word.
        Returns:
        the LyreExpression
      • isUpper

        public static LyreExpression isUpper​(@NonNull
                                             @NonNull LyreExpression expression)
        Predicate checking if the HString returned from the given expression is uppercase
            Usage:  isUpper( expression )
            e.g.: isUpper( @TOKEN ) -- check if the tokens on the current HString are uppercase
         
        Parameters:
        expression - the expression returning an HString to check is uppercase
        Returns:
        the LyreExpression
      • isWhitespace

        public static LyreExpression isWhitespace​(@NonNull
                                                  @NonNull LyreExpression expression)
        Predicate checking if the HString returned from the given expression is all whitespace
            Usage:  isWhitespace( expression )
            e.g.: isWhitespace( @TOKEN ) -- check if the tokens on the current HString are all whitespace
         
        Parameters:
        expression - the expression returning an HString to check is all whitespace.
        Returns:
        the LyreExpression
      • l1

        public static LyreExpression l1​(String prefix,
                                        @NonNull
                                        @NonNull LyreExpression expression)
        Converts a list of values into features with L1-normalized counts.
            Usage: L1{'prefix'}(expression)
            e.g.: L1{'WORD'}(@TOKEN) -- create bag-of-words with L1-normalized counts features over the tokens on the current HString
                                            with each feature having the prefix "WORD"
            e.g.: L1(@TOKEN) -- create bag-of-words binary features over the tokens on the current HString
            e.g.: L1{'BOW'} -- create bag-of-words binary features over the current HString with the prefix "BOW"
            e.g.: L1 -- create bag-of-words binary features over the current HString
         
        Parameters:
        prefix - the feature prefix (null is acceptable)
        expression - the expression returning the objects to convert into features
        Returns:
        the LyreExpression
      • l1

        public static LyreExpression l1​(String prefix)
        Converts a list of values into features with L1-normalized counts.
            Usage: L1{'prefix'}(expression)
            e.g.: L1{'WORD'}(@TOKEN) -- create bag-of-words with L1-normalized counts features over the tokens on the current HString
                                            with each feature having the prefix "WORD"
            e.g.: L1(@TOKEN) -- create bag-of-words binary features over the tokens on the current HString
            e.g.: L1{'BOW'} -- create bag-of-words binary features over the current HString with the prefix "BOW"
            e.g.: L1 -- create bag-of-words binary features over the current HString
         
        Parameters:
        prefix - the feature prefix (null is acceptable)
        Returns:
        the LyreExpression
      • l1

        public static LyreExpression l1​(@NonNull
                                        @NonNull LyreExpression expression)
        Converts a list of values into features with L1-normalized counts.
            Usage: L1{'prefix'}(expression)
            e.g.: L1{'WORD'}(@TOKEN) -- create bag-of-words with L1-normalized counts features over the tokens on the current HString
                                            with each feature having the prefix "WORD"
            e.g.: L1(@TOKEN) -- create bag-of-words binary features over the tokens on the current HString
            e.g.: L1{'BOW'} -- create bag-of-words binary features over the current HString with the prefix "BOW"
            e.g.: L1 -- create bag-of-words binary features over the current HString
         
        Parameters:
        expression - the expression returning the objects to convert into features
        Returns:
        the LyreExpression
      • last

        public static LyreExpression last​(@NonNull
                                          @NonNull LyreExpression list)
        Return the last element of a list expression or null if none.
            Usage: last( list_expression )
            e.g.: last( @ENTITY ) -- return the last entity annotation on this HString
         
        Parameters:
        list - the list expression
        Returns:
        the LyreExpression
      • lemma

        public static LyreExpression lemma​(@NonNull
                                           @NonNull LyreExpression expression)
        Gets the lemmatized form of the current HString resulting from the given expression.
            Usage:  lemma( expression )
            e.g.: lemma( @TOKEN ) -- returns the lemmatized form all tokens on the current HString
         
        Parameters:
        expression - the expression returning an HString to lemmatize
        Returns:
        the LyreExpression
      • len

        public static LyreExpression len​(@NonNull
                                         @NonNull LyreExpression expression)
        Determines the length of the current Object (characters if CharSequence, elements if Collection)
            Usage:  len( expression )
            e.g.: len( 'abc' ) -- returns the number of characters in the given literal
            e.g.: len( @TOKEN ) -- returns the number of tokens contained in the current HString
         
        Parameters:
        expression - the expression returning an Object to calculate the length of
        Returns:
        the LyreExpression
      • lexicon

        public static LyreExpression lexicon​(@NonNull
                                             @NonNull String name)
        Returns the Lexicon with the given name.
            Usage:  %LEXICON_NAME
            e.g.: %person -- return the lexicon named "person"
         
        Parameters:
        name - the name of the lexicon
        Returns:
        the LyreExpression
      • list

        public static LyreExpression list​(@NonNull
                                          @NonNull List<LyreExpression> elements)
        Creates an array of expressions.
            usage: [ expression1, expresion2, ..., expressionN ]
            e.g.: ['a', 'b', 'c'] -- returns a list of the given literal values.
        
            Advanced Usage Example: $_ ~= [ @PHRASE_CHUNK, @ENTITY ]
            -- Applies the list of expressions to the current token resulting in a list of the phrase chunks and
            -- entities on the current HString
        
            Advanced Usage Example: $_ ~= [ concat('W=', lower), concat('isDigit=', isDigit) ]
            -- Applies the list of expressions to the current token resulting in a list of Strings as follows:
            -- given $_ = 'test' the resulting array would be [ 'W=test', 'isDigit=false' ]
         
        Parameters:
        elements - the array elements
        Returns:
        the LyreExpression
      • literal

        public static LyreExpression literal​(@NonNull
                                             @NonNull String value)
        Lyre allows for string literals to be specified using single quotes ('). The backslash character can be use to escape a single quote if it is required in the literal.
            usage: 'value'
            e.g.: 'now is the time...'
         
        Parameters:
        value - the value
        Returns:
        the LyreExpression
      • literalArray

        public static LyreExpression literalArray​(Iterator<String> literals)
        Convenience method for constructing an array (list) of literal values.
        Parameters:
        literals - the literal values
        Returns:
        the LyreExpression
      • llen

        public static LyreExpression llen​(@NonNull
                                          @NonNull LyreExpression expression)
        Determines the length of the current Object treating it as a list.
            Usage:  len( expression )
            e.g.: llen( 'abc' ) -- returns the 1
            e.g.: llen( ['a', 2]) -- returns 2
         
        Parameters:
        expression - the expression returning an Object to calculate the length of
        Returns:
        the LyreExpression
      • longest

        public static LyreExpression longest​(@NonNull
                                             @NonNull LyreExpression list)
        Return the longest (character length) element of a list expression or null if none.
            Usage: longest( list_expression )
            e.g.: longest( @ENTITY ) -- return the entity annotation with the longest span on this HString
         
        Parameters:
        list - the list expression
        Returns:
        the LyreExpression
      • lookAhead

        public static LyreExpression lookAhead​(@NonNull
                                               @NonNull LyreExpression condition,
                                               @NonNull
                                               @NonNull LyreExpression expression)
        Determines if the next annotation matches the given condition (Positive Lookahead).
            usage: (?> expression)
            e.g.: (?> #VERB) -- returns true if the next Token is a verb
         
        Parameters:
        condition - the condition to be met by the next Token in order to evaluate to True
        expression - the expression
        Returns:
        the LyreExpression
      • lookBehind

        public static LyreExpression lookBehind​(@NonNull
                                                @NonNull LyreExpression condition,
                                                @NonNull
                                                @NonNull LyreExpression expression)
        Determines if the previous annotation matches the given expression (Positive Lookbehind).
            usage: (?< expression)
            e.g.: (?< #VERB) -- returns true if the previous Token is a verb
         
        Parameters:
        condition - the condition to be met by the previous Token in order to evaluate to True
        expression - the expression
        Returns:
        the LyreExpression
      • lower

        public static LyreExpression lower​(@NonNull
                                           @NonNull LyreExpression expression)
        Gets the lower-cased string form of the current HString resulting from the given expression.
            Usage:  lower( expression )
            e.g.: lower( @TOKEN ) -- returns the lower-cased string form  all tokens on the current HString
         
        Parameters:
        expression - the expression returning an HString to lower case
        Returns:
        the LyreExpression
      • lpad

        public static LyreExpression lpad​(@NonNull
                                          @NonNull LyreExpression expression,
                                          int minimumLength,
                                          char paddingCharacter)
        Pads the left-side of CharSequence with a given pad-character ensuring that length of CharSequence is at least the given minimum length.
            Usage: lpad( expression, minimum_length, padding_character )
            e.g.: lpad( $_, 5, '*' ) -- add * to the front of the current HString until the length is at least 5
                                          characters long
         
        Parameters:
        expression - the expression resulting in the string to left-pad
        minimumLength - the minimum length of the resulting padded string
        paddingCharacter - the character to use for padding
        Returns:
        the LyreExpression
      • lpad

        public static LyreExpression lpad​(@NonNull
                                          @NonNull LyreExpression expression,
                                          @NonNull
                                          @NonNull LyreExpression minimumLength,
                                          @NonNull
                                          @NonNull LyreExpression paddingCharacter)
        Pads the left-side of CharSequence with a given pad-character ensuring that length of CharSequence is at least the given minimum length.
            Usage: lpad( expression, minimum_length, padding_character )
            e.g.: lpad( $_, 5, '*' ) -- add * to the front of the current HString until the length is at least 5
                                          characters long
         
        Parameters:
        expression - the expression resulting in the string to left-pad
        minimumLength - the minimum length of the resulting padded string
        paddingCharacter - the character to use for padding
        Returns:
        the LyreExpression
      • lt

        public static LyreExpression lt​(@NonNull
                                        @NonNull LyreExpression left,
                                        @NonNull
                                        @NonNull LyreExpression right)
        Checks if the left-hand expression is less than the right-hand expression. Will default to string comparisons for non-numeric values.
            Usage: left_expression < right_expresison
            e.g.: $CONFIDENCE < 0.9 -- checks if the numeric confidence attributes is less than  0.9
         
        Parameters:
        left - the left hand expression
        right - the right hand expression
        Returns:
        the LyreExpression
      • lt

        public static LyreExpression lt​(@NonNull
                                        @NonNull LyreExpression left,
                                        double value)
        Checks if the left-hand expression is less than the right-hand expression. Will default to string comparisons for non-numeric values.
            Usage: left_expression < right_expresison
            e.g.: $CONFIDENCE < 0.9 -- checks if the numeric confidence attributes is less than  0.9
         
        Parameters:
        left - the left hand expression
        value - the right hand value
        Returns:
        the LyreExpression
      • lte

        public static LyreExpression lte​(@NonNull
                                         @NonNull LyreExpression left,
                                         @NonNull
                                         @NonNull LyreExpression right)
        Checks if the left-hand expression is less than or equal to the right-hand expression. Will default to string comparisons for non-numeric values.
            Usage: left_expression <= right_expresison
            e.g.: $CONFIDENCE <= 0.9 -- checks if the numeric confidence attributes is less than or equal  to 0.9
         
        Parameters:
        left - the left hand expression
        right - the right hand expression
        Returns:
        the LyreExpression
      • lte

        public static LyreExpression lte​(LyreExpression left,
                                         double value)
        Checks if the left-hand expression is less than or equal to the right-hand expression. Will default to string comparisons for non-numeric values.
            Usage: left_expression <= right_expresison
            e.g.: $CONFIDENCE <= 0.9 -- checks if the numeric confidence attributes is less than or equal  to 0.9
         
        Parameters:
        left - the left hand expression
        value - the right hand value
        Returns:
        the LyreExpression
      • map

        public static LyreExpression map​(@NonNull
                                         @NonNull LyreExpression list,
                                         @NonNull
                                         @NonNull LyreExpression operator)
        Applies the given operator to each element of the given list.
            usage: map( list_expression, operator_expression )
            e.g.: map( @TOKEN, lower ) -- applies the lower operation to each token in the current HString
                 ** Note this is the same as lower(@TOKEN)
            e.g.: map( @TOKEN, if(isDigit, '[:digit:]', $_) ) -- maps the if statement to each token in the current HString
                 ** Note that this is different from if( isDigit(@TOKEN), '[:digit:]', this)
         
        Parameters:
        list - the list of items to apply the operator to
        operator - the operator to apply
        Returns:
        the LyreExpression
      • max

        public static LyreExpression max​(@NonNull
                                         @NonNull LyreExpression list)
        Return the annotation in the list expression with maximum confidence as obtained via the CONFIDENCE attribute or null if none.
            Usage: max( list_expression )
            e.g.: max( @ENTITY ) -- return the entity annotation with the maximum confidence on this HString
         
        Parameters:
        list - the list expression
        Returns:
        the LyreExpression
      • ne

        public static LyreExpression ne​(@NonNull
                                        @NonNull LyreExpression left,
                                        @NonNull
                                        @NonNull LyreExpression right)
        Checks if the left and right expression are not equal using .equals, checking for content equality for HStrings and literals, and using Tag.isInstance(Tag) for tags.
            Usage: left_expression != right_expresison
            e.g.: $_ != 'man' -- checks if the current object is not equal to man
         
        Parameters:
        left - the left hand expression
        right - the right hand expression
        Returns:
        the LyreExpression
      • ne

        public static LyreExpression ne​(@NonNull
                                        @NonNull LyreExpression left,
                                        double value)
        Checks if the left and right expression are not equal using .equals, checking for content equality for HStrings and literals, and using Tag.isInstance(Tag) for tags.
            Usage: left_expression != right_expresison
            e.g.: $_ != 'man' -- checks if the current object is not equal to man
         
        Parameters:
        left - the left hand expression
        value - the right hand value
        Returns:
        the LyreExpression
      • negLookAhead

        public static LyreExpression negLookAhead​(@NonNull
                                                  @NonNull LyreExpression condition,
                                                  @NonNull
                                                  @NonNull LyreExpression expression)
        Determines if the next annotation does not match the given expression (Negative Lookahead).
            usage: (?!> expression)
            e.g.: (?!> #VERB) -- returns true if the next Token is NOT a verb
         
        Parameters:
        condition - the condition that must NOT be met by the next Token in order to evaluate to True
        expression - the expression
        Returns:
        the LyreExpression
      • negLookBehind

        public static LyreExpression negLookBehind​(@NonNull
                                                   @NonNull LyreExpression condition,
                                                   @NonNull
                                                   @NonNull LyreExpression expression)
        Determines if the previous annotation does not match the given expression (Negative Lookbehind).
            usage: (?!< expression)
            e.g.: (?!< #VERB) -- returns true if the previous Token is NOT a verb
         
        Parameters:
        condition - the condition that must NOT be met by the previous Token in order to evaluate to True
        expression - the expression
        Returns:
        the LyreExpression
      • none

        public static LyreExpression none​(@NonNull
                                          @NonNull LyreExpression list,
                                          @NonNull
                                          @NonNull LyreExpression predicate)
        Returns true if none of the items in the given list evaluates to *true* for the given predicate expression.
            usage: none( list_expression, predicate_expression )
            e.g.: none( @TOKEN, #VERB ) -- returns true if none of the tokens on the current HString is a verb
         
        Parameters:
        list - the list of items to apply the predicate to
        predicate - the predicate to use for testing
        Returns:
        the LyreExpression
      • not

        public static LyreExpression not​(@NonNull
                                         @NonNull LyreExpression predicate)
        Negates the given predicate expression
            Usage: !predicate_expression
            e.g.: !isDigit -- checks if the current HString is not a digit
         
        Parameters:
        predicate - the predicate expression to negate
        Returns:
        the LyreExpression
      • notNull

        public static LyreExpression notNull​(@NonNull
                                             @NonNull LyreExpression expression,
                                             @NonNull
                                             @NonNull LyreExpression defaultValue)
        Checks if the result a given expression is null or not and when it is not null returns the result and when is null returns a default value.
            Usage: nn( result_expression, default_value_expression )
            e.g.:  nn( @ENTITY, 'non-entity' ) -- returns all entities on the current HString or the string "non-entity" if
                                                  none
         
        Parameters:
        expression - the expression whose result is being examined.
        defaultValue - the default value when the expression results in a null value
        Returns:
        the LyreExpression
      • number

        public static LyreExpression number​(double number)
        Lyres accepts numerical literal values in the form of ints and doubles and allows for scientific notation.
            e.g.: 123.4
            e.g.: 1e-5
            e.g.: -123.123
         
        Parameters:
        number - the number
        Returns:
        the LyreExpression
      • or

        public static LyreExpression or​(@NonNull
                                        @NonNull LyreExpression left,
                                        @NonNull
                                        @NonNull LyreExpression right)
        Returns true when the left-hand or right-hand expressions evaluate to true
            Usage:  expresion || expresion
            e.g.: isContentWord || len > 3 -- returns true if the current HString is a content word or has 3 or more characters
         
        Parameters:
        left - the left-hand expresion to evaluate as a predicate
        right - the right-hand expresion to evaluate as a predicate
        Returns:
        the LyreExpression
      • orPipe

        public static LyreExpression orPipe​(@NonNull
                                            @NonNull LyreExpression... expressions)
        Sequentially processes each expression with the input object, returning the result of the first expression that evaluates to a non-null, non-empty list, or finite numeric value.
            Usage: expression1 |> expression2 |> ... |> expresisonN
         
        Parameters:
        expressions - The expressions to chain together.
        Returns:
        the lyre expression
      • plus

        public static LyreExpression plus​(@NonNull
                                          @NonNull LyreExpression... expressions)
        The plus operator can be used to concatenate strings, perform addition on numeric values, or append to a list.
        Parameters:
        expressions - the expressions to concatenate
        Returns:
        the LyreExpression
      • plus

        public static LyreExpression plus​(@NonNull
                                          @NonNull LyreExpression left,
                                          @NonNull
                                          @NonNull LyreExpression right)
        The plus operator can be used to concatenate strings, perform addition on numeric values, or append to a list.
        Parameters:
        left - the left expression to concatenate
        right - the right expression to concatenate
        Returns:
        the LyreExpression
      • pos

        public static LyreExpression pos​(@NonNull
                                         @NonNull LyreExpression expression)
        Gets the part-of-speech for the HString resulting from the given expression.
            Usage:  pos( expression )
            e.g.: pos( @TOKEN ) -- returns the part-of-speech for all tokens on the current HString
         
        Parameters:
        expression - the expression returning an HString whose part-of-speech we want
        Returns:
        the LyreExpression
      • regex

        public static LyreExpression regex​(@NonNull
                                           @NonNull String pattern)
        Creates a predicate expression to be applied to Strings testing them against the given regular expression pattern.
           usage: /java-regex/ig
           optional: i - case insensitive, g - match full span
           e.g.: /[aieou]/i -- match vowels in a case insensitive manner.
         
        To apply:
            $_ ~= /[aieou]/i -- returns true if the current HString has at least on vowel in a case insensitive manner.
         
        Parameters:
        pattern - the Java regular expression pattern (Note that when parsing lyre expects the form in usage statement)
        Returns:
        the LyreExpression
      • regex

        public static LyreExpression regex​(@NonNull
                                           @NonNull String pattern,
                                           boolean matchFullSpan)
        Creates a predicate expression to be applied to Strings testing them against the given regular expression pattern.
           usage: /java-regex/ig
           optional: i - case insensitive, g - match full span
           e.g.: /[aieou]/i -- match vowels in a case insensitive manner.
         
        To apply:
            $_ ~= /[aieou]/i -- returns true if the current HString has at least on vowel in a case insensitive manner.
         
        Parameters:
        pattern - the Java regular expression pattern (Note that when parsing lyre expects the form in usage statement)
        matchFullSpan - True - the regular expression must match the full HString and not just a substring of it
        Returns:
        the LyreExpression
      • rel

        public static LyreExpression rel​(@NonNull
                                         @NonNull RelationDirection direction,
                                         @NonNull
                                         @NonNull RelationType type)
        Gets the annotation(s) having the given relation type in the given direction (INCOMING or OUTGOING).
            Usage:  @>type -- annotations reachable from outgoing  given relation
            Usage:  @COREFERENCE -- return the annotation that the current token has a COREFERENCE relation with
         
        Parameters:
        direction - the direction of the relation (INCOMING or OUTGOING)
        type - the desired relation
        Returns:
        the LyreExpression
      • rel

        public static LyreExpression rel​(@NonNull
                                         @NonNull RelationDirection direction,
                                         @NonNull
                                         @NonNull RelationType type,
                                         String relation)
        Gets the annotation(s) having the the given relation type with the given relation value in the given direction (INCOMING or OUTGOING).
            Usage:  @>type{'relation'} -- annotations reachable from outgoing relation of given type and value
            Usage:  @COREFERNCE{'pronominal'} -- return the annotation having a COREFERENCE relation with value pronominal
         
        Parameters:
        direction - the direction of the relation (INCOMING or OUTGOING)
        type - the desired dependency relation
        relation - the desired relation value
        Returns:
        the LyreExpression
      • rel

        public static LyreExpression rel​(@NonNull
                                         @NonNull RelationDirection direction,
                                         @NonNull
                                         @NonNull RelationType type,
                                         @NonNull
                                         @NonNull LyreExpression expression)
        Gets the annotation(s) having the given relation type in the given direction (INCOMING or OUTGOING).
            Usage:  @>type{'relation'} -- annotations reachable from outgoing relation of given type and value
            Usage:  @COREFERNCE{'pronominal'} -- return the annotation having a COREFERENCE relation with value pronominal
         
        Parameters:
        direction - the direction of the relation (INCOMING or OUTGOING)
        type - the desired dependency relation
        expression - the expression returning the HString to extract dependency relations over
        Returns:
        the LyreExpression
      • rel

        public static LyreExpression rel​(@NonNull
                                         @NonNull RelationDirection direction,
                                         @NonNull
                                         @NonNull RelationType type,
                                         String relation,
                                         @NonNull
                                         @NonNull LyreExpression expression)
        Gets the annotation(s) having the the given relation type with the given relation value in the given direction (INCOMING or OUTGOING).
            Usage:  @>type{'relation'}(expression) -- annotations reachable from outgoing relation of given type and value
            Usage:  @COREFERNCE{'pronominal'}(@PHRASE_CHUNK) -- return the annotation that the phrase chunks on the current token
                                                               have an COREFERENCE relation with value pronominal
         
        Parameters:
        direction - the direction of the relation (INCOMING or OUTGOING)
        type - the desired dependency relation
        relation - the desired relation value
        expression - the expression returning the HString to extract dependency relations over
        Returns:
        the LyreExpression
      • rpad

        public static LyreExpression rpad​(@NonNull
                                          @NonNull LyreExpression expression,
                                          int minimumLength,
                                          char paddingCharacter)
        Pads the right-side of CharSequence with a given pad-character ensuring that length of CharSequence is at least the given minimum length.
            Usage: rpad( expression, minimum_length, padding_character )
            e.g.: rpad( $_, 5, '*' ) -- add * to the end of the current HString until the length is at least 5
                                          characters long
         
        Parameters:
        expression - the expression resulting in the string to left-pad
        minimumLength - the minimum length of the resulting padded string
        paddingCharacter - the character to use for padding
        Returns:
        the LyreExpression
      • rpad

        public static LyreExpression rpad​(@NonNull
                                          @NonNull LyreExpression expression,
                                          @NonNull
                                          @NonNull LyreExpression minimumLength,
                                          @NonNull
                                          @NonNull LyreExpression paddingCharacter)
        Pads the right-side of CharSequence with a given pad-character ensuring that length of CharSequence is at least the given minimum length.
            Usage: rpad( expression, minimum_length, padding_character )
            e.g.: rpad( $_, 5, '*' ) -- add * to the end of the current HString until the length is at least 5
                                          characters long
         
        Parameters:
        expression - the expression resulting in the string to left-pad
        minimumLength - the minimum length of the resulting padded string
        paddingCharacter - the character to use for padding
        Returns:
        the LyreExpression
      • rsub

        public static LyreExpression rsub​(@NonNull
                                          @NonNull String pattern,
                                          @NonNull
                                          @NonNull String replacement)
        Creates a regular expression substitution expression to be applied to Strings.
           usage: /java-regex/replacement/ig
           optional: i - case insensitive, g - replace all matches
           e.g.: /[aieou]/v/i -- replace all vowels with a v in a case insensitive manner.
         
        To apply:
            $_ ~= /[aieou]/v/i  -- replace all vowels with a v in the current HString in a case insensitive manner.
         
        Parameters:
        pattern - the Java regular expression pattern (Note that when parsing lyre expects the form in usage statement)
        replacement - the string to replace the matched sections with
        Returns:
        the LyreExpression
      • rsub

        public static LyreExpression rsub​(@NonNull
                                          @NonNull String pattern,
                                          @NonNull
                                          @NonNull String replacement,
                                          boolean replaceAll)
        Creates a regular expression substitution expression to be applied to Strings.
           usage: /java-regex/replacement/ig
           optional: i - case insensitive, g - replace all matches
           e.g.: /[aieou]/v/i -- replace all vowels with a v in a case insensitive manner.
         
        To apply:
            $_ ~= /[aieou]/v/i  -- replace all vowels with a v in the current HString in a case insensitive manner.
         
        Parameters:
        pattern - the Java regular expression pattern (Note that when parsing lyre expects the form in usage statement)
        replacement - the string to replace the matched sections with
        replaceAll - True - replace all matches in the HString
        Returns:
        the LyreExpression
      • slice

        public static LyreExpression slice​(@NonNull
                                           @NonNull LyreExpression expression,
                                           int start)
        Performs a slice (substring and sublist) on Strings and Collections.
            Usage: expression[start:end] -- Performs a slice from start to end on the output of the given expression
            e.g.:  'abc'[:-1] -- return the substring of 'abc' starting at 0 and going to length-1
         
        Parameters:
        expression - the expression to take substring of
        start - the start offset
        Returns:
        the LyreExpression
      • slice

        public static LyreExpression slice​(@NonNull
                                           @NonNull LyreExpression expression,
                                           int start,
                                           int end)
        Performs a slice (substring and sublist) on Strings and Collections.
            Usage: expression[start:end] -- Performs a slice from start to end on the output of the given expression
            e.g.:  'abc'[:-1] -- return the substring of 'abc' starting at 0 and going to length-1
         
        Parameters:
        expression - the expression to take substring of
        start - the start offset
        end - the end offset
        Returns:
        the LyreExpression
      • stem

        public static LyreExpression stem​(@NonNull
                                          @NonNull LyreExpression expression)
        Gets the stemmed form of the current HString resulting from the given expression.
            Usage:  stem( expression )
            e.g.: stem( @TOKEN ) -- returns the stemmed form all tokens on the current HString
         
        Parameters:
        expression - the expression returning an HString to stem
        Returns:
        the LyreExpression
      • string

        public static LyreExpression string​(@NonNull
                                            @NonNull LyreExpression expression)
        Gets the string form of the Object resulting from the given expression.
            Usage:  string( expression )
            e.g.: string( 123.5 ) -- returns the string form of the numerical literal
         
        Parameters:
        expression - the expression returning an Object to turn into a string
        Returns:
        the LyreExpression
      • tag

        public static LyreExpression tag​(@NonNull
                                         @NonNull Tag value)
        Checks if the Tag on the current HString is of the given Tag value.
            Usage: #TAG_VAlUE
            e.g.: #PERSON -- check if the tag has value PERSON
         
        Parameters:
        value - the tag value to test for
        Returns:
        the LyreExpression
      • tag

        public static LyreExpression tag​(@NonNull
                                         @NonNull String value)
        Checks if the Tag on the current HString is of the given Tag value.
            Usage: #TAG_VAlUE
            e.g.: #PERSON -- check if the tag has value PERSON
         
        Parameters:
        value - the tag value to test for
        Returns:
        the LyreExpression
      • tag

        public static LyreExpression tag​(@NonNull
                                         @NonNull Tag value,
                                         @NonNull
                                         @NonNull LyreExpression expression)
        Checks if the Tag on the HString resulting from the given expression is of the given Tag value.
            Usage: #TAG_VAlUE( expression )
            e.g.: #PERSON( @ENTITIY ) -- check if the tag of the entity on the current HString has value PERSON
         
        Parameters:
        value - the tag value to test for
        expression - the expression resulting in the HString to check the tag of
        Returns:
        the LyreExpression
      • tag

        public static LyreExpression tag​(@NonNull
                                         @NonNull String value,
                                         @NonNull
                                         @NonNull LyreExpression expression)
        Checks if the Tag on the HString resulting from the given expression is of the given Tag value.
            Usage: #TAG_VAlUE( expression )
            e.g.: #PERSON( @ENTITIY ) -- check if the tag of the entity on the current HString has value PERSON
         
        Parameters:
        value - the tag value to test for
        expression - the expression resulting in the HString to check the tag of
        Returns:
        the LyreExpression
      • tlen

        public static LyreExpression tlen​(@NonNull
                                          @NonNull LyreExpression expression)
        Returns the length of the underlying HString in Tokens
            Usage: tlen( object_expression )
            e.g.: tlen( @PHRASE_CHUNK ) -- returns the number of tokens per phrase chunk
         
        Parameters:
        expression - the expression resulting in the HString object to calculate the token length of
        Returns:
        the LyreExpression
      • trim

        public static LyreExpression trim​(@NonNull
                                          @NonNull LyreExpression expression,
                                          @NonNull
                                          @NonNull LyreExpression predicate)
        Removes tokens from the left and right of the input HString if they evaluate to true with the given predicate.
            Usage: trim( object_expression, predicate_expression )
            e.g.: trim( $_, isStopWord || len < 3 ) -- remove tokens that are stopwords or have a length less than three
                                                         from the current HString
         
        Parameters:
        expression - the expression resulting in the HString object to trim
        predicate - the predicate expression to use for trimming.
        Returns:
        the LyreExpression
      • upos

        public static LyreExpression upos​(@NonNull
                                          @NonNull LyreExpression expression)
        Gets the universal part-of-speech for the HString resulting from the given expression.
            Usage:  upos( expression )
            e.g.: upos( @TOKEN ) -- returns the universal part-of-speech for all tokens on the current HString
         
        Parameters:
        expression - the expression returning an HString whose universal part-of-speech we want
        Returns:
        the LyreExpression
      • upper

        public static LyreExpression upper​(@NonNull
                                           @NonNull LyreExpression expression)
        Gets the upper-cased string form of the current HString resulting from the given expression.
            Usage:  upper( expression )
            e.g.: upper( @TOKEN ) -- returns the upper-cased string form  all tokens on the current HString
         
        Parameters:
        expression - the expression returning an HString to upper case
        Returns:
        the LyreExpression
      • when

        public static LyreExpression when​(@NonNull
                                          @NonNull LyreExpression condition,
                                          @NonNull
                                          @NonNull LyreExpression expression)
        Performs the given expression when the given condition is true and returns null when the condition is false.
            Usage: when( condition_expresison, true_expression )
            e.g.: when( len > 3, 's3=' + $_[-3:] ) -- return the trigram suffix only when the length of the current
                                                        HString is greater than 3
         
        Parameters:
        condition - the condition expression
        expression - the expression to perform when the condition evaluates to true
        Returns:
        the LyreExpression
      • wordList

        public static LyreExpression wordList​(@NonNull
                                              @NonNull WordList wordList)
        Constructs a temporary word list to use as a predicate or as a container for checking for the existence of words and phrases.
        Parameters:
        wordList - the word list
        Returns:
        the LyreExpression
      • wordList

        public static LyreExpression wordList​(@NonNull
                                              @NonNull LyreExpression wordList)
        Constructs a temporary word list to use as a predicate or as a container for checking for the existence of words and phrases.
        Parameters:
        wordList - the word list expression
        Returns:
        the LyreExpression
      • xor

        public static LyreExpression xor​(@NonNull
                                         @NonNull LyreExpression left,
                                         @NonNull
                                         @NonNull LyreExpression right)
        Returns true when the left-hand or right-hand expressions evaluate to true but not both
            Usage:  expresion ^ expresion
            e.g.: isContentWord ^ len > 3 -- returns true if the current HString is a content word or has 3 or more characters
                                             but not both
         
        Parameters:
        left - the left-hand expresion to evaluate as a predicate
        right - the right-hand expresion to evaluate as a predicate
        Returns:
        the LyreExpression