Class StringMatcher

  • All Implemented Interfaces:
    AdditionalInformationHandler, CleanUpHandler, Destroyable, GlobalInfoSupporter, LoggingLevelHandler, LoggingSupporter, OptionHandler, QuickInfoSupporter, ShallowCopySupporter<Actor>, SizeOfHandler, Stoppable, StoppableWithFeedback, VariablesInspectionHandler, VariableChangeListener, Actor, ErrorHandler, InputConsumer, OutputProducer, Serializable, Comparable

    public class StringMatcher
    extends AbstractStringOperation
    Lets string tokens only pass if they match the regular expression. Matching sense can be inverted as well.
    Special characters like \n \r \t and \ need to be escaped properly. The input is expected to be escaped, i.e., the string "\t" will get turned into the character '\t'.
    Instead of outputting the strings, it is also possible to output the 1-based indices.

    Input/output:
    - accepts:
       java.lang.String
       java.lang.String[]
    - generates:
       java.lang.String
       java.lang.String[]


    -logging-level <OFF|SEVERE|WARNING|INFO|CONFIG|FINE|FINER|FINEST> (property: loggingLevel)
        The logging level for outputting errors and debugging output.
        default: WARNING
     
    -name <java.lang.String> (property: name)
        The name of the actor.
        default: StringMatcher
     
    -annotation <adams.core.base.BaseAnnotation> (property: annotations)
        The annotations to attach to this actor.
        default:
     
    -skip <boolean> (property: skip)
        If set to true, transformation is skipped and the input token is just forwarded
        as it is.
        default: false
     
    -stop-flow-on-error <boolean> (property: stopFlowOnError)
        If set to true, the flow execution at this level gets stopped in case this
        actor encounters an error; the error gets propagated; useful for critical
        actors.
        default: false
     
    -silent <boolean> (property: silent)
        If enabled, then no errors are output in the console; Note: the enclosing
        actor handler must have this enabled as well.
        default: false
     
    -regexp <adams.core.base.BaseRegExp> (property: regExp)
        The regular expression used for matching the strings.
        default: .*
        more: https://docs.oracle.com/javase/tutorial/essential/regex/
        https://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html
     
    -invert <boolean> (property: invert)
        If set to true, then the matching sense is inverted.
        default: false
     
    -output-indices <boolean> (property: outputIndices)
        If set to true, 1-based indices of matches are output instead of strings.
        default: false
     
    Author:
    fracpete (fracpete at waikato dot ac dot nz)
    See Also:
    Serialized Form
    • Field Detail

      • m_RegExp

        protected BaseRegExp m_RegExp
        the regular expression to match.
      • m_Invert

        protected boolean m_Invert
        whether to invert the matching sense.
      • m_OutputIndices

        protected boolean m_OutputIndices
        whether to output indices instead of the strings.
    • Constructor Detail

      • StringMatcher

        public StringMatcher()
    • Method Detail

      • setRegExp

        public void setRegExp​(BaseRegExp value)
        Sets the regular expression to match the strings against.
        Parameters:
        value - the regular expression
      • getRegExp

        public BaseRegExp getRegExp()
        Returns the regular expression to match the strings against.
        Returns:
        the regular expression
      • regExpTipText

        public String regExpTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setInvert

        public void setInvert​(boolean value)
        Sets whether to invert the matching sense.
        Parameters:
        value - true if inverting matching sense
      • getInvert

        public boolean getInvert()
        Returns whether to invert the matching sense.
        Returns:
        true if matching sense is inverted
      • invertTipText

        public String invertTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setOutputIndices

        public void setOutputIndices​(boolean value)
        Sets whether to output 1-based indices of matches instead of the strings.
        Parameters:
        value - true if to output indices
      • getOutputIndices

        public boolean getOutputIndices()
        Returns whether to output 1-based indices of matches instead of the strings.
        Returns:
        true if to output indices
      • outputIndicesTipText

        public String outputIndicesTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • process

        protected String process​(String s,
                                 int index)
        Processes the string. If null is returned, this output will be ignored.
        Specified by:
        process in class AbstractStringOperation
        Parameters:
        s - the string to process
        index - the 0-based index of the string currently being processed
        Returns:
        the processed string or null if nothing produced