use of org.languagetool.rules.bitext.IncorrectBitextExample in project languagetool by languagetool-org.
the class BitextPatternRuleHandler method endElement.
@Override
public void endElement(String namespaceURI, String sName, String qName) throws SAXException {
switch(qName) {
case RULE:
trgRule.setMessage(message.toString());
for (Match m : suggestionMatches) {
trgRule.addSuggestionMatch(m);
}
if (phrasePatternTokens.size() <= 1) {
suggestionMatches.clear();
}
BitextPatternRule bRule = new BitextPatternRule(srcRule, trgRule);
bRule.setCorrectBitextExamples(correctExamples);
bRule.setIncorrectBitextExamples(incorrectExamples);
bRule.setSourceLanguage(srcLang);
rules.add(bRule);
break;
case SRC_EXAMPLE:
srcExample = setExample();
break;
case TRG_EXAMPLE:
trgExample = setExample();
break;
case SOURCE:
srcRule = finalizeRule();
break;
case TARGET:
trgRule = finalizeRule();
break;
case EXAMPLE:
if (inCorrectExample) {
correctExamples.add(new StringPair(srcExample.getExample(), trgExample.getExample()));
} else if (inIncorrectExample) {
StringPair examplePair = new StringPair(srcExample.getExample(), trgExample.getExample());
if (trgExample.getCorrections().isEmpty()) {
incorrectExamples.add(new IncorrectBitextExample(examplePair));
} else {
List<String> corrections = trgExample.getCorrections();
incorrectExamples.add(new IncorrectBitextExample(examplePair, corrections));
}
}
inCorrectExample = false;
inIncorrectExample = false;
inErrorTriggerExample = false;
break;
default:
super.endElement(namespaceURI, sName, qName);
break;
}
}
Aggregations