Search in sources :

Example 41 with JLanguageTool

use of org.languagetool.JLanguageTool in project languagetool by languagetool-org.

the class SuggestionReplacerTest method getLanguageTool.

private JLanguageTool getLanguageTool() {
    JLanguageTool langTool = getLanguageTool(germanyGerman);
    langTool.disableRule("DE_CASE");
    return langTool;
}
Also used : JLanguageTool(org.languagetool.JLanguageTool)

Example 42 with JLanguageTool

use of org.languagetool.JLanguageTool in project languagetool by languagetool-org.

the class IndexerSearcherTest method testAllRules.

@Ignore("ignored as long as it doesn't work 100%")
public void testAllRules() throws Exception {
    long startTime = System.currentTimeMillis();
    // comment in to test with external index:
    //directory = new SimpleFSDirectory(new File("/media/external-disk/corpus/languagetool/fast-rule-evaluation-de/"));
    //errorSearcher = new Searcher(directory);
    // TODO: make this work for all languages
    Language language = new English();
    //Language language = new French();
    //Language language = new Spanish();
    //Language language = new Polish();
    //Language language = new German();
    JLanguageTool lt = new JLanguageTool(language);
    System.out.println("Creating index for " + language + "...");
    int ruleCount = createIndex(lt);
    System.out.println("Index created with " + ruleCount + " rules");
    int ruleCounter = 0;
    int ruleProblems = 0;
    int exceptionCount = 0;
    List<Rule> rules = lt.getAllActiveRules();
    for (Rule rule : rules) {
        if (rule instanceof PatternRule && !rule.isDefaultOff()) {
            PatternRule patternRule = (PatternRule) rule;
            try {
                ruleCounter++;
                SearcherResult searcherResult = errorSearcher.findRuleMatchesOnIndex(patternRule, language);
                List<MatchingSentence> matchingSentences = searcherResult.getMatchingSentences();
                boolean foundExpectedMatch = false;
                for (MatchingSentence matchingSentence : matchingSentences) {
                    List<RuleMatch> ruleMatches = matchingSentence.getRuleMatches();
                    List<String> ruleMatchIds = getRuleMatchIds(ruleMatches);
                    if (ruleMatchIds.contains(patternRule.getFullId())) {
                        // TODO: there can be more than one expected match, can't it?
                        foundExpectedMatch = true;
                        break;
                    }
                }
                if (!foundExpectedMatch) {
                    System.out.println("Error: No match found for " + patternRule);
                    System.out.println("Query      : " + searcherResult.getRelaxedQuery().toString(FIELD_NAME_LOWERCASE));
                    System.out.println("Default field: " + FIELD_NAME_LOWERCASE);
                    System.out.println("Lucene Hits: " + searcherResult.getLuceneMatchCount());
                    System.out.println("Matches    : " + matchingSentences);
                    System.out.println("Examples   : " + rule.getIncorrectExamples());
                    System.out.println();
                    ruleProblems++;
                } else {
                //long time = System.currentTimeMillis() - startTime;
                //System.out.println("Tested " + matchingSentences.size() + " sentences in " + time + "ms for rule " + patternRule);
                }
            } catch (UnsupportedPatternRuleException e) {
                System.out.println("UnsupportedPatternRuleException searching for rule " + patternRule.getFullId() + ": " + e.getMessage());
                ruleProblems++;
            } catch (Exception e) {
                System.out.println("Exception searching for rule " + patternRule.getFullId() + ": " + e.getMessage());
                e.printStackTrace(System.out);
                exceptionCount++;
            }
        }
    }
    System.out.println(language + ": problems: " + ruleProblems + ", total rules: " + ruleCounter);
    System.out.println(language + ": exceptions: " + exceptionCount + " (including timeouts)");
    System.out.println("Total time: " + (System.currentTimeMillis() - startTime) + "ms");
}
Also used : PatternRule(org.languagetool.rules.patterns.PatternRule) JLanguageTool(org.languagetool.JLanguageTool) IOException(java.io.IOException) English(org.languagetool.language.English) RuleMatch(org.languagetool.rules.RuleMatch) Language(org.languagetool.Language) PatternRule(org.languagetool.rules.patterns.PatternRule) Rule(org.languagetool.rules.Rule) Ignore(org.junit.Ignore)

Example 43 with JLanguageTool

use of org.languagetool.JLanguageTool in project languagetool by languagetool-org.

the class Example method main.

public static void main(String[] args) throws IOException {
    List<Language> realLanguages = Languages.get();
    System.out.println("This example will test a short string with all languages known to LanguageTool.");
    System.out.println("It's just a test to make sure there's at least no crash.");
    System.out.println("Using LanguageTool " + JLanguageTool.VERSION + " (" + JLanguageTool.BUILD_DATE + ")");
    System.out.println("Supported languages: " + realLanguages.size());
    for (Language language : realLanguages) {
        JLanguageTool langTool = new JLanguageTool(language);
        String input = "And the the";
        List<RuleMatch> result = langTool.check(input);
        System.out.println("Checking '" + input + "' with " + language + ":");
        for (RuleMatch ruleMatch : result) {
            System.out.println("    " + ruleMatch);
        }
    }
}
Also used : RuleMatch(org.languagetool.rules.RuleMatch) Language(org.languagetool.Language) JLanguageTool(org.languagetool.JLanguageTool)

Example 44 with JLanguageTool

use of org.languagetool.JLanguageTool in project languagetool by languagetool-org.

the class AccentuationCheckRuleTest method setUp.

@Before
public void setUp() throws IOException {
    rule = new AccentuationCheckRule(TestTools.getEnglishMessages());
    langTool = new JLanguageTool(new Catalan());
}
Also used : JLanguageTool(org.languagetool.JLanguageTool) Catalan(org.languagetool.language.Catalan) Before(org.junit.Before)

Example 45 with JLanguageTool

use of org.languagetool.JLanguageTool in project languagetool by languagetool-org.

the class AccentuationCheckRuleTest method testPositions.

@Test
public void testPositions() throws IOException {
    final AccentuationCheckRule rule = new AccentuationCheckRule(TestTools.getEnglishMessages());
    final RuleMatch[] matches;
    final JLanguageTool langTool = new JLanguageTool(new Catalan());
    matches = rule.match(langTool.getAnalyzedSentence("Són circumstancies extraordinàries."));
    assertEquals(4, matches[0].getFromPos());
    assertEquals(18, matches[0].getToPos());
}
Also used : RuleMatch(org.languagetool.rules.RuleMatch) JLanguageTool(org.languagetool.JLanguageTool) Catalan(org.languagetool.language.Catalan) Test(org.junit.Test)

Aggregations

JLanguageTool (org.languagetool.JLanguageTool)184 Test (org.junit.Test)109 RuleMatch (org.languagetool.rules.RuleMatch)57 Before (org.junit.Before)38 German (org.languagetool.language.German)16 Rule (org.languagetool.rules.Rule)16 Catalan (org.languagetool.language.Catalan)14 Ukrainian (org.languagetool.language.Ukrainian)14 English (org.languagetool.language.English)13 Polish (org.languagetool.language.Polish)12 Language (org.languagetool.Language)10 GermanyGerman (org.languagetool.language.GermanyGerman)9 PatternRule (org.languagetool.rules.patterns.PatternRule)9 AnalyzedSentence (org.languagetool.AnalyzedSentence)8 File (java.io.File)7 AnalyzedTokenReadings (org.languagetool.AnalyzedTokenReadings)6 Dutch (org.languagetool.language.Dutch)5 French (org.languagetool.language.French)5 ArrayList (java.util.ArrayList)4 FakeLanguage (org.languagetool.FakeLanguage)4