in languagetool-core/src/main/java/org/languagetool/tagging/disambiguation/rules/DisambiguationRuleHandler.java [110:278]
public void startElement(String namespaceURI, String lName,
String qName, Attributes attrs) throws SAXException {
switch (qName) {
case RULE:
inRule = true;
id = attrs.getValue(ID);
if (inRuleGroup) {
subId++;
}
name = attrs.getValue(NAME);
if (inRuleGroup && id == null) {
id = ruleGroupId;
}
if (inRuleGroup && name == null) {
name = ruleGroupName;
}
break;
case "rules":
if (language == null) {
language = Languages.getLanguageForShortCode(attrs.getValue("lang"));
}
break;
case PATTERN:
inPattern = true;
tokenCountForMarker = 0;
if (attrs.getValue(CASE_SENSITIVE) != null && YES.equals(attrs.getValue(CASE_SENSITIVE))) {
caseSensitive = true;
}
break;
case ANTIPATTERN:
inAntiPattern = true;
antiPatternCounter++;
caseSensitive = YES.equals(attrs.getValue(CASE_SENSITIVE));
tokenCounter = 0;
tokenCountForMarker = 0;
break;
case EXCEPTION:
setExceptions(attrs);
break;
case AND:
inAndGroup = true;
tokenCountForMarker++;
if (inUnification) {
uniCounter++;
}
break;
case UNIFY:
inUnification = true;
uniNegation = YES.equals(attrs.getValue(NEGATE));
uniCounter = 0;
break;
case UNIFY_IGNORE:
inUnificationNeutral = true;
break;
case "feature":
uFeature = attrs.getValue(ID);
break;
case TYPE:
uType = attrs.getValue(ID);
uTypeList.add(uType);
break;
case TOKEN:
setToken(attrs);
if (!inAndGroup) {
tokenCountForMarker++;
}
break;
case DISAMBIG:
inDisambiguation = true;
disambiguatedPOS = attrs.getValue(POSTAG);
if (attrs.getValue(ACTION) == null) {
// default mode:
disambigAction = DisambiguationPatternRule.DisambiguatorAction.REPLACE;
} else {
disambigAction = DisambiguationPatternRule.DisambiguatorAction
.valueOf(attrs.getValue(ACTION).toUpperCase(Locale.ENGLISH));
}
disamb = new StringBuilder();
break;
case MATCH:
inMatch = true;
match = new StringBuilder();
Match.CaseConversion caseConversion = Match.CaseConversion.NONE;
if (attrs.getValue("case_conversion") != null) {
caseConversion = Match.CaseConversion.valueOf(attrs
.getValue("case_conversion").toUpperCase(Locale.ENGLISH));
}
Match.IncludeRange includeRange = Match.IncludeRange.NONE;
if (attrs.getValue("include_skipped") != null) {
includeRange = Match.IncludeRange.valueOf(attrs
.getValue("include_skipped").toUpperCase(Locale.ENGLISH));
}
Match mWorker = new Match(attrs.getValue(POSTAG), attrs
.getValue("postag_replace"), YES
.equals(attrs.getValue(POSTAG_REGEXP)), attrs
.getValue("regexp_match"), attrs.getValue("regexp_replace"),
caseConversion, YES.equals(attrs.getValue("setpos")),
YES.equals(attrs.getValue("suppress_mispelled")),
includeRange);
if (inDisambiguation) {
if (attrs.getValue(NO) != null) {
int refNumber = Integer.parseInt(attrs.getValue(NO));
refNumberSanityCheck(refNumber);
mWorker.setTokenRef(refNumber);
posSelector = mWorker;
}
} else if (inToken && attrs.getValue(NO) != null) {
int refNumber = Integer.parseInt(attrs.getValue(NO));
refNumberSanityCheck(refNumber);
mWorker.setTokenRef(refNumber);
tokenReference = mWorker;
elements.append('\\');
elements.append(refNumber);
}
break;
case RULEGROUP:
ruleGroupId = attrs.getValue(ID);
ruleGroupName = attrs.getValue(NAME);
inRuleGroup = true;
subId = 0;
if (rulegroupAntiPatterns != null) {
rulegroupAntiPatterns.clear();
}
antiPatternCounter = 0;
break;
case UNIFICATION:
uFeature = attrs.getValue(FEATURE);
inUnificationDef = true;
break;
case "equivalence":
uType = attrs.getValue(TYPE);
break;
case WD:
wdLemma = attrs.getValue("lemma");
wdPos = attrs.getValue("pos");
inWord = true;
wd = new StringBuilder();
break;
case EXAMPLE:
inExample = true;
if (untouchedExamples == null) {
untouchedExamples = new ArrayList<>();
}
if (disambExamples == null) {
disambExamples = new ArrayList<>();
}
untouched = attrs.getValue(TYPE).equals("untouched");
if (attrs.getValue(TYPE).equals("ambiguous")) {
input = attrs.getValue("inputform");
output = attrs.getValue("outputform");
}
example = new StringBuilder();
break;
case "filter":
filterClassName = attrs.getValue("class");
filterArgs = attrs.getValue("args");
break;
case MARKER:
if (inMarker) {
throw new IllegalStateException("'<marker>' may not be nested in rule '" + id + "'");
}
example.append("<marker>");
if (inPattern || inAntiPattern) {
startPos = tokenCounter;
inMarker = true;
}
break;
}
}