当前位置: 首页>>代码示例>>Java>>正文


Java JLanguageTool.addRule方法代码示例

本文整理汇总了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);
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:17,代码来源:CommandLineToolsTest.java

示例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;
  }
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:19,代码来源:LanguageToolEvaluator.java

示例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);
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:16,代码来源:SentenceWhitespaceRuleTest.java

示例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);
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:15,代码来源:RealWordFalseAlarmEvaluator.java

示例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);
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:15,代码来源:SimpleCorpusEvaluator.java

示例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;
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:12,代码来源:Searcher.java


注:本文中的org.languagetool.JLanguageTool.addRule方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。