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;
}
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");
}
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);
}
}
}
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());
}
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());
}
Aggregations