Package org.languagetool.rules.patterns
Class XMLRuleHandler
- java.lang.Object
-
- org.xml.sax.helpers.DefaultHandler
-
- org.languagetool.rules.patterns.XMLRuleHandler
-
- All Implemented Interfaces:
ContentHandler
,DTDHandler
,EntityResolver
,ErrorHandler
- Direct Known Subclasses:
PatternRuleHandler
public class XMLRuleHandler extends DefaultHandler
XML rule handler that loads rules from XML and throws exceptions on errors and warnings.- Author:
- Daniel Naber
-
-
Field Summary
Fields Modifier and Type Field Description protected static String
AND
protected int
andGroupCounter
protected static String
ANTIPATTERN
protected static String
CASE_SENSITIVE
protected boolean
caseSensitive
protected ChunkTag
chunkTag
protected static String
CHUNKTAG
protected StringBuilder
correctExample
protected List<CorrectExample>
correctExamples
protected static String
DEFAULT
protected StringBuilder
elements
protected int
endPositionCorrection
protected Map<String,List<String>>
equivalenceFeatures
protected StringBuilder
errorTriggerExample
protected List<ErrorTriggeringExample>
errorTriggeringExamples
protected static String
EXAMPLE
protected StringBuilder
exampleCorrection
protected static String
EXCEPTION
protected Boolean
exceptionLevelCaseSensitive
protected boolean
exceptionLevelCaseSet
protected boolean
exceptionPosNegation
protected boolean
exceptionPosRegExp
protected String
exceptionPosToken
protected 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 String
FEATURE
protected String
id
static String
ID
protected static String
IGNORE
protected boolean
inAndGroup
protected StringBuilder
incorrectExample
protected boolean
inCorrectExample
protected List<IncorrectExample>
incorrectExamples
protected boolean
inErrorTriggerExample
protected boolean
inException
protected static 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 String
MARK
protected static String
MARKER
protected StringBuilder
match
protected static String
MATCH
protected static String
MAX
protected int
maxOccurrence
protected StringBuilder
message
protected static String
MESSAGE
protected static String
MIN
protected int
minOccurrence
static String
NAME
protected static String
NEGATE
protected static String
NEGATE_POS
protected static String
NO
protected static String
OFF
protected static String
ON
protected static String
OR
protected int
orGroupCounter
protected static String
PATTERN
protected PatternToken
patternToken
protected List<PatternToken>
patternTokens
List of elements as specified by tokens.protected String
phraseId
Current phrase ID.protected String
phraseIdRef
ID reference to the phrase.protected Map<String,List<List<PatternToken>>>
phraseMap
Phrase store - elementLists keyed by phraseIds.protected List<ArrayList<PatternToken>>
phrasePatternTokens
Logically forking element list, used for including multiple phrases in the current one.protected static String
PHRASES
protected Locator
pLocator
protected boolean
posNegation
protected boolean
posRegExp
protected static String
POSTAG
protected static String
POSTAG_REGEXP
protected String
posToken
protected StringBuilder
regex
protected boolean
regexCaseSensitive
protected org.languagetool.rules.patterns.XMLRuleHandler.RegexpMode
regexMode
protected static String
REGEXP
protected int
regexpMark
protected boolean
regExpression
protected static String
RULE
protected static String
RULEGROUP
protected String
ruleGroupId
protected List<AbstractPatternRule>
rules
protected static String
RULES
protected static String
SCOPE
protected StringBuilder
shortMessage
protected StringBuilder
shortMessageForRuleGroup
protected static String
SKIP
protected int
skipPos
protected static String
SPACEBEFORE
protected int
startPositionCorrection
protected static String
SUGGESTION
protected List<Match>
suggestionMatches
protected List<Match>
suggestionMatchesOutMsg
protected StringBuilder
suggestionsOutMsg
protected static String
TABNAME
protected static String
TEMP_OFF
protected static 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 String
TYPE
protected String
uFeature
protected static String
UNIFICATION
protected static String
UNIFY
protected static String
UNIFY_IGNORE
protected boolean
uniNegation
protected StringBuilder
url
protected StringBuilder
urlForRuleGroup
protected String
uType
protected List<String>
uTypeList
protected static 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 List<Match>
addLegacyMatches(List<Match> existingSugMatches, String messageStr, boolean inMessage)
Adds Match objects for all references to tokens (including '\1' and the like).void
error(SAXParseException e)
protected void
finalizeExceptions()
protected void
finalizePhrase()
protected void
finalizeTokens()
List<AbstractPatternRule>
getRules()
protected void
preparePhrase(Attributes attrs)
protected void
processElement(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(Locator locator)
protected void
setExceptions(Attributes attrs)
protected void
setMatchElement(Attributes attrs)
protected void
setRuleFilter(String filterClassName, String filterArgs, AbstractPatternRule rule)
protected void
setToken(Attributes attrs)
protected void
startPattern(Attributes attrs)
void
warning(SAXParseException e)
-
Methods inherited from class org.xml.sax.helpers.DefaultHandler
characters, endDocument, endElement, endPrefixMapping, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, skippedEntity, startDocument, startElement, startPrefixMapping, unparsedEntityDecl
-
-
-
-
Field Detail
-
ID
public static final String ID
- See Also:
- Constant Field Values
-
NAME
public static final String NAME
- See Also:
- Constant Field Values
-
YES
protected static final String YES
Definitions of values in XML files.- See Also:
- Constant Field Values
-
OFF
protected static final String OFF
- See Also:
- Constant Field Values
-
TEMP_OFF
protected static final String TEMP_OFF
- See Also:
- Constant Field Values
-
ON
protected static final String ON
- See Also:
- Constant Field Values
-
POSTAG
protected static final String POSTAG
- See Also:
- Constant Field Values
-
CHUNKTAG
protected static final String CHUNKTAG
- See Also:
- Constant Field Values
-
POSTAG_REGEXP
protected static final String POSTAG_REGEXP
- See Also:
- Constant Field Values
-
REGEXP
protected static final String REGEXP
- See Also:
- Constant Field Values
-
NEGATE
protected static final String NEGATE
- See Also:
- Constant Field Values
-
INFLECTED
protected static final String INFLECTED
- See Also:
- Constant Field Values
-
NEGATE_POS
protected static final String NEGATE_POS
- See Also:
- Constant Field Values
-
MARKER
protected static final String MARKER
- See Also:
- Constant Field Values
-
DEFAULT
protected static final String DEFAULT
- See Also:
- Constant Field Values
-
TYPE
protected static final String TYPE
- See Also:
- Constant Field Values
-
SPACEBEFORE
protected static final String SPACEBEFORE
- See Also:
- Constant Field Values
-
EXAMPLE
protected static final String EXAMPLE
- See Also:
- Constant Field Values
-
SCOPE
protected static final String SCOPE
- See Also:
- Constant Field Values
-
IGNORE
protected static final String IGNORE
- See Also:
- Constant Field Values
-
SKIP
protected static final String SKIP
- See Also:
- Constant Field Values
-
MIN
protected static final String MIN
- See Also:
- Constant Field Values
-
MAX
protected static final String MAX
- See Also:
- Constant Field Values
-
TOKEN
protected static final String TOKEN
- See Also:
- Constant Field Values
-
FEATURE
protected static final String FEATURE
- See Also:
- Constant Field Values
-
UNIFY
protected static final String UNIFY
- See Also:
- Constant Field Values
-
UNIFY_IGNORE
protected static final String UNIFY_IGNORE
- See Also:
- Constant Field Values
-
AND
protected static final String AND
- See Also:
- Constant Field Values
-
OR
protected static final String OR
- See Also:
- Constant Field Values
-
EXCEPTION
protected static final String EXCEPTION
- See Also:
- Constant Field Values
-
CASE_SENSITIVE
protected static final String CASE_SENSITIVE
- See Also:
- Constant Field Values
-
MARK
protected static final String MARK
- See Also:
- Constant Field Values
-
PATTERN
protected static final String PATTERN
- See Also:
- Constant Field Values
-
ANTIPATTERN
protected static final String ANTIPATTERN
- See Also:
- Constant Field Values
-
MATCH
protected static final String MATCH
- See Also:
- Constant Field Values
-
UNIFICATION
protected static final String UNIFICATION
- See Also:
- Constant Field Values
-
RULE
protected static final String RULE
- See Also:
- Constant Field Values
-
RULES
protected static final String RULES
- See Also:
- Constant Field Values
-
RULEGROUP
protected static final String RULEGROUP
- See Also:
- Constant Field Values
-
NO
protected static final String NO
- See Also:
- Constant Field Values
-
PHRASES
protected static final String PHRASES
- See Also:
- Constant Field Values
-
MESSAGE
protected static final String MESSAGE
- See Also:
- Constant Field Values
-
SUGGESTION
protected static final String SUGGESTION
- See Also:
- Constant Field Values
-
TABNAME
protected static final String TABNAME
- See Also:
- Constant Field Values
-
rules
protected List<AbstractPatternRule> rules
-
language
protected Language language
-
correctExample
protected StringBuilder correctExample
-
incorrectExample
protected StringBuilder incorrectExample
-
errorTriggerExample
protected StringBuilder errorTriggerExample
-
exampleCorrection
protected StringBuilder exampleCorrection
-
message
protected StringBuilder message
-
suggestionsOutMsg
protected StringBuilder suggestionsOutMsg
-
match
protected StringBuilder match
-
elements
protected StringBuilder elements
-
exceptions
protected StringBuilder exceptions
-
correctExamples
protected List<CorrectExample> correctExamples
-
incorrectExamples
protected List<IncorrectExample> incorrectExamples
-
errorTriggeringExamples
protected 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 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 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 Boolean exceptionLevelCaseSensitive
-
exceptionLevelCaseSet
protected boolean exceptionLevelCaseSet
-
patternTokens
protected 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 String phraseIdRef
ID reference to the phrase.
-
phraseId
protected String phraseId
Current phrase ID.
-
skipPos
protected int skipPos
-
minOccurrence
protected int minOccurrence
-
maxOccurrence
protected int maxOccurrence
-
ruleGroupId
protected String ruleGroupId
-
id
protected String id
-
patternToken
protected PatternToken patternToken
-
tokenReference
protected Match tokenReference
-
pLocator
protected Locator pLocator
-
startPositionCorrection
protected int startPositionCorrection
-
endPositionCorrection
protected int endPositionCorrection
-
tokenCounter
protected int tokenCounter
-
phraseMap
protected Map<String,List<List<PatternToken>>> phraseMap
Phrase store - elementLists keyed by phraseIds.
-
phrasePatternTokens
protected List<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 StringBuilder url
-
urlForRuleGroup
protected StringBuilder urlForRuleGroup
-
inRegex
protected boolean inRegex
-
regex
protected StringBuilder regex
-
regexMode
protected org.languagetool.rules.patterns.XMLRuleHandler.RegexpMode regexMode
-
regexCaseSensitive
protected boolean regexCaseSensitive
-
regexpMark
protected int regexpMark
-
inShortMessage
protected boolean inShortMessage
-
inShortMessageForRuleGroup
protected boolean inShortMessageForRuleGroup
-
shortMessage
protected StringBuilder shortMessage
-
shortMessageForRuleGroup
protected StringBuilder shortMessageForRuleGroup
-
inUnification
protected boolean inUnification
-
inMarker
protected boolean inMarker
-
inUnificationDef
protected boolean inUnificationDef
-
uniNegation
protected boolean uniNegation
-
inUnificationNeutral
protected boolean inUnificationNeutral
-
uFeature
protected String uFeature
-
uType
protected String uType
-
-
Method Detail
-
getRules
public List<AbstractPatternRule> getRules()
-
warning
public void warning(SAXParseException e) throws SAXException
- Specified by:
warning
in interfaceErrorHandler
- Overrides:
warning
in classDefaultHandler
- Throws:
SAXException
-
error
public void error(SAXParseException e) throws SAXException
- Specified by:
error
in interfaceErrorHandler
- Overrides:
error
in classDefaultHandler
- Throws:
SAXException
-
setDocumentLocator
public void setDocumentLocator(Locator locator)
- Specified by:
setDocumentLocator
in interfaceContentHandler
- Overrides:
setDocumentLocator
in classDefaultHandler
-
resetToken
protected void resetToken()
-
resetException
protected void resetException()
-
preparePhrase
protected void preparePhrase(Attributes attrs)
-
finalizePhrase
protected void finalizePhrase()
-
startPattern
protected void startPattern(Attributes attrs) throws SAXException
- Throws:
SAXException
-
processElement
protected void processElement(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(Attributes attrs) throws SAXException
- Throws:
SAXException
-
setExceptions
protected void setExceptions(Attributes attrs)
-
finalizeExceptions
protected void finalizeExceptions()
-
setToken
protected void setToken(Attributes attrs)
-
addLegacyMatches
@Nullable protected @Nullable List<Match> addLegacyMatches(List<Match> existingSugMatches, String messageStr, boolean inMessage)
Adds Match objects for all references to tokens (including '\1' and the like).
-
finalizeTokens
protected void finalizeTokens() throws SAXException
- Throws:
SAXException
-
setRuleFilter
protected void setRuleFilter(String filterClassName, String filterArgs, AbstractPatternRule rule)
-
-