use of org.languagetool.rules.Rule in project languagetool by languagetool-org.
the class Searcher method getLanguageToolWithOneRule.
private JLanguageTool getLanguageToolWithOneRule(Language lang, PatternRule patternRule) {
JLanguageTool langTool = new JLanguageTool(lang);
for (Rule rule : langTool.getAllActiveRules()) {
if (!rule.getId().equals(patternRule.getId())) {
langTool.disableRule(rule.getId());
}
}
langTool.addRule(patternRule);
// rule might be off by default
langTool.enableRule(patternRule.getId());
return langTool;
}
use of org.languagetool.rules.Rule in project languagetool by languagetool-org.
the class AtomFeedChecker method disableSpellingRules.
private void disableSpellingRules(JLanguageTool langTool) {
for (Rule rule : langTool.getAllActiveRules()) {
if (rule.isDictionaryBasedSpellingRule()) {
langTool.disableRule(rule.getId());
System.out.println("Disabled spelling rule: " + rule.getId());
}
}
}
use of org.languagetool.rules.Rule in project languagetool by languagetool-org.
the class AtomFeedChecker method activateCategory.
private void activateCategory(String categoryName, JLanguageTool langTool) {
for (Rule rule : langTool.getAllRules()) {
if (rule.getCategory().getName().equals(categoryName)) {
System.out.println("Activating " + rule.getId() + " in category " + categoryName);
langTool.enableRule(rule.getId());
}
}
}
use of org.languagetool.rules.Rule in project languagetool by languagetool-org.
the class WikipediaQuickCheck method main.
/*public static void mainTest(String[] args) throws IOException {
TextFilter filter = new SwebleWikipediaTextFilter();
String plainText = filter.filter("hallo\n* eins\n* zwei");
System.out.println(plainText);
}*/
public static void main(String[] args) throws IOException, PageNotFoundException {
if (args.length != 1) {
System.out.println("Usage: " + WikipediaQuickCheck.class.getName() + " <url>");
System.exit(1);
}
WikipediaQuickCheck check = new WikipediaQuickCheck();
// URL examples:
//String urlString = "http://de.wikipedia.org/wiki/Angela_Merkel";
//String urlString = "https://de.wikipedia.org/wiki/Benutzer_Diskussion:Dnaber";
//String urlString = "https://secure.wikimedia.org/wikipedia/de/wiki/Gütersloh";
String urlString = args[0];
MarkupAwareWikipediaResult result = check.checkPage(new URL(urlString), new ErrorMarker("***", "***"));
int errorCount = 0;
for (AppliedRuleMatch match : result.getAppliedRuleMatches()) {
RuleMatchApplication matchApplication = match.getRuleMatchApplications().get(0);
RuleMatch ruleMatch = match.getRuleMatch();
Rule rule = ruleMatch.getRule();
System.out.println("");
String message = ruleMatch.getMessage().replace("<suggestion>", "'").replace("</suggestion>", "'");
errorCount++;
System.out.print(errorCount + ". " + message);
if (rule instanceof AbstractPatternRule) {
System.out.println(" (" + ((AbstractPatternRule) rule).getFullId() + ")");
} else {
System.out.println(" (" + rule.getId() + ")");
}
System.out.println(" ..." + matchApplication.getOriginalErrorContext(50).replace("\n", "\\n") + "...");
}
}
use of org.languagetool.rules.Rule 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");
}
Aggregations