Package net.loomchild.segment.srx
Class RuleManager
- java.lang.Object
-
- net.loomchild.segment.srx.RuleManager
-
public class RuleManager extends java.lang.Object
Represents segmentation rules manager. Responsible for constructing and storing break and exception rules.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<Rule>
breakRuleList
private SrxDocument
document
private java.util.Map<Rule,java.util.regex.Pattern>
exceptionPatternMap
private int
maxLookbehindConstructLength
-
Constructor Summary
Constructors Constructor Description RuleManager(SrxDocument document, java.util.List<LanguageRule> languageRuleList, int maxLookbehindConstructLength)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private java.lang.String
createExceptionPatternString(Rule rule)
Creates exception pattern string that can be matched in the place where break rule was matched.java.util.List<Rule>
getBreakRuleList()
java.util.regex.Pattern
getExceptionPattern(Rule breakRule)
-
-
-
Field Detail
-
document
private SrxDocument document
-
maxLookbehindConstructLength
private int maxLookbehindConstructLength
-
breakRuleList
private java.util.List<Rule> breakRuleList
-
exceptionPatternMap
private java.util.Map<Rule,java.util.regex.Pattern> exceptionPatternMap
-
-
Constructor Detail
-
RuleManager
public RuleManager(SrxDocument document, java.util.List<LanguageRule> languageRuleList, int maxLookbehindConstructLength)
Constructor. Responsible for retrieving rules from SRX document for given language code, constructing patterns and storing them in quick accessible format. Adds break rules tobreakRuleList
and constructs corresponding exception patterns inexceptionPatternMap
. Uses document cache to store rules and patterns.- Parameters:
document
- SRX documentlanguageRuleList
- list of language rulesmaxLookbehindConstructLength
- Maximum length of regular expression in lookbehind (seeUtil.finitize(String, int)
).
-
-
Method Detail
-
getBreakRuleList
public java.util.List<Rule> getBreakRuleList()
- Returns:
- break rule list
-
getExceptionPattern
public java.util.regex.Pattern getExceptionPattern(Rule breakRule)
- Parameters:
breakRule
-- Returns:
- exception pattern corresponding to give break rule
-
createExceptionPatternString
private java.lang.String createExceptionPatternString(Rule rule)
Creates exception pattern string that can be matched in the place where break rule was matched. Both parts of the rule (beforePattern and afterPattern) are incorporated into one pattern. beforePattern is used in lookbehind, therefore it needs to be modified so it matches finite string (contains no *, + or {n,}).- Parameters:
rule
- exception rule- Returns:
- string containing exception pattern
-
-