Class Rule
java.lang.Object
org.apache.commons.codec.language.bm.Rule
A phoneme rule.
 
Rules have a pattern, left context, right context, output phoneme, set of languages for which they apply and a logical flag indicating if all languages must be in play. A rule matches if:
- the pattern matches at the current position
- the string up until the beginning of the pattern matches the left context
- the string from the end of the pattern matches the right context
- logical is ALL and all languages are in scope; or
- logical is any other value and at least one language is in scope
Rules are typically generated by parsing rules resources. In normal use, there will be no need for the user to explicitly construct their own.
Rules are immutable and thread-safe.
Rules resources
Rules are typically loaded from resource files. These are UTF-8 encoded text files. They are systematically named following the pattern:
/org/apache/commons/codec/language/bm/${NameType#getName}_${RuleType#getName}_${language}.txt
The format of these resources is the following:
- Rules: whitespace separated, double-quoted strings. There should be 4 columns to each row, and these
 will be interpreted as:
 - pattern
- left context
- right context
- phoneme
 
- End-of-line comments: Any occurrence of '//' will cause all text following on that line to be discarded as a comment.
- Multi-line comments: Any line starting with '/*' will start multi-line commenting mode. This will skip all content until a line ending in '*' and '/' is found.
- Blank lines: All blank lines will be skipped.
- Since:
- 1.6
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic final classA phoneme.static interfaceA phoneme expression.static final classA list of phonemes.static interfaceA minimal wrapper around the functionality of Pattern that we use, to allow for alternate implementations.
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final StringUnused.static final Rule.RPatternAlways matches.
- 
Constructor SummaryConstructorsConstructorDescriptionRule(String pattern, String lContext, String rContext, Rule.PhonemeExpr phoneme) Creates a new rule.
- 
Method SummaryModifier and TypeMethodDescriptiongetInstance(NameType nameType, RuleType rt, String lang) Gets rules for a combination of name type, rule type and a single language.getInstance(NameType nameType, RuleType rt, Languages.LanguageSet langs) Gets rules for a combination of name type, rule type and languages.getInstanceMap(NameType nameType, RuleType rt, String lang) Gets rules for a combination of name type, rule type and a single language.getInstanceMap(NameType nameType, RuleType rt, Languages.LanguageSet langs) Gets rules for a combination of name type, rule type and languages.Gets the left context.Gets the pattern.Gets the phoneme.Gets the right context.booleanpatternAndContextMatches(CharSequence input, int i) Decides if the pattern and context match the input starting at a position.
- 
Field Details- 
ALL_STRINGS_RMATCHERAlways matches.
- 
ALLUnused.- See Also:
 
 
- 
- 
Constructor Details- 
RuleCreates a new rule.- Parameters:
- pattern- the pattern
- lContext- the left context
- rContext- the right context
- phoneme- the resulting phoneme
 
 
- 
- 
Method Details- 
getInstanceGets rules for a combination of name type, rule type and languages.- Parameters:
- nameType- the NameType to consider
- rt- the RuleType to consider
- langs- the set of languages to consider
- Returns:
- a list of Rules that apply
 
- 
getInstanceGets rules for a combination of name type, rule type and a single language.- Parameters:
- nameType- the NameType to consider
- rt- the RuleType to consider
- lang- the language to consider
- Returns:
- a list of Rules that apply
 
- 
getInstanceMappublic static Map<String,List<Rule>> getInstanceMap(NameType nameType, RuleType rt, Languages.LanguageSet langs) Gets rules for a combination of name type, rule type and languages.- Parameters:
- nameType- the NameType to consider
- rt- the RuleType to consider
- langs- the set of languages to consider
- Returns:
- a map containing all Rules that apply, grouped by the first character of the rule pattern
- Since:
- 1.9
 
- 
getInstanceMapGets rules for a combination of name type, rule type and a single language.- Parameters:
- nameType- the NameType to consider
- rt- the RuleType to consider
- lang- the language to consider
- Returns:
- a map containing all Rules that apply, grouped by the first character of the rule pattern
- Since:
- 1.9
 
- 
getLContextGets the left context. This is a regular expression that must match to the left of the pattern.- Returns:
- the left context Pattern
 
- 
getPatternGets the pattern. This is a string-literal that must exactly match.- Returns:
- the pattern
 
- 
getPhonemeGets the phoneme. If the rule matches, this is the phoneme associated with the pattern match.- Returns:
- the phoneme
 
- 
getRContextGets the right context. This is a regular expression that must match to the right of the pattern.- Returns:
- the right context Pattern
 
- 
patternAndContextMatchesDecides if the pattern and context match the input starting at a position. It is a match if thelContextmatchesinputup toi,patternmatches at i andrContextmatches from the end of the match ofpatternto the end ofinput.- Parameters:
- input- the input String
- i- the int position within the input
- Returns:
- true if the pattern and left/right context match, false otherwise
 
 
-