public class IrregularMappingRule extends AbstractRegexReplacementRule
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.
Modifier and Type | Field and Description |
---|---|
protected java.util.Map<java.lang.String,java.lang.String> |
mappings |
pattern
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.
|
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.
|
applies, apply, disjunction, disjunction
public IrregularMappingRule(java.util.Map<java.lang.String,java.lang.String> wordMappings, java.lang.String regex)
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.public java.lang.String replace(java.util.regex.Matcher m)
AbstractRegexReplacementRule
Matcher
to perform a replacement.replace
in class AbstractRegexReplacementRule
m
- The matcher used to match the word.public static java.util.Map<java.lang.String,java.lang.String> toMap(java.lang.String[][] wordMappings)
wordMappings
- Two-dimensional array of strings.
First entry is singular form,
second entry is plural form.