Package org.languagetool

Examples of org.languagetool.MultiThreadedJLanguageTool


  }

  private void initLanguageTool() {
    try {
      prepareConfig(docLanguage);
      langTool = new MultiThreadedJLanguageTool(docLanguage, config.getMotherTongue());
      langTool.activateDefaultPatternRules();
      langTool.activateDefaultFalseFriendRules();
      for (Rule rule : langTool.getAllActiveRules()) {
        if (rule.isDictionaryBasedSpellingRule()) {
          langTool.disableRule(rule.getId());
View Full Code Here


    for (int i = 0; i < RUNS; i++) {
      int beginIndex = rnd.nextInt(text.length());
      int endIndex = Math.min(beginIndex + MAX_TEXT_LENGTH, text.length()-1);
      String subText = text.substring(beginIndex, endIndex);
      long startTime = System.currentTimeMillis();
      JLanguageTool langTool = new MultiThreadedJLanguageTool(language);
      langTool.activateDefaultPatternRules();
      List<RuleMatch> matches = langTool.check(subText);
      long runTime = System.currentTimeMillis() - startTime;
      if (i >= SKIP) {
        totalTime += runTime;
        System.out.println("Time: " + runTime + "ms (" + matches.size() + " matches)");
      } else {
View Full Code Here

    }
    PerformanceTest test = new PerformanceTest();
    String languageCode = args[0];
    File textFile = new File(args[1]);
    //JLanguageTool langTool = new JLanguageTool(Language.getLanguageForShortName(languageCode));
    JLanguageTool langTool = new MultiThreadedJLanguageTool(Language.getLanguageForShortName(languageCode));
    test.run(langTool, textFile);
  }
View Full Code Here

      //FIXME
      //no need to read again the file
      config = new Configuration(new File(System.getProperty("user.home")), CONFIG_FILE, language);
      //config still contains old language, update it
      this.config.setLanguage(language);
      languageTool = new MultiThreadedJLanguageTool(language, config.getMotherTongue());
      languageTool.activateDefaultPatternRules();
      languageTool.activateDefaultFalseFriendRules();
      loadConfig();
    } catch (Exception e) {
      throw new RuntimeException(e);
View Full Code Here

    }
    return new MediaWikiContent(handler.getRevisionContent(), handler.getTimestamp());
  }

  private JLanguageTool getLanguageTool(Language lang) throws IOException {
    final JLanguageTool langTool = new MultiThreadedJLanguageTool(lang);
    langTool.activateDefaultPatternRules();
    enableWikipediaRules(langTool);
    for (String disabledRuleId : disabledRuleIds) {
      langTool.disableRule(disabledRuleId);
    }
    disableSpellingRules(langTool);
    return langTool;
  }
View Full Code Here

    this.singleLineBreakMarksParagraph = singleLineBreakMarksParagraph;
    profileRules = false;
    bitextMode = false;
    srcLt = null;
    bRules = null;
    lt = new MultiThreadedJLanguageTool(language, motherTongue);
    lt.activateDefaultPatternRules();
    lt.activateDefaultFalseFriendRules();
    if (languageModelIndexDir != null) {
      lt.activateLanguageModelRules(languageModelIndexDir);
    }
View Full Code Here

  private void setBitextMode(final Language sourceLang,
      final String[] disabledRules, final String[] enabledRules) throws IOException, ParserConfigurationException, SAXException {
    bitextMode = true;
    final Language target = lt.getLanguage();
    lt = new MultiThreadedJLanguageTool(target, null);
    srcLt = new MultiThreadedJLanguageTool(sourceLang);
    lt.activateDefaultPatternRules();
    Tools.selectRules(lt, disabledRules, enabledRules);
    Tools.selectRules(srcLt, disabledRules, enabledRules);
    bRules = Tools.getBitextRules(sourceLang, lt.getLanguage());
View Full Code Here

  }

  private void changeLanguage(Language language, Language motherTongue,
                              String[] disabledRules, String[] enabledRules) {
    try {
      lt = new MultiThreadedJLanguageTool(language, motherTongue);
      lt.activateDefaultPatternRules();
      lt.activateDefaultFalseFriendRules();
      Tools.selectRules(lt, disabledRules, enabledRules);
      if (verbose) {
        lt.setOutput(System.err);
View Full Code Here

  }

  private void run(File propFile, Set<String> disabledRules, String langCode, List<String> fileNames, String[] ruleIds,
                   String[] additionalCategoryIds, int maxSentences, int maxErrors, File languageModelDir) throws IOException {
    final Language lang = Language.getLanguageForShortName(langCode);
    final JLanguageTool languageTool = new MultiThreadedJLanguageTool(lang);
    languageTool.activateDefaultPatternRules();
    if (languageModelDir != null) {
      languageTool.activateLanguageModelRules(languageModelDir);
    }
    if (ruleIds != null) {
      enableOnlySpecifiedRules(ruleIds, languageTool);
    } else {
      applyRuleDeactivation(languageTool, disabledRules);
    }
    activateAdditionalCategories(additionalCategoryIds, languageTool);
    disableSpellingRules(languageTool);
    System.out.println("Working on: " + StringUtils.join(fileNames, ", "));
    System.out.println("Sentence limit: " + (maxSentences > 0 ? maxSentences : "no limit"));
    System.out.println("Error limit: " + (maxErrors > 0 ? maxErrors : "no limit"));

    ResultHandler resultHandler = null;
    int ruleMatchCount = 0;
    int sentenceCount = 0;
    try {
      if (propFile != null) {
        resultHandler = new DatabaseHandler(propFile, maxSentences, maxErrors);
      } else {
        resultHandler = new StdoutHandler(maxSentences, maxErrors);
      }
      MixingSentenceSource mixingSource = MixingSentenceSource.create(fileNames, lang);
      while (mixingSource.hasNext()) {
        Sentence sentence = mixingSource.next();
        try {
          List<RuleMatch> matches = languageTool.check(sentence.getText());
          resultHandler.handleResult(sentence, matches, lang);
          sentenceCount++;
          if (sentenceCount % 5000 == 0) {
            System.err.printf("%s sentences checked...\n", NumberFormat.getNumberInstance(Locale.US).format(sentenceCount));
          }
View Full Code Here

TOP

Related Classes of org.languagetool.MultiThreadedJLanguageTool

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.