Search in sources :

Example 1 with DisambiguationRuleLoader

use of org.languagetool.tagging.disambiguation.rules.DisambiguationRuleLoader in project languagetool by languagetool-org.

the class TestFrenchDisambiguator method disambiguate.

@Override
public AnalyzedSentence disambiguate(AnalyzedSentence input) throws IOException {
    AnalyzedSentence sentence = input;
    String filePath = "/disambiguator.xml";
    try (InputStream inputStream = getClass().getResourceAsStream(filePath)) {
        final DisambiguationRuleLoader ruleLoader = new DisambiguationRuleLoader();
        List<DisambiguationPatternRule> disambiguationRules = ruleLoader.getRules(inputStream);
        for (final DisambiguationPatternRule patternRule : disambiguationRules) {
            sentence = patternRule.replace(sentence);
        }
    } catch (Exception e) {
        throw new RuntimeException("Problems with loading disambiguation file: " + filePath, e);
    }
    return sentence;
}
Also used : AnalyzedSentence(org.languagetool.AnalyzedSentence) InputStream(java.io.InputStream) DisambiguationPatternRule(org.languagetool.tagging.disambiguation.rules.DisambiguationPatternRule) DisambiguationRuleLoader(org.languagetool.tagging.disambiguation.rules.DisambiguationRuleLoader) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 AnalyzedSentence (org.languagetool.AnalyzedSentence)1 DisambiguationPatternRule (org.languagetool.tagging.disambiguation.rules.DisambiguationPatternRule)1 DisambiguationRuleLoader (org.languagetool.tagging.disambiguation.rules.DisambiguationRuleLoader)1