Search in sources :

Example 1 with PatternRule

use of org.languagetool.rules.patterns.PatternRule in project languagetool by languagetool-org.

the class ExampleSentenceCorrectionCreator method run.

private void run(Language lang) throws IOException {
    File basePath = new File("/lt/git/languagetool/languagetool-language-modules");
    if (!basePath.exists()) {
        throw new RuntimeException("basePath does not exist: " + basePath);
    }
    String langCode = lang.getShortCode();
    File xml = new File(basePath, "/" + langCode + "/src/main/resources/org/languagetool/rules/" + langCode + "/grammar.xml");
    List<String> xmlLines = IOUtils.readLines(new FileReader(xml));
    JLanguageTool tool = new JLanguageTool(lang);
    for (Rule rule : tool.getAllRules()) {
        if (!(rule instanceof PatternRule)) {
            continue;
        }
        List<IncorrectExample> incorrectExamples = rule.getIncorrectExamples();
        for (IncorrectExample incorrectExample : incorrectExamples) {
            checkCorrections(rule, incorrectExample, xmlLines, tool);
        }
    }
    System.err.println("Added corrections: " + addedCorrectionsCount);
    for (String xmlLine : xmlLines) {
        System.out.println(xmlLine);
    }
}
Also used : PatternRule(org.languagetool.rules.patterns.PatternRule) AbstractPatternRule(org.languagetool.rules.patterns.AbstractPatternRule) JLanguageTool(org.languagetool.JLanguageTool) FileReader(java.io.FileReader) Rule(org.languagetool.rules.Rule) PatternRule(org.languagetool.rules.patterns.PatternRule) AbstractPatternRule(org.languagetool.rules.patterns.AbstractPatternRule) IncorrectExample(org.languagetool.rules.IncorrectExample) File(java.io.File)

Example 2 with PatternRule

use of org.languagetool.rules.patterns.PatternRule in project languagetool by languagetool-org.

the class RuleWithMaxFilterTest method testNoFilteringIfDifferentRulegroups.

@Test
public void testNoFilteringIfDifferentRulegroups() {
    List<PatternToken> fakePatternTokens = new ArrayList<>();
    Rule rule1 = new PatternRule("id1", language, fakePatternTokens, "desc1", "msg1", "shortMsg1");
    Rule rule2 = new PatternRule("id2", language, fakePatternTokens, "desc2", "msg2", "shortMsg2");
    RuleMatch match1 = new RuleMatch(rule1, 10, 20, "Match1");
    RuleMatch match2 = new RuleMatch(rule2, 15, 25, "Match2");
    RuleWithMaxFilter filter = new RuleWithMaxFilter();
    List<RuleMatch> filteredMatches1 = filter.filter(Arrays.asList(match1, match2));
    assertEquals(2, filteredMatches1.size());
    RuleMatch match3 = new RuleMatch(rule2, 11, 19, "Match3");
    List<RuleMatch> filteredMatches2 = filter.filter(Arrays.asList(match1, match3));
    assertEquals(2, filteredMatches2.size());
}
Also used : PatternToken(org.languagetool.rules.patterns.PatternToken) PatternRule(org.languagetool.rules.patterns.PatternRule) ArrayList(java.util.ArrayList) PatternRule(org.languagetool.rules.patterns.PatternRule) Test(org.junit.Test)

Example 3 with PatternRule

use of org.languagetool.rules.patterns.PatternRule in project languagetool by languagetool-org.

the class RuleWithMaxFilterTest method testFilter.

@Test
public void testFilter() {
    List<PatternToken> fakePatternTokens = new ArrayList<>();
    PatternRule rule1 = new PatternRule("id1", language, fakePatternTokens, "desc1", "msg1", "shortMsg1");
    PatternRule rule2 = new PatternRule("id1", language, fakePatternTokens, "desc2", "msg2", "shortMsg2");
    RuleMatch match1 = new RuleMatch(rule1, 10, 20, "Match1");
    RuleMatch match2 = new RuleMatch(rule2, 15, 25, "Match2");
    RuleWithMaxFilter filter = new RuleWithMaxFilter();
    List<RuleMatch> filteredMatches1 = filter.filter(Arrays.asList(match1, match2));
    assertEquals(2, filteredMatches1.size());
    RuleMatch match3 = new RuleMatch(rule2, 11, 19, "Match3");
    List<RuleMatch> filteredMatches2 = filter.filter(Arrays.asList(match1, match3));
    assertEquals(1, filteredMatches2.size());
}
Also used : PatternToken(org.languagetool.rules.patterns.PatternToken) PatternRule(org.languagetool.rules.patterns.PatternRule) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 4 with PatternRule

use of org.languagetool.rules.patterns.PatternRule in project languagetool by languagetool-org.

the class SameRuleGroupFilterTest method testNoFilteringIfNotOverlapping.

@Test
public void testNoFilteringIfNotOverlapping() {
    List<PatternToken> fakePatternTokens = new ArrayList<>();
    PatternRule rule1 = new PatternRule("id1", language, fakePatternTokens, "desc1", "msg1", "shortMsg1");
    PatternRule rule2 = new PatternRule("id1", language, fakePatternTokens, "desc2", "msg2", "shortMsg2");
    RuleMatch match1 = new RuleMatch(rule1, 10, 20, "Match1");
    RuleMatch match2 = new RuleMatch(rule2, 21, 25, "Match2");
    SameRuleGroupFilter filter = new SameRuleGroupFilter();
    List<RuleMatch> filteredMatches = filter.filter(Arrays.asList(match1, match2));
    assertEquals(2, filteredMatches.size());
}
Also used : PatternToken(org.languagetool.rules.patterns.PatternToken) PatternRule(org.languagetool.rules.patterns.PatternRule) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 5 with PatternRule

use of org.languagetool.rules.patterns.PatternRule in project languagetool by languagetool-org.

the class SameRuleGroupFilterTest method testNoFilteringIfDifferentRulegroups.

@Test
public void testNoFilteringIfDifferentRulegroups() {
    List<PatternToken> fakePatternTokens = new ArrayList<>();
    Rule rule1 = new PatternRule("id1", language, fakePatternTokens, "desc1", "msg1", "shortMsg1");
    Rule rule2 = new PatternRule("id2", language, fakePatternTokens, "desc2", "msg2", "shortMsg2");
    RuleMatch match1 = new RuleMatch(rule1, 10, 20, "Match1");
    RuleMatch match2 = new RuleMatch(rule2, 15, 25, "Match2");
    SameRuleGroupFilter filter = new SameRuleGroupFilter();
    List<RuleMatch> filteredMatches = filter.filter(Arrays.asList(match1, match2));
    assertEquals(2, filteredMatches.size());
}
Also used : PatternToken(org.languagetool.rules.patterns.PatternToken) PatternRule(org.languagetool.rules.patterns.PatternRule) ArrayList(java.util.ArrayList) PatternRule(org.languagetool.rules.patterns.PatternRule) Test(org.junit.Test)

Aggregations

PatternRule (org.languagetool.rules.patterns.PatternRule)30 PatternToken (org.languagetool.rules.patterns.PatternToken)17 Rule (org.languagetool.rules.Rule)13 ArrayList (java.util.ArrayList)12 RuleMatch (org.languagetool.rules.RuleMatch)11 Test (org.junit.Test)10 JLanguageTool (org.languagetool.JLanguageTool)8 English (org.languagetool.language.English)8 File (java.io.File)4 FileReader (java.io.FileReader)3 IncorrectExample (org.languagetool.rules.IncorrectExample)3 Ignore (org.junit.Ignore)2 Language (org.languagetool.Language)2 AbstractPatternRule (org.languagetool.rules.patterns.AbstractPatternRule)2 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 Document (org.apache.lucene.document.Document)1 Field (org.apache.lucene.document.Field)1