public abstract class AbstractRegexReplacementRule extends java.lang.Object implements WordRule
Subclasses must implement replace(java.util.regex.Matcher)
to perform the actual
replacement.
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.regex.Pattern |
pattern |
Constructor and Description |
---|
AbstractRegexReplacementRule(java.lang.String regex)
Construct a rule using the given regular expression.
|
Modifier and Type | Method and Description |
---|---|
boolean |
applies(java.lang.String word)
Tests to see if this rule applies for the given word.
|
java.lang.String |
apply(java.lang.String word)
Applies this rule to the word, and transforming it into a new form.
|
static java.lang.String |
disjunction(java.util.Set<java.lang.String> patterns)
Form the disjunction of the given regular expression patterns.
|
static java.lang.String |
disjunction(java.lang.String[] patterns)
Form the disjunction of the given regular expression patterns.
|
abstract java.lang.String |
replace(java.util.regex.Matcher matcher)
Use the state in the given
Matcher to perform a replacement. |
public AbstractRegexReplacementRule(java.lang.String regex)
regex
- The regular expression used to match words.
Match information is available to subclasses in the
replace(java.util.regex.Matcher)
method.public boolean applies(java.lang.String word)
public java.lang.String apply(java.lang.String word)
public static java.lang.String disjunction(java.lang.String[] patterns)
patterns
- An array of regular expression patterns.For example, if "patterns" contains "a" and "b", then the disjunction is "(a|b)", that is, "a or b".
public static java.lang.String disjunction(java.util.Set<java.lang.String> patterns)
patterns
- A set of regular expression patterns.For example, if "patterns" contains "a" and "b", then the disjunction is "(a|b)", that is, "a or b".
public abstract java.lang.String replace(java.util.regex.Matcher matcher)
Matcher
to perform a replacement.matcher
- The matcher used to match the word.