Search in sources :

Example 11 with RuleMatch

use of org.languagetool.rules.RuleMatch in project languagetool by languagetool-org.

the class AtDXmlSerializer method ruleMatchesToXml.

public String ruleMatchesToXml(List<RuleMatch> matches, String text) {
    StringBuilder sb = new StringBuilder();
    sb.append("<results>\n");
    sb.append("<!-- THIS MODE HAS BEEN DEPRECATED - PLEASE USE THE STANDARD JSON MODE -->\n");
    sb.append("<!-- Server: LanguageTool " + JLanguageTool.VERSION + " (").append(JLanguageTool.BUILD_DATE).append(") -->\n");
    for (RuleMatch match : matches) {
        addRuleMatch(sb, match, text);
    }
    sb.append("</results>\n");
    return sb.toString();
}
Also used : RuleMatch(org.languagetool.rules.RuleMatch)

Example 12 with RuleMatch

use of org.languagetool.rules.RuleMatch in project languagetool by languagetool-org.

the class SimpleReplaceRuleTest method testRule.

@Test
public void testRule() throws IOException {
    SimpleReplaceRule rule = new SimpleReplaceRule(TestTools.getEnglishMessages());
    RuleMatch[] matches;
    JLanguageTool langTool = new JLanguageTool(new Ukrainian());
    // correct sentences:
    matches = rule.match(langTool.getAnalyzedSentence("Ці рядки повинні збігатися."));
    assertEquals(0, matches.length);
    // incorrect sentences:
    matches = rule.match(langTool.getAnalyzedSentence("Ці рядки повинні співпадати."));
    assertEquals(1, matches.length);
    assertEquals(2, matches[0].getSuggestedReplacements().size());
    assertEquals(Arrays.asList("збігатися", "сходитися"), matches[0].getSuggestedReplacements());
    matches = rule.match(langTool.getAnalyzedSentence("Нападаючий"));
    assertEquals(1, matches.length);
    assertEquals(Arrays.asList("Нападник", "Нападальний", "Нападний"), matches[0].getSuggestedReplacements());
    matches = rule.match(langTool.getAnalyzedSentence("Нападаючого"));
    assertEquals(1, matches.length);
    assertEquals(Arrays.asList("Нападник", "Нападальний", "Нападний"), matches[0].getSuggestedReplacements());
    // test ignoreTagged
    matches = rule.match(langTool.getAnalyzedSentence("щедрота"));
    assertEquals(1, matches.length);
    assertEquals(Arrays.asList("щедрість", "гойність", "щедриня"), matches[0].getSuggestedReplacements());
    matches = rule.match(langTool.getAnalyzedSentence("щедроти"));
    assertEquals(0, matches.length);
}
Also used : Ukrainian(org.languagetool.language.Ukrainian) RuleMatch(org.languagetool.rules.RuleMatch) JLanguageTool(org.languagetool.JLanguageTool) Test(org.junit.Test)

Example 13 with RuleMatch

use of org.languagetool.rules.RuleMatch in project languagetool by languagetool-org.

the class SimpleReplaceSoftRuleTest method testRule.

@Test
public void testRule() throws IOException {
    SimpleReplaceSoftRule rule = new SimpleReplaceSoftRule(TestTools.getEnglishMessages());
    RuleMatch[] matches;
    JLanguageTool langTool = new JLanguageTool(new Ukrainian());
    // correct sentences:
    matches = rule.match(langTool.getAnalyzedSentence("Ці рядки повинні збігатися."));
    assertEquals(0, matches.length);
    matches = rule.match(langTool.getAnalyzedSentence("Цей брелок."));
    assertEquals(1, matches.length);
    assertEquals(Arrays.asList("дармовис"), matches[0].getSuggestedReplacements());
    matches = rule.match(langTool.getAnalyzedSentence("Не знайде спасіння."));
    assertEquals(1, matches.length);
    assertEquals(Arrays.asList("рятування", "рятунок", "порятунок", "визволення"), matches[0].getSuggestedReplacements());
    assertTrue(matches[0].getMessage().contains(": релігія"));
    //refl
    matches = rule.match(langTool.getAnalyzedSentence("відображаються"));
    assertEquals(1, matches.length);
    assertEquals(Arrays.asList("показуватися", "зображатися", "відбиватися"), matches[0].getSuggestedReplacements());
    assertTrue("No context: " + matches[0].getMessage(), matches[0].getMessage().contains(": математика"));
// test ignoreTagged
//    matches = rule.match(langTool.getAnalyzedSentence("щедрота"));
//    assertEquals(1, matches.length);
//    assertEquals(Arrays.asList("щедрість", "гойність", "щедриня"), matches[0].getSuggestedReplacements());
//
//    matches = rule.match(langTool.getAnalyzedSentence("щедроти"));
//    assertEquals(0, matches.length);
}
Also used : Ukrainian(org.languagetool.language.Ukrainian) RuleMatch(org.languagetool.rules.RuleMatch) JLanguageTool(org.languagetool.JLanguageTool) Test(org.junit.Test)

Example 14 with RuleMatch

use of org.languagetool.rules.RuleMatch in project languagetool by languagetool-org.

the class MixedAlphabetsRuleTest method testRule.

@Test
public void testRule() throws IOException {
    final MixedAlphabetsRule rule = new MixedAlphabetsRule(TestTools.getMessages("uk"));
    final JLanguageTool langTool = new JLanguageTool(new Ukrainian());
    // correct sentences:
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("сміття")).length);
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("not mixed")).length);
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("123454")).length);
    //incorrect sentences:
    //latin i
    RuleMatch[] matches = rule.match(langTool.getAnalyzedSentence("смiття"));
    // check match positions:
    assertEquals(1, matches.length);
    assertEquals(Arrays.asList("сміття"), matches[0].getSuggestedReplacements());
    // cyrillic i and x
    matches = rule.match(langTool.getAnalyzedSentence("mіхed"));
    assertEquals(1, matches.length);
    assertEquals(Arrays.asList("mixed"), matches[0].getSuggestedReplacements());
    // umlaut instead of accented і
    matches = rule.match(langTool.getAnalyzedSentence("горíти"));
    assertEquals(1, matches.length);
    assertEquals(Arrays.asList("горі́ти"), matches[0].getSuggestedReplacements());
    // latin i
    matches = rule.match(langTool.getAnalyzedSentence("Чорного i Азовського"));
    assertEquals(1, matches.length);
    assertEquals(Arrays.asList("і"), matches[0].getSuggestedReplacements());
    // cyrillic І and latin X
    matches = rule.match(langTool.getAnalyzedSentence("XІ"));
    assertEquals(1, matches.length);
    assertEquals(Arrays.asList("XI"), matches[0].getSuggestedReplacements());
    // cyrillic X and latin I
    matches = rule.match(langTool.getAnalyzedSentence("ХI"));
    assertEquals(1, matches.length);
    assertEquals(Arrays.asList("XI"), matches[0].getSuggestedReplacements());
    // cyrillic both X and I used for latin number
    matches = rule.match(langTool.getAnalyzedSentence("ХІ"));
    assertEquals(1, matches.length);
    assertEquals(Arrays.asList("XI"), matches[0].getSuggestedReplacements());
    // cyrillic B
    matches = rule.match(langTool.getAnalyzedSentence("Щеплення від гепатиту В."));
    assertEquals(1, matches.length);
    assertEquals("B", matches[0].getSuggestedReplacements().get(0));
    // cyrillic А
    matches = rule.match(langTool.getAnalyzedSentence("група А"));
    assertEquals(1, matches.length);
    assertEquals("A", matches[0].getSuggestedReplacements().get(0));
    // cyrillic С
    matches = rule.match(langTool.getAnalyzedSentence("На 0,6°С."));
    assertEquals(1, matches.length);
    assertEquals("0,6°C", matches[0].getSuggestedReplacements().get(0));
}
Also used : Ukrainian(org.languagetool.language.Ukrainian) RuleMatch(org.languagetool.rules.RuleMatch) JLanguageTool(org.languagetool.JLanguageTool) Test(org.junit.Test)

Example 15 with RuleMatch

use of org.languagetool.rules.RuleMatch in project languagetool by languagetool-org.

the class MorfologikUkrainianSpellerRuleTest method testMorfologikSpeller.

@Test
public void testMorfologikSpeller() throws IOException {
    MorfologikUkrainianSpellerRule rule = new MorfologikUkrainianSpellerRule(TestTools.getMessages("uk"), new Ukrainian());
    JLanguageTool langTool = new JLanguageTool(new Ukrainian());
    // correct sentences:
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("До вас прийде заввідділу!")).length);
    assertEquals(0, rule.match(langTool.getAnalyzedSentence(",")).length);
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("123454")).length);
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("До нас приїде The Beatles!")).length);
    // soft hyphen
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("піс­ні")).length);
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("піс­ні піс­ні")).length);
    // non-breaking hyphen
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("ось‑ось")).length);
    //incorrect sentences:
    RuleMatch[] matches = rule.match(langTool.getAnalyzedSentence("атакуючий"));
    // check match positions:
    assertEquals(1, matches.length);
    matches = rule.match(langTool.getAnalyzedSentence("шкляний"));
    assertEquals(1, matches.length);
    assertEquals("скляний", matches[0].getSuggestedReplacements().get(0));
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("а")).length);
    // mix alphabets
    // latin 'i'
    matches = rule.match(langTool.getAnalyzedSentence("прийдешнiй"));
    assertEquals(1, matches.length);
    assertEquals("прийдешній", matches[0].getSuggestedReplacements().get(0));
    // кличний для неістот
    matches = rule.match(langTool.getAnalyzedSentence("душе"));
    assertEquals(1, matches.length);
    // розмовний інфінітив
    matches = rule.match(langTool.getAnalyzedSentence("писать"));
    assertEquals(1, matches.length);
    // compounding
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("Жакет був синьо-жовтого кольору")).length);
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("Він багато сидів на інтернет-форумах")).length);
    assertEquals(1, rule.match(langTool.getAnalyzedSentence("Він багато сидів на інтермет-форумах")).length);
    // dynamic tagging
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("екс-креветка")).length);
    assertEquals(1, rule.match(langTool.getAnalyzedSentence("банд-формування.")).length);
    assertEquals(1, rule.match(langTool.getAnalyzedSentence("учбово-виховного")).length);
    // abbreviations
    RuleMatch[] match = rule.match(langTool.getAnalyzedSentence("Читання віршів Т.Г.Шевченко і Г.Тютюнника"));
    assertEquals(new ArrayList<RuleMatch>(), Arrays.asList(match));
    match = rule.match(langTool.getAnalyzedSentence("Читання віршів Т. Г. Шевченко і Г. Тютюнника"));
    assertEquals(new ArrayList<RuleMatch>(), Arrays.asList(match));
    match = rule.match(langTool.getAnalyzedSentence("Англі́йська мова (англ. English language, English) належить до германської групи"));
    assertEquals(new ArrayList<RuleMatch>(), Arrays.asList(match));
    match = rule.match(langTool.getAnalyzedSentence("Англі́йська мова (англ English language, English) належить до германської групи"));
    assertEquals(1, match.length);
    match = rule.match(langTool.getAnalyzedSentence("100 тис. гривень"));
    assertEquals(new ArrayList<RuleMatch>(), Arrays.asList(match));
    match = rule.match(langTool.getAnalyzedSentence("100 кв. м"));
    assertEquals(new ArrayList<RuleMatch>(), Arrays.asList(match));
    match = rule.match(langTool.getAnalyzedSentence("100 км²"));
    assertEquals(new ArrayList<RuleMatch>(), Arrays.asList(match));
    match = rule.match(langTool.getAnalyzedSentence("100 кв м"));
    assertEquals(1, Arrays.asList(match).size());
    match = rule.match(langTool.getAnalyzedSentence("2 раза"));
    assertEquals(1, Arrays.asList(match).size());
    match = rule.match(langTool.getAnalyzedSentence("півтора раза"));
    assertEquals(0, match.length);
}
Also used : Ukrainian(org.languagetool.language.Ukrainian) RuleMatch(org.languagetool.rules.RuleMatch) JLanguageTool(org.languagetool.JLanguageTool) Test(org.junit.Test)

Aggregations

RuleMatch (org.languagetool.rules.RuleMatch)144 Test (org.junit.Test)64 JLanguageTool (org.languagetool.JLanguageTool)54 ArrayList (java.util.ArrayList)30 AnalyzedTokenReadings (org.languagetool.AnalyzedTokenReadings)14 Rule (org.languagetool.rules.Rule)14 Language (org.languagetool.Language)10 PatternRule (org.languagetool.rules.patterns.PatternRule)10 AnalyzedSentence (org.languagetool.AnalyzedSentence)8 Ukrainian (org.languagetool.language.Ukrainian)8 AbstractPatternRule (org.languagetool.rules.patterns.AbstractPatternRule)8 Matcher (java.util.regex.Matcher)7 English (org.languagetool.language.English)7 IOException (java.io.IOException)6 Catalan (org.languagetool.language.Catalan)6 Polish (org.languagetool.language.Polish)6 GermanyGerman (org.languagetool.language.GermanyGerman)5 AnnotatedText (org.languagetool.markup.AnnotatedText)5 PatternToken (org.languagetool.rules.patterns.PatternToken)5 AnalyzedToken (org.languagetool.AnalyzedToken)4