use of org.languagetool.rules.TextLevelRule in project languagetool by languagetool-org.
the class CommandLineTools method profileRulesOnText.
/**
* Simple rule profiler - used to run LT on a corpus to see which
* rule takes most time. Prints results to System.out.
*
* @param contents text to check
* @param lt instance of LanguageTool
*/
public static void profileRulesOnText(String contents, JLanguageTool lt) throws IOException {
long[] workTime = new long[10];
List<Rule> rules = lt.getAllActiveRules();
int ruleCount = rules.size();
System.out.printf("Testing %d rules%n", ruleCount);
System.out.println("Rule ID\tTime\tSentences\tMatches\tSentences per sec.");
List<String> sentences = lt.sentenceTokenize(contents);
for (Rule rule : rules) {
if (rule instanceof TextLevelRule) {
// profile rules for sentences only
continue;
}
int matchCount = 0;
for (int k = 0; k < 10; k++) {
long startTime = System.currentTimeMillis();
for (String sentence : sentences) {
matchCount += rule.match(lt.getAnalyzedSentence(sentence)).length;
}
long endTime = System.currentTimeMillis();
workTime[k] = endTime - startTime;
}
long time = median(workTime);
float timeInSeconds = time / 1000.0f;
float sentencesPerSecond = sentences.size() / timeInSeconds;
System.out.printf(Locale.ENGLISH, "%s\t%d\t%d\t%d\t%.1f", rule.getId(), time, sentences.size(), matchCount, sentencesPerSecond);
System.out.println();
}
}
use of org.languagetool.rules.TextLevelRule in project languagetool by languagetool-org.
the class WordCoherencyRuleTest method testRules.
@Test
public void testRules() throws IOException {
JLanguageTool langTool = new JLanguageTool(new Persian());
TextLevelRule rule = new WordCoherencyRule(TestTools.getMessages("fa"));
assertThat(rule.match(Collections.singletonList(langTool.getAnalyzedSentence("این یک اتاق است."))).length, is(0));
assertThat(rule.match(Collections.singletonList(langTool.getAnalyzedSentence("این یک اتاق است. این یک اطاق است."))).length, is(1));
}
Aggregations