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


Java JLanguageTool.disableRule方法代码示例

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


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

示例1: testHintsForDemoLanguage

import org.languagetool.JLanguageTool; //导入方法依赖的package包/类
@Test
public void testHintsForDemoLanguage() throws IOException, ParserConfigurationException, SAXException {
  JLanguageTool langTool1 = new JLanguageTool(new BritishEnglish(), new German());
  langTool1.disableRule(MorfologikBritishSpellerRule.RULE_ID);
  List<RuleMatch> matches1 = assertErrors(1, "And forDemoOnly.", langTool1);
  assertEquals("DEMO_ENTRY", matches1.get(0).getRule().getId());

  JLanguageTool langTool2 = new JLanguageTool(new English(), new German());
  langTool2.disableRule(MorfologikBritishSpellerRule.RULE_ID);
  List<RuleMatch> matches2 = assertErrors(1, "And forDemoOnly.", langTool2);
  assertEquals("DEMO_ENTRY", matches2.get(0).getRule().getId());

  JLanguageTool langTool3 = new JLanguageTool(new AmericanEnglish(), new German());
  langTool3.disableRule(MorfologikAmericanSpellerRule.RULE_ID);
  assertErrors(0, "And forDemoOnly.", langTool3);
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:17,代码来源:FalseFriendRuleTest.java

示例2: testIgnorePhrases

import org.languagetool.JLanguageTool; //导入方法依赖的package包/类
@Test
public void testIgnorePhrases() throws IOException {
  JLanguageTool lt = new JLanguageTool(new GermanyGerman());
  assertThat(lt.check("Ein Test mit Auriensis Fantasiewortus").size(), is(2));
  for (Rule rule : lt.getAllActiveRules()) {
    if (rule instanceof SpellingCheckRule) {
      ((SpellingCheckRule) rule).acceptPhrases(Arrays.asList("Auriensis Fantasiewortus", "fudeldu laberwort"));
    } else {
      lt.disableRule(rule.getId());
    }
  }
  assertThat(lt.check("Ein Test mit Auriensis Fantasiewortus").size(), is(0));
  assertThat(lt.check("Ein Test mit Auriensis und Fantasiewortus").size(), is(2));  // the words on their own are not ignored
  assertThat(lt.check("fudeldu laberwort").size(), is(0));
  assertThat(lt.check("Fudeldu laberwort").size(), is(0));  // Uppercase at sentence start is okay
  assertThat(lt.check("Fudeldu Laberwort").size(), is(2));  // Different case somewhere other than at sentence start is not okay
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:18,代码来源:SpellingCheckRuleTest.java

示例3: testIgnorePhrases

import org.languagetool.JLanguageTool; //导入方法依赖的package包/类
@Test
public void testIgnorePhrases() throws IOException {
  JLanguageTool langTool = new JLanguageTool(new AmericanEnglish());
  assertThat(langTool.check("A test with myfoo mybar").size(), is(2));
  for (Rule rule : langTool.getAllActiveRules()) {
    if (rule instanceof SpellingCheckRule) {
      ((SpellingCheckRule) rule).acceptPhrases(Arrays.asList("myfoo mybar", "Myy othertest"));
    } else {
      langTool.disableRule(rule.getId());
    }
  }
  assertThat(langTool.check("A test with myfoo mybar").size(), is(0));
  assertThat(langTool.check("A test with myfoo and mybar").size(), is(2));  // the words on their own are not ignored
  assertThat(langTool.check("myfoo mybar here").size(), is(0));
  assertThat(langTool.check("Myfoo mybar here").size(), is(0));
  assertThat(langTool.check("MYfoo mybar here").size(), is(2));
  
  assertThat(langTool.check("Myy othertest is okay").size(), is(0));
  assertThat(langTool.check("And Myy othertest is okay").size(), is(0));
  assertThat(langTool.check("But Myy Othertest is not okay").size(), is(2));
  assertThat(langTool.check("But myy othertest is not okay").size(), is(2));
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:23,代码来源:SpellingCheckRuleTest.java

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

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

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

示例7: AtomFeedChecker

import org.languagetool.JLanguageTool; //导入方法依赖的package包/类
AtomFeedChecker(Language language, DatabaseConfig dbConfig, File languageModelDir) throws IOException {
  this.language = Objects.requireNonNull(language);
  langTool = new JLanguageTool(language);
  if (languageModelDir != null) {
    langTool.activateLanguageModelRules(languageModelDir);
  }
  // disable because they create too many false alarms:
  langTool.disableRule("UNPAIRED_BRACKETS");
  langTool.disableRule("EN_UNPAIRED_BRACKETS");
  langTool.disableRule("EN_QUOTES");
  langTool.disableRule("COMMA_PARENTHESIS_WHITESPACE");
  langTool.disableRule("UPPERCASE_SENTENCE_START");
  langTool.disableRule("FRENCH_WHITESPACE");  // fr
  activateCategory("Wikipedia", langTool);
  disableSpellingRules(langTool);
  if (dbConfig != null) {
    matchDatabase = new MatchDatabase(dbConfig.getUrl(), dbConfig.getUser(), dbConfig.getPassword());
  } else {
    matchDatabase = null;
  }
  contextTools.setContextSize(CONTEXT_SIZE);
  contextTools.setErrorMarkerStart("<err>");
  contextTools.setErrorMarkerEnd("</err>");
  contextTools.setEscapeHtml(false);
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:26,代码来源:AtomFeedChecker.java

示例8: disableSpellingRules

import org.languagetool.JLanguageTool; //导入方法依赖的package包/类
private void disableSpellingRules(JLanguageTool languageTool) {
  List<Rule> allRules = languageTool.getAllRules();
  for (Rule rule : allRules) {
    if (rule instanceof SpellingCheckRule) {
      languageTool.disableRule(rule.getId());
    }
  }
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:9,代码来源:PatternRuleTest.java

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

示例10: disableSpellingRules

import org.languagetool.JLanguageTool; //导入方法依赖的package包/类
private void disableSpellingRules(JLanguageTool languageTool) {
  List<Rule> allActiveRules = languageTool.getAllActiveRules();
  for (Rule rule : allActiveRules) {
    if (rule.isDictionaryBasedSpellingRule()) {
      languageTool.disableRule(rule.getId());
    }
  }
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:9,代码来源:WikipediaQuickCheck.java

示例11: getLanguageToolForSpellCheck

import org.languagetool.JLanguageTool; //导入方法依赖的package包/类
private JLanguageTool getLanguageToolForSpellCheck(Language language) {
  JLanguageTool lt = new JLanguageTool(language);
  for (Rule rule : lt.getAllActiveRules()) {
    if (!rule.isDictionaryBasedSpellingRule()) {
      lt.disableRule(rule.getId());
    }
  }
  return lt;
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:10,代码来源:SpellCheckEvaluation.java

示例12: CheckBNC

import org.languagetool.JLanguageTool; //导入方法依赖的package包/类
private CheckBNC() throws IOException {
  langTool = new JLanguageTool(new English());
  final String[] disRules = {"UPPERCASE_SENTENCE_START", "COMMA_PARENTHESIS_WHITESPACE",
      "WORD_REPEAT_RULE", "DOUBLE_PUNCTUATION"};
  System.err.println("Note: disabling the following rules:");
  for (String disRule : disRules) {
    langTool.disableRule(disRule);
    System.err.println(" " + disRule);
  }
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:11,代码来源:CheckBNC.java

示例13: evaluate

import org.languagetool.JLanguageTool; //导入方法依赖的package包/类
@SuppressWarnings("ConstantConditions")
private void evaluate(List<Sentence> sentences, boolean isCorrect, String token, String homophoneToken, List<Long> evalFactors) throws IOException {
  println("======================");
  printf("Starting evaluation on " + sentences.size() + " sentences with %s/%s:\n", token, homophoneToken);
  JLanguageTool lt = new JLanguageTool(language);
  List<Rule> allActiveRules = lt.getAllActiveRules();
  for (Rule activeRule : allActiveRules) {
    lt.disableRule(activeRule.getId());
  }
  for (Sentence sentence : sentences) {
    String textToken = isCorrect ? token : homophoneToken;
    String plainText = sentence.getText();
    String replacement = plainText.indexOf(textToken) == 0 ? StringTools.uppercaseFirstChar(token) : token;
    String replacedTokenSentence = isCorrect ? plainText : plainText.replaceFirst("(?i)\\b" + textToken + "\\b", replacement);
    AnalyzedSentence analyzedSentence = lt.getAnalyzedSentence(replacedTokenSentence);
    for (Long factor : evalFactors) {
      rule.setConfusionSet(new ConfusionSet(factor, homophoneToken, token));
      RuleMatch[] matches = rule.match(analyzedSentence);
      boolean consideredCorrect = matches.length == 0;
      String displayStr = plainText.replaceFirst("(?i)\\b" + textToken + "\\b", "**" + replacement + "**");
      if (consideredCorrect && isCorrect) {
        evalValues.get(factor).trueNegatives++;
      } else if (!consideredCorrect && isCorrect) {
        evalValues.get(factor).falsePositives++;
        println("false positive with factor " + factor + ": " + displayStr);
      } else if (consideredCorrect && !isCorrect) {
        //println("false negative: " + displayStr);
        evalValues.get(factor).falseNegatives++;
      } else {
        evalValues.get(factor).truePositives++;
        //System.out.println("true positive: " + displayStr);
      }
    }
  }
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:36,代码来源:ConfusionRuleEvaluator.java

示例14: disableSpellingRules

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

示例15: applyRuleDeactivation

import org.languagetool.JLanguageTool; //导入方法依赖的package包/类
private void applyRuleDeactivation(JLanguageTool languageTool, Set<String> disabledRules) {
  // disabled via config file, usually to avoid too many false alarms:
  for (String disabledRuleId : disabledRules) {
    languageTool.disableRule(disabledRuleId);
  }
  System.out.println("These rules are disabled: " + languageTool.getDisabledRules());
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:8,代码来源:SentenceSourceChecker.java


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