Package org.languagetool.rules.patterns
Class XMLRuleHandler
- java.lang.Object
-
- org.xml.sax.helpers.DefaultHandler
-
- org.languagetool.rules.patterns.XMLRuleHandler
-
- All Implemented Interfaces:
org.xml.sax.ContentHandler
,org.xml.sax.DTDHandler
,org.xml.sax.EntityResolver
,org.xml.sax.ErrorHandler
- Direct Known Subclasses:
DisambiguationRuleHandler
,FalseFriendRuleHandler
,PatternRuleHandler
public class XMLRuleHandler extends org.xml.sax.helpers.DefaultHandler
XML rule handler that loads rules from XML and throws exceptions on errors and warnings.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
XMLRuleHandler.RegexpMode
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.String
AND
protected int
andGroupCounter
protected static java.lang.String
ANTIPATTERN
protected static java.lang.String
CASE_SENSITIVE
protected boolean
caseSensitive
protected ChunkTag
chunkTag
protected static java.lang.String
CHUNKTAG
protected java.lang.StringBuilder
correctExample
protected java.util.List<CorrectExample>
correctExamples
protected static java.lang.String
DEFAULT
protected java.lang.StringBuilder
elements
protected int
endPositionCorrection
protected java.util.Map<java.lang.String,java.util.List<java.lang.String>>
equivalenceFeatures
protected java.lang.StringBuilder
errorTriggerExample
protected java.util.List<ErrorTriggeringExample>
errorTriggeringExamples
protected static java.lang.String
EXAMPLE
protected java.lang.StringBuilder
exampleCorrection
protected static java.lang.String
EXCEPTION
protected java.lang.Boolean
exceptionLevelCaseSensitive
protected boolean
exceptionLevelCaseSet
protected boolean
exceptionPosNegation
protected boolean
exceptionPosRegExp
protected java.lang.String
exceptionPosToken
protected java.lang.StringBuilder
exceptions
protected boolean
exceptionSet
protected boolean
exceptionSpaceBefore
protected boolean
exceptionSpaceBeforeSet
protected boolean
exceptionStringInflected
protected boolean
exceptionStringNegation
protected boolean
exceptionStringRegExp
protected boolean
exceptionValidNext
protected boolean
exceptionValidPrev
protected static java.lang.String
FEATURE
protected java.lang.String
id
static java.lang.String
ID
protected static java.lang.String
IGNORE
protected boolean
inAndGroup
protected java.lang.StringBuilder
incorrectExample
protected boolean
inCorrectExample
protected java.util.List<IncorrectExample>
incorrectExamples
protected boolean
inErrorTriggerExample
protected boolean
inException
protected static java.lang.String
INFLECTED
protected boolean
inIncorrectExample
protected boolean
inMarker
protected boolean
inMatch
protected boolean
inMessage
protected boolean
inOrGroup
protected boolean
inPattern
protected boolean
inPhrases
protected boolean
inRegex
protected boolean
inRuleGroup
protected boolean
inShortMessage
protected boolean
inShortMessageForRuleGroup
protected boolean
inSuggestion
protected boolean
inToken
protected boolean
inUnification
protected boolean
inUnificationDef
protected boolean
inUnificationNeutral
protected boolean
inUrl
protected boolean
inUrlForRuleGroup
protected Language
language
protected boolean
lastPhrase
true when phraseref is the last element in the rule.protected static java.lang.String
MARK
protected static java.lang.String
MARKER
protected java.lang.StringBuilder
match
protected static java.lang.String
MATCH
protected static java.lang.String
MAX
protected int
maxOccurrence
protected java.lang.StringBuilder
message
protected static java.lang.String
MESSAGE
protected static java.lang.String
MIN
protected int
minOccurrence
static java.lang.String
NAME
protected static java.lang.String
NEGATE
protected static java.lang.String
NEGATE_POS
protected static java.lang.String
NO
protected static java.lang.String
OFF
protected static java.lang.String
ON
protected static java.lang.String
OR
protected int
orGroupCounter
protected static java.lang.String
PATTERN
protected PatternToken
patternToken
protected java.util.List<PatternToken>
patternTokens
List of elements as specified by tokens.protected java.lang.String
phraseId
Current phrase ID.protected java.lang.String
phraseIdRef
ID reference to the phrase.protected java.util.Map<java.lang.String,java.util.List<java.util.List<PatternToken>>>
phraseMap
Phrase store - elementLists keyed by phraseIds.protected java.util.List<java.util.ArrayList<PatternToken>>
phrasePatternTokens
Logically forking element list, used for including multiple phrases in the current one.protected static java.lang.String
PHRASES
protected org.xml.sax.Locator
pLocator
protected boolean
posNegation
protected boolean
posRegExp
protected static java.lang.String
POSTAG
protected static java.lang.String
POSTAG_REGEXP
protected java.lang.String
posToken
protected java.lang.StringBuilder
regex
protected boolean
regexCaseSensitive
protected XMLRuleHandler.RegexpMode
regexMode
protected static java.lang.String
REGEXP
protected int
regexpMark
protected boolean
regExpression
protected static java.lang.String
RULE
protected static java.lang.String
RULEGROUP
protected java.lang.String
ruleGroupId
protected java.util.List<AbstractPatternRule>
rules
protected static java.lang.String
RULES
protected static java.lang.String
SCOPE
protected java.lang.StringBuilder
shortMessage
protected java.lang.StringBuilder
shortMessageForRuleGroup
protected static java.lang.String
SKIP
protected int
skipPos
protected static java.lang.String
SPACEBEFORE
protected int
startPositionCorrection
protected static java.lang.String
SUGGESTION
protected java.util.List<Match>
suggestionMatches
protected java.util.List<Match>
suggestionMatchesOutMsg
protected java.lang.StringBuilder
suggestionsOutMsg
protected static java.lang.String
TABNAME
protected static java.lang.String
TEMP_OFF
protected static java.lang.String
TOKEN
protected int
tokenCounter
protected boolean
tokenInflected
protected boolean
tokenLevelCaseSensitive
protected boolean
tokenLevelCaseSet
protected boolean
tokenNegated
protected Match
tokenReference
protected boolean
tokenSpaceBefore
protected boolean
tokenSpaceBeforeSet
protected static java.lang.String
TYPE
protected java.lang.String
uFeature
protected static java.lang.String
UNIFICATION
protected static java.lang.String
UNIFY
protected static java.lang.String
UNIFY_IGNORE
protected boolean
uniNegation
protected java.lang.StringBuilder
url
protected java.lang.StringBuilder
urlForRuleGroup
protected java.lang.String
uType
protected java.util.List<java.lang.String>
uTypeList
protected static java.lang.String
YES
Definitions of values in XML files.
-
Constructor Summary
Constructors Constructor Description XMLRuleHandler()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected @Nullable java.util.List<Match>
addLegacyMatches(java.util.List<Match> existingSugMatches, java.lang.String messageStr, boolean inMessage)
Adds Match objects for all references to tokens (including '\1' and the like).private void
checkNumber(org.xml.sax.Attributes attrs)
private void
checkRefNumber(int refNumber)
void
error(org.xml.sax.SAXParseException e)
protected void
finalizeExceptions()
protected void
finalizePhrase()
protected void
finalizeTokens()
java.util.List<AbstractPatternRule>
getRules()
protected void
preparePhrase(org.xml.sax.Attributes attrs)
protected void
processElement(java.util.List<PatternToken> patternTokens)
Calculates the offset of the match reference (if any) in case the match element has been used in the group.protected void
resetException()
protected void
resetToken()
void
setDocumentLocator(org.xml.sax.Locator locator)
protected void
setExceptions(org.xml.sax.Attributes attrs)
protected void
setMatchElement(org.xml.sax.Attributes attrs)
protected void
setRuleFilter(java.lang.String filterClassName, java.lang.String filterArgs, AbstractPatternRule rule)
protected void
setToken(org.xml.sax.Attributes attrs)
protected void
startPattern(org.xml.sax.Attributes attrs)
void
warning(org.xml.sax.SAXParseException e)
-
-
-
Field Detail
-
ID
public static final java.lang.String ID
- See Also:
- Constant Field Values
-
NAME
public static final java.lang.String NAME
- See Also:
- Constant Field Values
-
YES
protected static final java.lang.String YES
Definitions of values in XML files.- See Also:
- Constant Field Values
-
OFF
protected static final java.lang.String OFF
- See Also:
- Constant Field Values
-
TEMP_OFF
protected static final java.lang.String TEMP_OFF
- See Also:
- Constant Field Values
-
ON
protected static final java.lang.String ON
- See Also:
- Constant Field Values
-
POSTAG
protected static final java.lang.String POSTAG
- See Also:
- Constant Field Values
-
CHUNKTAG
protected static final java.lang.String CHUNKTAG
- See Also:
- Constant Field Values
-
POSTAG_REGEXP
protected static final java.lang.String POSTAG_REGEXP
- See Also:
- Constant Field Values
-
REGEXP
protected static final java.lang.String REGEXP
- See Also:
- Constant Field Values
-
NEGATE
protected static final java.lang.String NEGATE
- See Also:
- Constant Field Values
-
INFLECTED
protected static final java.lang.String INFLECTED
- See Also:
- Constant Field Values
-
NEGATE_POS
protected static final java.lang.String NEGATE_POS
- See Also:
- Constant Field Values
-
MARKER
protected static final java.lang.String MARKER
- See Also:
- Constant Field Values
-
DEFAULT
protected static final java.lang.String DEFAULT
- See Also:
- Constant Field Values
-
TYPE
protected static final java.lang.String TYPE
- See Also:
- Constant Field Values
-
SPACEBEFORE
protected static final java.lang.String SPACEBEFORE
- See Also:
- Constant Field Values
-
EXAMPLE
protected static final java.lang.String EXAMPLE
- See Also:
- Constant Field Values
-
SCOPE
protected static final java.lang.String SCOPE
- See Also:
- Constant Field Values
-
IGNORE
protected static final java.lang.String IGNORE
- See Also:
- Constant Field Values
-
SKIP
protected static final java.lang.String SKIP
- See Also:
- Constant Field Values
-
MIN
protected static final java.lang.String MIN
- See Also:
- Constant Field Values
-
MAX
protected static final java.lang.String MAX
- See Also:
- Constant Field Values
-
TOKEN
protected static final java.lang.String TOKEN
- See Also:
- Constant Field Values
-
FEATURE
protected static final java.lang.String FEATURE
- See Also:
- Constant Field Values
-
UNIFY
protected static final java.lang.String UNIFY
- See Also:
- Constant Field Values
-
UNIFY_IGNORE
protected static final java.lang.String UNIFY_IGNORE
- See Also:
- Constant Field Values
-
AND
protected static final java.lang.String AND
- See Also:
- Constant Field Values
-
OR
protected static final java.lang.String OR
- See Also:
- Constant Field Values
-
EXCEPTION
protected static final java.lang.String EXCEPTION
- See Also:
- Constant Field Values
-
CASE_SENSITIVE
protected static final java.lang.String CASE_SENSITIVE
- See Also:
- Constant Field Values
-
MARK
protected static final java.lang.String MARK
- See Also:
- Constant Field Values
-
PATTERN
protected static final java.lang.String PATTERN
- See Also:
- Constant Field Values
-
ANTIPATTERN
protected static final java.lang.String ANTIPATTERN
- See Also:
- Constant Field Values
-
MATCH
protected static final java.lang.String MATCH
- See Also:
- Constant Field Values
-
UNIFICATION
protected static final java.lang.String UNIFICATION
- See Also:
- Constant Field Values
-
RULE
protected static final java.lang.String RULE
- See Also:
- Constant Field Values
-
RULES
protected static final java.lang.String RULES
- See Also:
- Constant Field Values
-
RULEGROUP
protected static final java.lang.String RULEGROUP
- See Also:
- Constant Field Values
-
NO
protected static final java.lang.String NO
- See Also:
- Constant Field Values
-
PHRASES
protected static final java.lang.String PHRASES
- See Also:
- Constant Field Values
-
MESSAGE
protected static final java.lang.String MESSAGE
- See Also:
- Constant Field Values
-
SUGGESTION
protected static final java.lang.String SUGGESTION
- See Also:
- Constant Field Values
-
TABNAME
protected static final java.lang.String TABNAME
- See Also:
- Constant Field Values
-
rules
protected java.util.List<AbstractPatternRule> rules
-
language
protected Language language
-
correctExample
protected java.lang.StringBuilder correctExample
-
incorrectExample
protected java.lang.StringBuilder incorrectExample
-
errorTriggerExample
protected java.lang.StringBuilder errorTriggerExample
-
exampleCorrection
protected java.lang.StringBuilder exampleCorrection
-
message
protected java.lang.StringBuilder message
-
suggestionsOutMsg
protected java.lang.StringBuilder suggestionsOutMsg
-
match
protected java.lang.StringBuilder match
-
elements
protected java.lang.StringBuilder elements
-
exceptions
protected java.lang.StringBuilder exceptions
-
correctExamples
protected java.util.List<CorrectExample> correctExamples
-
incorrectExamples
protected java.util.List<IncorrectExample> incorrectExamples
-
errorTriggeringExamples
protected java.util.List<ErrorTriggeringExample> errorTriggeringExamples
-
inPattern
protected boolean inPattern
-
inCorrectExample
protected boolean inCorrectExample
-
inIncorrectExample
protected boolean inIncorrectExample
-
inErrorTriggerExample
protected boolean inErrorTriggerExample
-
inMessage
protected boolean inMessage
-
inSuggestion
protected boolean inSuggestion
-
inMatch
protected boolean inMatch
-
inRuleGroup
protected boolean inRuleGroup
-
inToken
protected boolean inToken
-
inException
protected boolean inException
-
inPhrases
protected boolean inPhrases
-
inAndGroup
protected boolean inAndGroup
-
inOrGroup
protected boolean inOrGroup
-
tokenSpaceBefore
protected boolean tokenSpaceBefore
-
tokenSpaceBeforeSet
protected boolean tokenSpaceBeforeSet
-
posToken
protected java.lang.String posToken
-
chunkTag
protected ChunkTag chunkTag
-
posNegation
protected boolean posNegation
-
posRegExp
protected boolean posRegExp
-
caseSensitive
protected boolean caseSensitive
-
regExpression
protected boolean regExpression
-
tokenNegated
protected boolean tokenNegated
-
tokenInflected
protected boolean tokenInflected
-
tokenLevelCaseSensitive
protected boolean tokenLevelCaseSensitive
-
tokenLevelCaseSet
protected boolean tokenLevelCaseSet
-
exceptionPosToken
protected java.lang.String exceptionPosToken
-
exceptionStringRegExp
protected boolean exceptionStringRegExp
-
exceptionStringNegation
protected boolean exceptionStringNegation
-
exceptionStringInflected
protected boolean exceptionStringInflected
-
exceptionPosNegation
protected boolean exceptionPosNegation
-
exceptionPosRegExp
protected boolean exceptionPosRegExp
-
exceptionValidNext
protected boolean exceptionValidNext
-
exceptionValidPrev
protected boolean exceptionValidPrev
-
exceptionSet
protected boolean exceptionSet
-
exceptionSpaceBefore
protected boolean exceptionSpaceBefore
-
exceptionSpaceBeforeSet
protected boolean exceptionSpaceBeforeSet
-
exceptionLevelCaseSensitive
protected java.lang.Boolean exceptionLevelCaseSensitive
-
exceptionLevelCaseSet
protected boolean exceptionLevelCaseSet
-
patternTokens
protected java.util.List<PatternToken> patternTokens
List of elements as specified by tokens.
-
lastPhrase
protected boolean lastPhrase
true when phraseref is the last element in the rule.
-
phraseIdRef
protected java.lang.String phraseIdRef
ID reference to the phrase.
-
phraseId
protected java.lang.String phraseId
Current phrase ID.
-
skipPos
protected int skipPos
-
minOccurrence
protected int minOccurrence
-
maxOccurrence
protected int maxOccurrence
-
ruleGroupId
protected java.lang.String ruleGroupId
-
id
protected java.lang.String id
-
patternToken
protected PatternToken patternToken
-
tokenReference
protected Match tokenReference
-
suggestionMatches
protected java.util.List<Match> suggestionMatches
-
suggestionMatchesOutMsg
protected java.util.List<Match> suggestionMatchesOutMsg
-
pLocator
protected org.xml.sax.Locator pLocator
-
startPositionCorrection
protected int startPositionCorrection
-
endPositionCorrection
protected int endPositionCorrection
-
tokenCounter
protected int tokenCounter
-
phraseMap
protected java.util.Map<java.lang.String,java.util.List<java.util.List<PatternToken>>> phraseMap
Phrase store - elementLists keyed by phraseIds.
-
phrasePatternTokens
protected java.util.List<java.util.ArrayList<PatternToken>> phrasePatternTokens
Logically forking element list, used for including multiple phrases in the current one.
-
andGroupCounter
protected int andGroupCounter
-
orGroupCounter
protected int orGroupCounter
-
inUrl
protected boolean inUrl
-
inUrlForRuleGroup
protected boolean inUrlForRuleGroup
-
url
protected java.lang.StringBuilder url
-
urlForRuleGroup
protected java.lang.StringBuilder urlForRuleGroup
-
inRegex
protected boolean inRegex
-
regex
protected java.lang.StringBuilder regex
-
regexMode
protected XMLRuleHandler.RegexpMode regexMode
-
regexCaseSensitive
protected boolean regexCaseSensitive
-
regexpMark
protected int regexpMark
-
inShortMessage
protected boolean inShortMessage
-
inShortMessageForRuleGroup
protected boolean inShortMessageForRuleGroup
-
shortMessage
protected java.lang.StringBuilder shortMessage
-
shortMessageForRuleGroup
protected java.lang.StringBuilder shortMessageForRuleGroup
-
inUnification
protected boolean inUnification
-
inMarker
protected boolean inMarker
-
inUnificationDef
protected boolean inUnificationDef
-
uniNegation
protected boolean uniNegation
-
inUnificationNeutral
protected boolean inUnificationNeutral
-
uFeature
protected java.lang.String uFeature
-
uType
protected java.lang.String uType
-
uTypeList
protected java.util.List<java.lang.String> uTypeList
-
equivalenceFeatures
protected java.util.Map<java.lang.String,java.util.List<java.lang.String>> equivalenceFeatures
-
-
Method Detail
-
getRules
public java.util.List<AbstractPatternRule> getRules()
-
warning
public void warning(org.xml.sax.SAXParseException e) throws org.xml.sax.SAXException
- Specified by:
warning
in interfaceorg.xml.sax.ErrorHandler
- Overrides:
warning
in classorg.xml.sax.helpers.DefaultHandler
- Throws:
org.xml.sax.SAXException
-
error
public void error(org.xml.sax.SAXParseException e) throws org.xml.sax.SAXException
- Specified by:
error
in interfaceorg.xml.sax.ErrorHandler
- Overrides:
error
in classorg.xml.sax.helpers.DefaultHandler
- Throws:
org.xml.sax.SAXException
-
setDocumentLocator
public void setDocumentLocator(org.xml.sax.Locator locator)
- Specified by:
setDocumentLocator
in interfaceorg.xml.sax.ContentHandler
- Overrides:
setDocumentLocator
in classorg.xml.sax.helpers.DefaultHandler
-
resetToken
protected void resetToken()
-
resetException
protected void resetException()
-
preparePhrase
protected void preparePhrase(org.xml.sax.Attributes attrs)
-
finalizePhrase
protected void finalizePhrase()
-
startPattern
protected void startPattern(org.xml.sax.Attributes attrs) throws org.xml.sax.SAXException
- Throws:
org.xml.sax.SAXException
-
processElement
protected void processElement(java.util.List<PatternToken> patternTokens)
Calculates the offset of the match reference (if any) in case the match element has been used in the group.- Parameters:
patternTokens
- token list where the match element was used. It is directly changed.
-
setMatchElement
protected void setMatchElement(org.xml.sax.Attributes attrs) throws org.xml.sax.SAXException
- Throws:
org.xml.sax.SAXException
-
checkNumber
private void checkNumber(org.xml.sax.Attributes attrs) throws org.xml.sax.SAXException
- Throws:
org.xml.sax.SAXException
-
checkRefNumber
private void checkRefNumber(int refNumber) throws org.xml.sax.SAXException
- Throws:
org.xml.sax.SAXException
-
setExceptions
protected void setExceptions(org.xml.sax.Attributes attrs)
-
finalizeExceptions
protected void finalizeExceptions()
-
setToken
protected void setToken(org.xml.sax.Attributes attrs)
-
addLegacyMatches
@Nullable protected @Nullable java.util.List<Match> addLegacyMatches(java.util.List<Match> existingSugMatches, java.lang.String messageStr, boolean inMessage)
Adds Match objects for all references to tokens (including '\1' and the like).
-
finalizeTokens
protected void finalizeTokens() throws org.xml.sax.SAXException
- Throws:
org.xml.sax.SAXException
-
setRuleFilter
protected void setRuleFilter(java.lang.String filterClassName, java.lang.String filterArgs, AbstractPatternRule rule)
-
-