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


Java JLanguageTool.getAllActiveRules方法代码示例

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


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

示例1: testWordListValidity

import org.languagetool.JLanguageTool; //导入方法依赖的package包/类
@Test
public void testWordListValidity() throws IOException {
  Set<String> checked = new HashSet<>();
  for (Language lang : Languages.get()) {
    if (lang.getShortCode().equals("ru")) {
      // skipping, Cyrillic chars not part of the validation yet
      continue;
    }
    JLanguageTool lt = new JLanguageTool(lang);
    List<Rule> rules = lt.getAllActiveRules();
    for (Rule rule : rules) {
      if (rule instanceof SpellingCheckRule) {
        SpellingCheckRule sRule = (SpellingCheckRule) rule;
        String file = sRule.getSpellingFileName();
        if (JLanguageTool.getDataBroker().resourceExists(file) && !checked.contains(file)) {
          System.out.println("Checking " + file);
          CachingWordListLoader loader = new CachingWordListLoader();
          List<String> words = loader.loadWords(file);
          validateWords(words, file);
          checked.add(file);
        }
      }
    }
  }
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:26,代码来源:WordListValidatorTest.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: run

import org.languagetool.JLanguageTool; //导入方法依赖的package包/类
private void run(Language lang) throws IOException {
  File basePath = new File("/lt/git/languagetool/languagetool-language-modules");
  if (!basePath.exists()) {
    throw new RuntimeException("basePath does not exist: " + basePath);
  }
  String langCode = lang.getShortCode();
  File xml = new File(basePath, "/" + langCode + "/src/main/resources/org/languagetool/rules/" + langCode + "/grammar.xml");
  List<String> xmlLines = IOUtils.readLines(new FileReader(xml));
  JLanguageTool tool = new JLanguageTool(lang);
  for (Rule rule : tool.getAllActiveRules()) {
    if (!(rule instanceof PatternRule)) {
      continue;
    }
    List<CorrectExample> correctExamples = rule.getCorrectExamples();
    List<IncorrectExample> incorrectExamples = rule.getIncorrectExamples();
    for (IncorrectExample incorrectExample : incorrectExamples) {
      checkCorrections(rule, correctExamples, incorrectExample, xmlLines);
    }
  }
  System.err.println("Useless examples: " + uselessExampleCount);
  System.err.println("Removed lines: " + removedLinesCount);
  for (String xmlLine : xmlLines) {
    System.out.println(xmlLine);
  }
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:26,代码来源:UselessExampleFinder.java

示例5: run

import org.languagetool.JLanguageTool; //导入方法依赖的package包/类
private void run(Language lang) throws IOException {
  File basePath = new File("/home/dnaber/lt/git/languagetool/languagetool-language-modules");
  if (!basePath.exists()) {
    throw new RuntimeException("basePath does not exist: " + basePath);
  }
  JLanguageTool tool = new JLanguageTool(lang);
  System.out.println("<html>");
  System.out.println("<head>");
  System.out.println("  <title>LanguageTool examples sentences</title>");
  System.out.println("  <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />");
  System.out.println("</head>");
  System.out.println("<body>");
  int i = 1;
  for (Rule rule : tool.getAllActiveRules()) {
    List<IncorrectExample> incorrectExamples = rule.getIncorrectExamples();
    if (incorrectExamples.size() > 0) {
      String example = incorrectExamples.get(0).getExample()
              .replace("<marker>", "<b>")
              .replace("</marker>", "</b>");
      System.out.println(i + ". " + example + " [" + rule.getId() + "]<br>");
      i++;
    }
  }
  System.out.println("</body>");
  System.out.println("</html>");
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:27,代码来源:ExampleSentencePrinter.java

示例6: Helper

import org.languagetool.JLanguageTool; //导入方法依赖的package包/类
@Autowired
public Helper(final CloudantClient cloudantClient,
              WolframRepository wolframRepository,
              @Value("${cloudant.chatDB}") String chatDBName,
              @Value("${cloudant.feedbackDB}") String feedbackDBName,
              @Value("${cloudant.explorerDB}") String explorerDBName,
              @Value("${tmdb.apiKey}") String tmdbApiKey) {
    try {
        chatDB = cloudantClient.database(chatDBName, true);
        feedbackDB = cloudantClient.database(feedbackDBName, true);
        explorerDB = cloudantClient.database(explorerDBName, true);
    }
    catch(Exception e) {
        logger.info("ERROR HERE");
        e.printStackTrace();
    }
    finally {
        this.tmdbApiKey = tmdbApiKey;
        this.wolframRepository = wolframRepository;

        riveScriptBot = new RiveScriptBot();
        eliza = new ElizaMain();
        eliza.readScript(true, "src/main/resources/eliza/script");

        sparql = new SPARQL(explorerDB);
        languageTool = new JLanguageTool(new AmericanEnglish());
        for (Rule rule : languageTool.getAllActiveRules()) {
            if (rule instanceof SpellingCheckRule) {
                List<String> wordsToIgnore = Arrays.asList("nlp");
                ((SpellingCheckRule) rule).addIgnoreTokens(wordsToIgnore);
            }
        }
    }
}
 
开发者ID:dbpedia,项目名称:chatbot,代码行数:35,代码来源:Application.java

示例7: setupSpellCheckTool

import org.languagetool.JLanguageTool; //导入方法依赖的package包/类
private void setupSpellCheckTool() {     
    painter = new DefaultHighlighter.DefaultHighlightPainter(Color.PINK);  //Default color is: PINK
    langTool = new JLanguageTool(new AmericanEnglish());    //Default Language is: American English
    for (Rule rule : langTool.getAllActiveRules()) {
        if (rule instanceof SpellingCheckRule) {
            ((SpellingCheckRule)rule).acceptPhrases(getLatexTerms());  //Accept LaText Terms from tex.cwl
            ((SpellingCheckRule)rule).acceptPhrases(Arrays.asList("documentclass", "maketitle", "tex", "TEX", "Tex"));  //Accept some TEX terms not contained in tex.cwl
        }
    }
    
    autoCheckThread = new Thread(new SpellCheckService(this));
    autoCheckThread.start();
}
 
开发者ID:sebbrudzinski,项目名称:Open-LaTeX-Studio,代码行数:14,代码来源:EditorTopComponent.java

示例8: getBracketsRule

import org.languagetool.JLanguageTool; //导入方法依赖的package包/类
public static GenericUnpairedBracketsRule getBracketsRule(JLanguageTool langTool) {
  for (Rule rule : langTool.getAllActiveRules()) {
    if (rule instanceof GenericUnpairedBracketsRule) {
      return (GenericUnpairedBracketsRule)rule;
    }
  }
  throw new RuntimeException("Rule not found: " + GenericUnpairedBracketsRule.class);
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:9,代码来源:GenericUnpairedBracketsRuleTest.java

示例9: profileRulesOnText

import org.languagetool.JLanguageTool; //导入方法依赖的package包/类
/**
 * 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) {
      continue; // profile rules for sentences only
    }
    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();
  }
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:39,代码来源:CommandLineTools.java

示例10: initExampleSentences

import org.languagetool.JLanguageTool; //导入方法依赖的package包/类
private void initExampleSentences(Language language) throws IOException {
  JLanguageTool lt = new JLanguageTool(language);
  List<Rule> rules = lt.getAllActiveRules();
  List<ExampleSentence> sentences = new ArrayList<>();
  for (Rule rule : rules) {
    if (rule instanceof AbstractPatternRule && !rule.isDefaultOff()) {
      List<IncorrectExample> incorrectExamples = rule.getIncorrectExamples();
      for (IncorrectExample incorrectExample : incorrectExamples) {
        ExampleSentence sentence = new ExampleSentence(incorrectExample.getExample(), rule.getId());
        sentences.add(sentence);
      }
    }
  }
  languageToExamples.put(language, sentences);
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:16,代码来源:ExampleSentenceProvider.java

示例11: createIndex

import org.languagetool.JLanguageTool; //导入方法依赖的package包/类
private int createIndex(JLanguageTool lt) throws IOException {
  int ruleCount = 0;
  try (Indexer indexer = new Indexer(directory, lt.getLanguage())) {
    List<Rule> rules = lt.getAllActiveRules();
    for (Rule rule : rules) {
      if (rule instanceof PatternRule && !rule.isDefaultOff()) {
        PatternRule patternRule = (PatternRule) rule;
        List<IncorrectExample> incorrectExamples = rule.getIncorrectExamples();
        Document doc = new Document();
        FieldType idType = new FieldType();
        idType.setStored(true);
        idType.setTokenized(false);
        doc.add(new Field("ruleId", patternRule.getFullId(), idType));
        for (IncorrectExample incorrectExample : incorrectExamples) {
          String example = incorrectExample.getExample().replaceAll("</?marker>", "");
          FieldType fieldType = new FieldType();
          fieldType.setStored(true);
          fieldType.setTokenized(true);
          fieldType.setIndexOptions(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS);
          doc.add(new Field(FIELD_NAME, example, fieldType));
          // no lowercase here, it would lowercase the input to the LT analysis, leading to wrong POS tags:
          doc.add(new Field(FIELD_NAME_LOWERCASE, example, fieldType));
        }
        indexer.add(doc);
        ruleCount++;
      }
    }
  }
  errorSearcher = new Searcher(directory);
  return ruleCount;
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:32,代码来源:IndexerSearcherTest.java

示例12: run

import org.languagetool.JLanguageTool; //导入方法依赖的package包/类
private void run(Language lang) throws IOException {
  File basePath = new File("/lt/git/languagetool/languagetool-language-modules");
  if (!basePath.exists()) {
    throw new RuntimeException("basePath does not exist: " + basePath);
  }
  String langCode = lang.getShortCode();
  File xml = new File(basePath, "/" + langCode + "/src/main/resources/org/languagetool/rules/" + langCode + "/grammar.xml");
  List<String> xmlLines = IOUtils.readLines(new FileReader(xml));
  JLanguageTool tool = new JLanguageTool(lang);
  int totalRules = 0;
  for (Rule rule : tool.getAllActiveRules()) {
    if (!(rule instanceof PatternRule)) {
      continue;
    }
    PatternRule patternRule = (PatternRule) rule;
    String id = patternRule.getFullId();
    if (isSimple((PatternRule)rule)) {
      System.err.println("Simplifying: " + id);
      simplify(patternRule, xmlLines);
    } else {
      System.err.println("Can't simplify: " + id);
    }
    totalRules++;
  }
  System.err.println("touchedRulesCount: " + touchedRulesCount + " out of " + totalRules);
  for (String xmlLine : xmlLines) {
    System.out.println(xmlLine);
  }
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:30,代码来源:RuleSimplifier.java

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

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

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


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