Package opennlp.tools.namefind

## Class RegexNameFinder

- java.lang.Object
- - opennlp.tools.namefind.RegexNameFinder

- All Implemented Interfaces:
    `TokenNameFinder`

      public final class RegexNameFinder
      extends Object
      implements TokenNameFinder

  A `TokenNameFinder` implementation based on a series of regular expressions.

- - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `RegexNameFinder​(Map<String,​Pattern[]> regexMap)` | Initializes a `RegexNameFinder` instance.
    `RegexNameFinder​(Pattern[] patterns)` | Deprecated. Use constructor `RegexNameFinder(Pattern[], String)` for single types, and/or constructor `RegexNameFinder(Map)` instead.
    `RegexNameFinder​(Pattern[] patterns, String type)` | Initializes a `RegexNameFinder` instance.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `clearAdaptiveData()` | Forgets all adaptive data which was collected during previous calls to one of the find methods.
    `Span[]` | `find​(String text)` | Finds `spans` with character indices, rather than word.
    `Span[]` | `find​(String[] tokens)` | Generates name tags for the given sequence, typically a sentence, returning `token spans` for any identified names.
    `Pattern[]` | `getMatchingPatterns()` |
    `String` | `getSpanType()` |
    `void` | `setMatchingPatterns​(Pattern[] mPatterns)` |
    `void` | `setSpanType​(String sType)` |

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### RegexNameFinder

          public RegexNameFinder​(Map<String,​Pattern[]> regexMap)

      Initializes a `RegexNameFinder` instance.
      Parameters:
        `regexMap` - A `Map` where the key is a type, and the value is a `Pattern`. Must not be `null`.

    - #### RegexNameFinder

          public RegexNameFinder​(Pattern[] patterns,
                                 String type)

      Initializes a `RegexNameFinder` instance.
      Parameters:
        `patterns` - The `patterns` to use. Must not be `null` and not be empty.
        `type` - The type to use.
      Throws:
        `IllegalArgumentException` - Thrown if `patterns` were `null` or empty.

    - #### RegexNameFinder

          @Deprecated
          public RegexNameFinder​(Pattern[] patterns)

      Deprecated.
      Use constructor `RegexNameFinder(Pattern[], String)` for single types, and/or constructor `RegexNameFinder(Map)` instead.
      Initializes a `RegexNameFinder` instance.
      Parameters:
        `patterns` - The `patterns` to use. Must not be `null` and not be empty.
      Throws:
        `IllegalArgumentException` - Thrown if `patterns` were `null` or empty.

  - ### Method Detail

    - #### find

          public Span[] find​(String[] tokens)

      Description copied from interface: `TokenNameFinder`
      Generates name tags for the given sequence, typically a sentence, returning `token spans` for any identified names.
      Specified by:
        `find` in interface `TokenNameFinder`
      Parameters:
        `tokens` - An array of the tokens or words of the sequence, typically a sentence.
      Returns:
        An array of `spans` for each of the names identified.

    - #### find

          public Span[] find​(String text)

      Finds `spans` with character indices, rather than word.
      Parameters:
        `text` - The text to use.
      Returns:
        A `Span` representing the annotations.

    - #### clearAdaptiveData

          public void clearAdaptiveData()

      Description copied from interface: `TokenNameFinder`
      Forgets all adaptive data which was collected during previous calls to one of the find methods.

      Note: This method should typically be called at the end of the processing of a document.

      Specified by:
        `clearAdaptiveData` in interface `TokenNameFinder`

    - #### getMatchingPatterns

          public Pattern[] getMatchingPatterns()

      Returns:
        Retrieves the `matching patterns` used.

    - #### setMatchingPatterns

          public void setMatchingPatterns​(Pattern[] mPatterns)

      Parameters:
        `mPatterns` - The `matching patterns` to be set.

    - #### getSpanType

          public String getSpanType()

      Returns:
        Retrieves the `Span` type used.

    - #### setSpanType

          public void setSpanType​(String sType)

      Parameters:
        `sType` - Sets a (different) `Span` type.