Class RegexNERecogniser

  • All Implemented Interfaces:

    public class RegexNERecogniser
    extends java.lang.Object
    implements NERecogniser
    This class offers an implementation of NERecogniser based on Regular Expressions.

    The default configuration file "ner-regex.txt" is used when no argument constructor is used to instantiate this class. The regex file is loaded via Class.getResourceAsStream(String), so the file should be placed in the same package path as of this class.

    The format of regex configuration as follows:
    For example, to extract week day from text:
    Nov. 7, 2015
    • Field Detail

      • entityTypes

        public java.util.Set<java.lang.String> entityTypes
      • patterns

        public java.util.Map<java.lang.String,​java.util.regex.Pattern> patterns
    • Constructor Detail

      • RegexNERecogniser

        public RegexNERecogniser()
      • RegexNERecogniser

        public RegexNERecogniser​( stream)
    • Method Detail

      • isAvailable

        public boolean isAvailable()
        Description copied from interface: NERecogniser
        checks if this Named Entity recogniser is available for service
        Specified by:
        isAvailable in interface NERecogniser
        true if this recogniser is ready to recognise, false otherwise
      • getEntityTypes

        public java.util.Set<java.lang.String> getEntityTypes()
        Description copied from interface: NERecogniser
        gets a set of entity types whose names are recognisable by this
        Specified by:
        getEntityTypes in interface NERecogniser
        set of entity types/classes
      • findMatches

        public java.util.Set<java.lang.String> findMatches​(java.lang.String text,
                                                           java.util.regex.Pattern pattern)
        finds matching sub groups in text
        text - text containing interesting sub strings
        pattern - pattern to find sub strings
        set of sub strings if any found, or null if none found
      • recognise

        public java.util.Map<java.lang.String,​java.util.Set<java.lang.String>> recognise​(java.lang.String text)
        Description copied from interface: NERecogniser
        call for name recognition action from text
        Specified by:
        recognise in interface NERecogniser
        text - text with possibly contains names
        map of entityType -> set of names