Search in sources :

Example 36 with RuleMatch

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

the class StartupTimePerformanceTest method run.

private void run(Language language) throws IOException {
    long totalTime = 0;
    for (int i = 0; i < RUNS; i++) {
        long startTime = System.currentTimeMillis();
        MultiThreadedJLanguageTool langTool = new MultiThreadedJLanguageTool(language);
        List<RuleMatch> matches = langTool.check("");
        if (matches.size() > 0) {
            throw new RuntimeException("Got matches on empty input for " + language + ": " + matches);
        }
        long runTime = System.currentTimeMillis() - startTime;
        langTool.shutdown();
        if (i >= SKIP) {
            totalTime += runTime;
        }
    //System.out.println(runTime + "ms");
    }
    System.out.println(language.getShortCodeWithCountryAndVariant() + ": avg. Time: " + (float) totalTime / RUNS + "ms");
}
Also used : RuleMatch(org.languagetool.rules.RuleMatch) MultiThreadedJLanguageTool(org.languagetool.MultiThreadedJLanguageTool)

Example 37 with RuleMatch

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

the class JLanguageToolTest method testAnnotateTextCheckMultipleSentences.

@Test
public void testAnnotateTextCheckMultipleSentences() throws IOException {
    JLanguageTool languageTool = new JLanguageTool(english);
    AnnotatedText annotatedText = new AnnotatedTextBuilder().addMarkup("<b>").addText("here").addMarkup("</b>").addText(" is an error. And ").addMarkup("<i attr='foo'>").addText("here is also").addMarkup("</i>").addText(" a error.").build();
    List<RuleMatch> matches = languageTool.check(annotatedText);
    assertThat(matches.size(), is(2));
    assertThat(matches.get(0).getFromPos(), is(3));
    assertThat(matches.get(0).getToPos(), is(7));
    assertThat(matches.get(1).getFromPos(), is(60));
    assertThat(matches.get(1).getToPos(), is(61));
}
Also used : RuleMatch(org.languagetool.rules.RuleMatch) AnnotatedTextBuilder(org.languagetool.markup.AnnotatedTextBuilder) AnnotatedText(org.languagetool.markup.AnnotatedText) Test(org.junit.Test)

Example 38 with RuleMatch

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

the class JLanguageToolTest method testAnnotateTextCheckMultipleSentences2.

@Test
public void testAnnotateTextCheckMultipleSentences2() throws IOException {
    JLanguageTool languageTool = new JLanguageTool(english);
    AnnotatedText annotatedText = new AnnotatedTextBuilder().addText("here").addText(" is an error. And ").addMarkup("<i attr='foo'/>").addText("here is also ").addMarkup("<i>").addText("a").addMarkup("</i>").addText(" error.").build();
    List<RuleMatch> matches = languageTool.check(annotatedText);
    assertThat(matches.size(), is(2));
    assertThat(matches.get(0).getFromPos(), is(0));
    assertThat(matches.get(0).getToPos(), is(4));
    assertThat(matches.get(1).getFromPos(), is(53));
    assertThat(matches.get(1).getToPos(), is(54));
}
Also used : RuleMatch(org.languagetool.rules.RuleMatch) AnnotatedTextBuilder(org.languagetool.markup.AnnotatedTextBuilder) AnnotatedText(org.languagetool.markup.AnnotatedText) Test(org.junit.Test)

Example 39 with RuleMatch

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

the class DifferentLengthRuleTest method testRule.

@Test
public void testRule() throws IOException {
    DifferentLengthRule rule = new DifferentLengthRule();
    RuleMatch[] matches;
    JLanguageTool trgLangTool = new JLanguageTool(TestTools.getDemoLanguage());
    JLanguageTool srcLangTool = new JLanguageTool(new FakeLanguage());
    rule.setSourceLanguage(TestTools.getDemoLanguage());
    // correct sentences:
    matches = rule.match(srcLangTool.getAnalyzedSentence("This is a test sentence."), trgLangTool.getAnalyzedSentence("To zdanie testowe."));
    assertEquals(0, matches.length);
    matches = rule.match(srcLangTool.getAnalyzedSentence("Click this button."), trgLangTool.getAnalyzedSentence("Kliknij ten przycisk."));
    assertEquals(0, matches.length);
    // incorrect sentences:
    matches = rule.match(srcLangTool.getAnalyzedSentence("Open a file, and check if it is corrupt."), trgLangTool.getAnalyzedSentence("Otwórz plik."));
    assertEquals(1, matches.length);
}
Also used : RuleMatch(org.languagetool.rules.RuleMatch) FakeLanguage(org.languagetool.FakeLanguage) JLanguageTool(org.languagetool.JLanguageTool) Test(org.junit.Test)

Example 40 with RuleMatch

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

the class PatternRuleMatcherTest method testZeroMinOccurrencesWithSuggestion.

@Test
public void testZeroMinOccurrencesWithSuggestion() throws Exception {
    PatternToken patternTokenB = makeElement("b");
    patternTokenB.setMinOccurrence(0);
    // regex: a b? c
    List<PatternToken> patternTokens = Arrays.asList(makeElement("a"), patternTokenB, makeElement("c"));
    PatternRule rule = new PatternRule("", new Demo(), patternTokens, "my description", "<suggestion>\\1 \\2 \\3</suggestion>", "short message");
    PatternRuleMatcher matcher = new PatternRuleMatcher(rule, false);
    // we need to add this line to trigger proper replacement but I am not sure why :(
    rule.addSuggestionMatch(new Match(null, null, false, null, null, CaseConversion.NONE, false, false, IncludeRange.NONE));
    RuleMatch[] matches = getMatches("a b c", matcher);
    assertEquals(Arrays.asList("a b c"), matches[0].getSuggestedReplacements());
    RuleMatch[] matches2 = getMatches("a c", matcher);
    assertEquals(Arrays.asList("a c"), matches2[0].getSuggestedReplacements());
}
Also used : Demo(org.languagetool.language.Demo) RuleMatch(org.languagetool.rules.RuleMatch) RuleMatch(org.languagetool.rules.RuleMatch) 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