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.DefaultHandlerXML 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 classXMLRuleHandler.RegexpMode
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.StringANDprotected intandGroupCounterprotected static java.lang.StringANTIPATTERNprotected static java.lang.StringCASE_SENSITIVEprotected booleancaseSensitiveprotected ChunkTagchunkTagprotected static java.lang.StringCHUNKTAGprotected java.lang.StringBuildercorrectExampleprotected java.util.List<CorrectExample>correctExamplesprotected static java.lang.StringDEFAULTprotected java.lang.StringBuilderelementsprotected intendPositionCorrectionprotected java.util.Map<java.lang.String,java.util.List<java.lang.String>>equivalenceFeaturesprotected java.lang.StringBuildererrorTriggerExampleprotected java.util.List<ErrorTriggeringExample>errorTriggeringExamplesprotected static java.lang.StringEXAMPLEprotected java.lang.StringBuilderexampleCorrectionprotected static java.lang.StringEXCEPTIONprotected java.lang.BooleanexceptionLevelCaseSensitiveprotected booleanexceptionLevelCaseSetprotected booleanexceptionPosNegationprotected booleanexceptionPosRegExpprotected java.lang.StringexceptionPosTokenprotected java.lang.StringBuilderexceptionsprotected booleanexceptionSetprotected booleanexceptionSpaceBeforeprotected booleanexceptionSpaceBeforeSetprotected booleanexceptionStringInflectedprotected booleanexceptionStringNegationprotected booleanexceptionStringRegExpprotected booleanexceptionValidNextprotected booleanexceptionValidPrevprotected static java.lang.StringFEATUREprotected java.lang.Stringidstatic java.lang.StringIDprotected static java.lang.StringIGNOREprotected booleaninAndGroupprotected java.lang.StringBuilderincorrectExampleprotected booleaninCorrectExampleprotected java.util.List<IncorrectExample>incorrectExamplesprotected booleaninErrorTriggerExampleprotected booleaninExceptionprotected static java.lang.StringINFLECTEDprotected booleaninIncorrectExampleprotected booleaninMarkerprotected booleaninMatchprotected booleaninMessageprotected booleaninOrGroupprotected booleaninPatternprotected booleaninPhrasesprotected booleaninRegexprotected booleaninRuleGroupprotected booleaninShortMessageprotected booleaninShortMessageForRuleGroupprotected booleaninSuggestionprotected booleaninTokenprotected booleaninUnificationprotected booleaninUnificationDefprotected booleaninUnificationNeutralprotected booleaninUrlprotected booleaninUrlForRuleGroupprotected Languagelanguageprotected booleanlastPhrasetrue when phraseref is the last element in the rule.protected static java.lang.StringMARKprotected static java.lang.StringMARKERprotected java.lang.StringBuildermatchprotected static java.lang.StringMATCHprotected static java.lang.StringMAXprotected intmaxOccurrenceprotected java.lang.StringBuildermessageprotected static java.lang.StringMESSAGEprotected static java.lang.StringMINprotected intminOccurrencestatic java.lang.StringNAMEprotected static java.lang.StringNEGATEprotected static java.lang.StringNEGATE_POSprotected static java.lang.StringNOprotected static java.lang.StringOFFprotected static java.lang.StringONprotected static java.lang.StringORprotected intorGroupCounterprotected static java.lang.StringPATTERNprotected PatternTokenpatternTokenprotected java.util.List<PatternToken>patternTokensList of elements as specified by tokens.protected java.lang.StringphraseIdCurrent phrase ID.protected java.lang.StringphraseIdRefID reference to the phrase.protected java.util.Map<java.lang.String,java.util.List<java.util.List<PatternToken>>>phraseMapPhrase store - elementLists keyed by phraseIds.protected java.util.List<java.util.ArrayList<PatternToken>>phrasePatternTokensLogically forking element list, used for including multiple phrases in the current one.protected static java.lang.StringPHRASESprotected org.xml.sax.LocatorpLocatorprotected booleanposNegationprotected booleanposRegExpprotected static java.lang.StringPOSTAGprotected static java.lang.StringPOSTAG_REGEXPprotected java.lang.StringposTokenprotected java.lang.StringBuilderregexprotected booleanregexCaseSensitiveprotected XMLRuleHandler.RegexpModeregexModeprotected static java.lang.StringREGEXPprotected intregexpMarkprotected booleanregExpressionprotected static java.lang.StringRULEprotected static java.lang.StringRULEGROUPprotected java.lang.StringruleGroupIdprotected java.util.List<AbstractPatternRule>rulesprotected static java.lang.StringRULESprotected static java.lang.StringSCOPEprotected java.lang.StringBuildershortMessageprotected java.lang.StringBuildershortMessageForRuleGroupprotected static java.lang.StringSKIPprotected intskipPosprotected static java.lang.StringSPACEBEFOREprotected intstartPositionCorrectionprotected static java.lang.StringSUGGESTIONprotected java.util.List<Match>suggestionMatchesprotected java.util.List<Match>suggestionMatchesOutMsgprotected java.lang.StringBuildersuggestionsOutMsgprotected static java.lang.StringTABNAMEprotected static java.lang.StringTEMP_OFFprotected static java.lang.StringTOKENprotected inttokenCounterprotected booleantokenInflectedprotected booleantokenLevelCaseSensitiveprotected booleantokenLevelCaseSetprotected booleantokenNegatedprotected MatchtokenReferenceprotected booleantokenSpaceBeforeprotected booleantokenSpaceBeforeSetprotected static java.lang.StringTYPEprotected java.lang.StringuFeatureprotected static java.lang.StringUNIFICATIONprotected static java.lang.StringUNIFYprotected static java.lang.StringUNIFY_IGNOREprotected booleanuniNegationprotected java.lang.StringBuilderurlprotected java.lang.StringBuilderurlForRuleGroupprotected java.lang.StringuTypeprotected java.util.List<java.lang.String>uTypeListprotected static java.lang.StringYESDefinitions 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 voidcheckNumber(org.xml.sax.Attributes attrs)private voidcheckRefNumber(int refNumber)voiderror(org.xml.sax.SAXParseException e)protected voidfinalizeExceptions()protected voidfinalizePhrase()protected voidfinalizeTokens()java.util.List<AbstractPatternRule>getRules()protected voidpreparePhrase(org.xml.sax.Attributes attrs)protected voidprocessElement(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 voidresetException()protected voidresetToken()voidsetDocumentLocator(org.xml.sax.Locator locator)protected voidsetExceptions(org.xml.sax.Attributes attrs)protected voidsetMatchElement(org.xml.sax.Attributes attrs)protected voidsetRuleFilter(java.lang.String filterClassName, java.lang.String filterArgs, AbstractPatternRule rule)protected voidsetToken(org.xml.sax.Attributes attrs)protected voidstartPattern(org.xml.sax.Attributes attrs)voidwarning(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:
warningin interfaceorg.xml.sax.ErrorHandler- Overrides:
warningin 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:
errorin interfaceorg.xml.sax.ErrorHandler- Overrides:
errorin classorg.xml.sax.helpers.DefaultHandler- Throws:
org.xml.sax.SAXException
-
setDocumentLocator
public void setDocumentLocator(org.xml.sax.Locator locator)
- Specified by:
setDocumentLocatorin interfaceorg.xml.sax.ContentHandler- Overrides:
setDocumentLocatorin 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)
-
-