edu.northwestern.at.morphadorner.corpuslinguistics.inflector.wordrule

## Class IrregularMappingRule

- java.lang.Object
- - edu.northwestern.at.morphadorner.corpuslinguistics.inflector.wordrule.AbstractRegexReplacementRule
  - - edu.northwestern.at.morphadorner.corpuslinguistics.inflector.wordrule.IrregularMappingRule

- All Implemented Interfaces:
    WordRule

      public class IrregularMappingRule
      extends AbstractRegexReplacementRule

  A rule for specifying an irregular inflection using a combination of a map of singular to plural forms and a regular expression replacement.

  Subclasses can implement `replace(java.util.regex.Matcher)` to perform the actual replacement, which by default uses the map to substitute a plural form for the corresponding singular form found in group 0 of the regular expression match.

  Original code written by Tom White under the Apache v2 license. Modified by Philip R. Burns for integration into MorphAdorner.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected java.util.Map<java.lang.String,java.lang.String>` | `mappings`

    - ### Fields inherited from class edu.northwestern.at.morphadorner.corpuslinguistics.inflector.wordrule.AbstractRegexReplacementRule

      `pattern`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `IrregularMappingRule(java.util.Map<java.lang.String,java.lang.String> wordMappings, java.lang.String regex)` Construct a rule using a regular expression and irregular forms map.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `java.lang.String` | `replace(java.util.regex.Matcher m)` Use the state in the given `Matcher` to perform a replacement.
    `static java.util.Map<java.lang.String,java.lang.String>` | `toMap(java.lang.String[][] wordMappings)` Convert an array of String array mapping pairs into a map.

    - ### Methods inherited from class edu.northwestern.at.morphadorner.corpuslinguistics.inflector.wordrule.AbstractRegexReplacementRule

      `applies, apply, disjunction, disjunction`

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

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

- - ### Field Detail

    - #### mappings

          protected final java.util.Map<java.lang.String,java.lang.String> mappings

  - ### Constructor Detail

    - #### IrregularMappingRule

          public IrregularMappingRule(java.util.Map<java.lang.String,java.lang.String> wordMappings,
                              java.lang.String regex)

      Construct a rule using a regular expression and irregular forms map.
      Parameters:
        `wordMappings` - The map of singular to plural forms.
        `regex` - The regular expression used to match words. Match information is available to subclasses in the `replace(java.util.regex.Matcher)` method.

  - ### Method Detail

    - #### replace

          public java.lang.String replace(java.util.regex.Matcher m)

      Description copied from class: `AbstractRegexReplacementRule`
      Use the state in the given `Matcher` to perform a replacement.
      Specified by:
        `replace` in class `AbstractRegexReplacementRule`
      Parameters:
        `m` - The matcher used to match the word.
      Returns:
        The transformed word.

    - #### toMap

          public static java.util.Map<java.lang.String,java.lang.String> toMap(java.lang.String[][] wordMappings)

      Convert an array of String array mapping pairs into a map.
      Parameters:
        `wordMappings` - Two-dimensional array of strings. First entry is singular form, second entry is plural form.
      Returns:
        A map of singular to plural forms.