本文整理汇总了Java中org.languagetool.JLanguageTool.addRule方法的典型用法代码示例。如果您正苦于以下问题:Java JLanguageTool.addRule方法的具体用法?Java JLanguageTool.addRule怎么用?Java JLanguageTool.addRule使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.languagetool.JLanguageTool
的用法示例。
在下文中一共展示了JLanguageTool.addRule方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testCheck
import org.languagetool.JLanguageTool; //导入方法依赖的package包/类
@Test
public void testCheck() throws IOException, ParserConfigurationException, SAXException {
JLanguageTool tool = new JLanguageTool(TestTools.getDemoLanguage());
int matches = CommandLineTools.checkText("Foo.", tool);
String output = new String(this.out.toByteArray());
assertEquals(0, output.indexOf("Time:"));
assertEquals(0, matches);
tool.disableRule("test_unification_with_negation");
tool.addRule(new WordRepeatRule(TestTools.getEnglishMessages(), TestTools.getDemoLanguage()));
matches = CommandLineTools.checkText("To jest problem problem.", tool);
output = new String(this.out.toByteArray());
assertTrue(output.contains("Rule ID: WORD_REPEAT_RULE"));
assertEquals(1, matches);
}
示例2: LanguageToolEvaluator
import org.languagetool.JLanguageTool; //导入方法依赖的package包/类
LanguageToolEvaluator(File indexTopDir) throws IOException {
langTool = new JLanguageTool(new BritishEnglish());
disableRules();
if (indexTopDir != null) {
if (indexTopDir.isDirectory()) {
languageModel = new LuceneLanguageModel(indexTopDir);
System.out.println("Using Lucene language model from " + languageModel);
EnglishConfusionProbabilityRule probabilityRule =
new EnglishConfusionProbabilityRule(JLanguageTool.getMessageBundle(), languageModel, new English());
//new EnglishConfusionProbabilityRule(JLanguageTool.getMessageBundle(), languageModel, new File("/tmp/languagetool_network.net"));
langTool.addRule(probabilityRule);
} else {
throw new RuntimeException("Does not exist or not a directory: " + indexTopDir);
}
} else {
languageModel = null;
}
}
示例3: testMatch
import org.languagetool.JLanguageTool; //导入方法依赖的package包/类
@Test
public void testMatch() throws Exception {
SentenceWhitespaceRule rule = new SentenceWhitespaceRule(TestTools.getEnglishMessages());
JLanguageTool lt = new JLanguageTool(new FakeLanguage());
lt.addRule(rule);
assertGood("This is a text. And there's the next sentence.", rule, lt);
assertGood("This is a text! And there's the next sentence.", rule, lt);
assertGood("This is a text\nAnd there's the next sentence.", rule, lt);
assertGood("This is a text\n\nAnd there's the next sentence.", rule, lt);
assertBad("This is a text.And there's the next sentence.", rule, lt);
assertBad("This is a text!And there's the next sentence.", rule, lt);
assertBad("This is a text?And there's the next sentence.", rule, lt);
}
示例4: RealWordFalseAlarmEvaluator
import org.languagetool.JLanguageTool; //导入方法依赖的package包/类
RealWordFalseAlarmEvaluator(File languageModelIndexDir) throws IOException {
try (InputStream inputStream = JLanguageTool.getDataBroker().getFromResourceDirAsStream("/en/confusion_sets.txt")) {
ConfusionSetLoader confusionSetLoader = new ConfusionSetLoader();
confusionSets = confusionSetLoader.loadConfusionSet(inputStream);
}
langTool = new JLanguageTool(new BritishEnglish());
List<Rule> rules = langTool.getAllActiveRules();
for (Rule rule : rules) {
langTool.disableRule(rule.getId());
}
languageModel = new LuceneLanguageModel(languageModelIndexDir);
confusionRule = new EnglishConfusionProbabilityRule(JLanguageTool.getMessageBundle(), languageModel, new English());
langTool.addRule(confusionRule);
}
示例5: NgramLanguageToolEvaluator
import org.languagetool.JLanguageTool; //导入方法依赖的package包/类
NgramLanguageToolEvaluator(File... indexTopDirs) throws IOException {
langTool = new JLanguageTool(new English());
disableAllRules();
List<LanguageModel> lms = new ArrayList<>();
for (File indexTopDir : indexTopDirs) {
lms.add(new LuceneLanguageModel(indexTopDir));
}
languageModel = new MultiLanguageModel(lms);
LuceneSingleIndexLanguageModel.clearCaches();
System.out.println("Using Lucene language model from " + languageModel);
probabilityRule = new EnglishNgramProbabilityRule(JLanguageTool.getMessageBundle(), languageModel, new English());
probabilityRule.setDefaultOn();
langTool.addRule(probabilityRule);
}
示例6: getLanguageToolWithOneRule
import org.languagetool.JLanguageTool; //导入方法依赖的package包/类
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);
langTool.enableRule(patternRule.getId()); // rule might be off by default
return langTool;
}