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


Java JLanguageTool.enableRule方法代码示例

本文整理汇总了Java中org.languagetool.JLanguageTool.enableRule方法的典型用法代码示例。如果您正苦于以下问题:Java JLanguageTool.enableRule方法的具体用法?Java JLanguageTool.enableRule怎么用?Java JLanguageTool.enableRule使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.languagetool.JLanguageTool的用法示例。


在下文中一共展示了JLanguageTool.enableRule方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: initLanguageTool

import org.languagetool.JLanguageTool; //导入方法依赖的package包/类
private void initLanguageTool() {
  try {
    prepareConfig(docLanguage);
    // not using MultiThreadedJLanguageTool here fixes "osl::Thread::Create failed", see https://bugs.documentfoundation.org/show_bug.cgi?id=90740:
    langTool = new JLanguageTool(docLanguage, config.getMotherTongue());
    File ngramDirectory = config.getNgramDirectory();
    if (ngramDirectory != null) {
      File ngramLangDir = new File(config.getNgramDirectory(), docLanguage.getShortCode());
      if (ngramLangDir.exists()) {  // user might have ngram data only for some languages and that's okay
        langTool.activateLanguageModelRules(ngramDirectory);
      }
    }
    for (Rule rule : langTool.getAllActiveOfficeRules()) {
      if (rule.isDictionaryBasedSpellingRule()) {
        langTool.disableRule(rule.getId());
      }
      if (rule.useInOffice()) {
        langTool.enableRule(rule.getId());
      }
    }
    recheck = false;
  } catch (Throwable t) {
    showError(t);
  }
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:26,代码来源:Main.java

示例2: configureFromRules

import org.languagetool.JLanguageTool; //导入方法依赖的package包/类
/**
 * @since 3.3
 */
public static void configureFromRules(JLanguageTool langTool, Configuration config) {
  Set<String> disabledRules = config.getDisabledRuleIds();
  if (disabledRules != null) {
    for (String ruleId : disabledRules) {
      langTool.disableRule(ruleId);
    }
  }
  Set<String> disabledCategories = config.getDisabledCategoryNames();
  if (disabledCategories != null) {
    for (String categoryName : disabledCategories) {
      langTool.disableCategory(new CategoryId(categoryName));
    }
  }
  if(config.getEnabledRulesOnly()) {
    for (Rule rule : langTool.getAllRules()) {
      langTool.disableRule(rule.getId());
    }
  }
  Set<String> enabledRules = config.getEnabledRuleIds();
  if (enabledRules != null) {
    for (String ruleName : enabledRules) {
      langTool.enableRule(ruleName);
    }
  }
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:29,代码来源:Tools.java

示例3: checkCorrections

import org.languagetool.JLanguageTool; //导入方法依赖的package包/类
private void checkCorrections(Rule rule, IncorrectExample incorrectExample, List<String> xmlLines, JLanguageTool tool) throws IOException {
  List<String> corrections = incorrectExample.getCorrections();
  if (corrections.isEmpty()) {
    for (Rule r : tool.getAllActiveRules()) {
      tool.disableRule(r.getId());
    }
    tool.enableRule(rule.getId());
    String incorrectSentence = incorrectExample.getExample().replaceAll("</?marker>", "");
    List<RuleMatch> matches = tool.check(incorrectSentence);
    System.err.println("no corrections: " + rule.getId() + ", " + matches.size() + " matches");
    if (matches.size() == 0) {
      throw new RuntimeException("Got no rule match: " + incorrectSentence);
    }
    List<String> suggestedReplacements = matches.get(0).getSuggestedReplacements();
    String newAttribute = "correction=\"" + String.join("|", suggestedReplacements) + "\"";
    addAttribute(rule, newAttribute, xmlLines);
  }
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:19,代码来源:ExampleSentenceCorrectionCreator.java

示例4: getBaselineTime

import org.languagetool.JLanguageTool; //导入方法依赖的package包/类
private static long getBaselineTime(JLanguageTool langTool, String text) throws IOException {
  deactivateAllRules(langTool);
  long baselineStartTime = System.currentTimeMillis();
  langTool.check(text);
  long baselineTime = System.currentTimeMillis() - baselineStartTime;
  if (langTool.getAllActiveRules().size() > 0) {
    throw new RuntimeException("Did not expect to get any pattern rules: " + langTool.getAllActiveRules().size());
  }
  for (Rule rule : langTool.getAllRules()) {
    langTool.enableRule(rule.getId());
  }
  return baselineTime;
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:14,代码来源:RuleNumberScalabilityTest.java

示例5: testMultipleSentences

import org.languagetool.JLanguageTool; //导入方法依赖的package包/类
@Test
public void testMultipleSentences() throws IOException {
  final JLanguageTool tool = new JLanguageTool(new Catalan());
  tool.enableRule("CA_UNPAIRED_BRACKETS");

  List<RuleMatch> matches;
  matches = tool
      .check("Aquesta és una sentència múltiple amb claudàtors: "
          + "[Ací hi ha un claudàtor. Amb algun text.] i ací continua.\n");
  assertEquals(0, matches.size());
  matches = tool
      .check("\"Sóc la teva filla. El corcó no et rosegarà més.\"\n\n");
  assertEquals(0, matches.size());
  matches = tool
      .check("\"Sóc la teva filla. El corcó no et rosegarà més\".\n\n");
  assertEquals(0, matches.size());
  matches = tool
      .check("Aquesta és una sentència múltiple amb claudàtors: "
          + "[Ací hi ha un claudàtor. Amb algun text. I ací continua.\n\n");
  assertEquals(1, matches.size());
  
  matches = tool
      .check("«Els manaments diuen: \"No desitjaràs la dona del teu veí\"»");
  //assertEquals(0, matches.size());
          
  matches = tool
      .check("Aquesta és una sentència múltiple amb parèntesis "
          + "(Ací hi ha un parèntesi. \n\n Amb algun text.) i ací continua.");
  assertEquals(0, matches.size());
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:31,代码来源:CatalanUnpairedBracketsRuleTest.java

示例6: enableOnlySpecifiedRules

import org.languagetool.JLanguageTool; //导入方法依赖的package包/类
private void enableOnlySpecifiedRules(String[] ruleIds, JLanguageTool languageTool) {
  for (Rule rule : languageTool.getAllRules()) {
    languageTool.disableRule(rule.getId());
  }
  for (String ruleId : ruleIds) {
    languageTool.enableRule(ruleId);
  }
  warnOnNonExistingRuleIds(ruleIds, languageTool);
  System.out.println("Only these rules are enabled: " + Arrays.toString(ruleIds));
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:11,代码来源:SentenceSourceChecker.java

示例7: activateAdditionalCategories

import org.languagetool.JLanguageTool; //导入方法依赖的package包/类
private void activateAdditionalCategories(String[] additionalCategoryIds, JLanguageTool languageTool) {
  if (additionalCategoryIds != null) {
    for (String categoryId : additionalCategoryIds) {
      for (Rule rule : languageTool.getAllRules()) {
        CategoryId id = rule.getCategory().getId();
        if (id != null && id.toString().equals(categoryId)) {
          System.out.println("Activating " + rule.getId() + " in category " + categoryId);
          languageTool.enableRule(rule.getId());
        }
      }
    }
  }
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:14,代码来源:SentenceSourceChecker.java

示例8: activateCategory

import org.languagetool.JLanguageTool; //导入方法依赖的package包/类
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());
    }
  }
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:9,代码来源:AtomFeedChecker.java

示例9: enableWikipediaRules

import org.languagetool.JLanguageTool; //导入方法依赖的package包/类
private void enableWikipediaRules(JLanguageTool langTool) {
  List<Rule> allRules = langTool.getAllRules();
  for (Rule rule : allRules) {
    if (rule.getCategory().getName().equals("Wikipedia")) {
      langTool.enableRule(rule.getId());
    }
  }
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:9,代码来源:WikipediaQuickCheck.java

示例10: 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

示例11: main

import org.languagetool.JLanguageTool; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
  if (args.length != 2) {
    System.out.println("Usage: " + RuleNumberScalabilityTest.class.getSimpleName() + " <languageCode> <text_file>");
    System.exit(1);
  }
  JLanguageTool langTool = new JLanguageTool(Languages.getLanguageForShortCode(args[0]));
  String text = StringTools.readStream(new FileInputStream(args[1]), "utf-8");
  System.out.println("Warmup...");
  langTool.check(text);
  langTool.check(text);

  long baselineTime = getBaselineTime(langTool, text);
  System.out.println("Baseline: " + baselineTime + "ms (time with no pattern rules active)");

  int ruleNumber = langTool.getAllActiveRules().size();
  System.out.println("Total rules: " + ruleNumber);
  int steps = 5;
  int prevActiveRules = -1;
  long prevCleanRunTime = -1;
  for (int i = steps; i > 0; i--) {
    int targetActiveRules = ruleNumber / i;
    deactivateAllRules(langTool);
    for (Rule rule : langTool.getAllRules()) {
      langTool.enableRule(rule.getId());
      if (langTool.getAllActiveRules().size() > targetActiveRules) {
        break;
      }
    }
    int activeRules = langTool.getAllActiveRules().size();
    long startTime = System.currentTimeMillis();
    langTool.check(text);
    long runTime = System.currentTimeMillis() - startTime;
    long cleanRunTime = runTime - baselineTime;
    if (prevActiveRules != -1 && prevCleanRunTime != -1) {
      float ruleFactor = (float)activeRules / prevActiveRules;
      float cleanRuntimeFactor = (float)cleanRunTime / prevCleanRunTime;
      System.out.println("Active rules: " + activeRules + ", runtime: " + runTime + "ms, cleanRunTime: " + cleanRunTime
        + ", ruleFactor: " + ruleFactor + ", cleanRuntimeFactor: " + cleanRuntimeFactor);
    } else {
      System.out.println("Active rules: " + activeRules + ", runtime: " + runTime + "ms, cleanRunTime: " + cleanRunTime);
    }
    prevActiveRules = activeRules;
    prevCleanRunTime = cleanRunTime;
  }
  System.out.println("ruleFactor = the number of rules compared to the previous run");
  System.out.println("cleanRuntimeFactor = the runtime (without baseline) compared to the previous run");
  System.out.println(" => cleanRuntimeFactor should not grow much more than ruleFactor, otherwise we scale");
  System.out.println(" => badly with respect to the number of rules");
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:50,代码来源:RuleNumberScalabilityTest.java

示例12: enableOnlyOneRule

import org.languagetool.JLanguageTool; //导入方法依赖的package包/类
private void enableOnlyOneRule(JLanguageTool lt, Rule ruleToActivate) {
  for (Rule rule : lt.getAllRules()) {
    lt.disableRule(rule.getId());
  }
  lt.enableRule(ruleToActivate.getId());
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:7,代码来源:RuleTest.java


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