Examples of JLanguageTool


Examples of org.languagetool.JLanguageTool

public class CompoundRuleTest extends CompoundRuleTestAbs {

  @Override
  protected void setUp() throws Exception {
    super.setUp();
    langTool = new JLanguageTool(new Swedish());
    rule = new CompoundRule(null);
  }
View Full Code Here

Examples of org.languagetool.JLanguageTool

    final File file = new File(xmlFileName);
    if (!file.exists() || !file.isFile()) {
      throw new IOException("File doesn't exist or isn't a file: " + xmlFileName);
    }
    final Language lang = Language.getLanguageForShortName(langCode);
    final JLanguageTool languageTool = new JLanguageTool(lang);
    languageTool.activateDefaultPatternRules();
    if (ruleIds != null) {
      enableSpecifiedRules(ruleIds, languageTool);
    } else {
      applyRuleDeactivation(languageTool, disabledRules);
    }
View Full Code Here

Examples of org.languagetool.JLanguageTool

    }
    return matchingSentences;
  }

  private JLanguageTool getLanguageToolWithOneRule(Language lang, PatternRule patternRule) throws IOException {
    final JLanguageTool langTool = new JLanguageTool(lang);
    for (Rule rule : langTool.getAllActiveRules()) {
      langTool.disableRule(rule.getId());
    }
    langTool.addRule(patternRule);
    return langTool;
  }
View Full Code Here

Examples of org.languagetool.JLanguageTool

    @Override
    public void run() {
      try {
        final Sort sort = new Sort(new SortField("docCount", SortField.Type.INT))// do not sort by relevance as this will move the shortest documents to the top
        final long t1 = System.currentTimeMillis();
        final JLanguageTool languageTool = getLanguageToolWithOneRule(language, rule);
        final long langToolCreationTime = System.currentTimeMillis() - t1;
        final long t2 = System.currentTimeMillis();
        final PossiblyLimitedTopDocs limitedTopDocs = getTopDocs(query, sort);
        final long luceneTime = System.currentTimeMillis() - t2;
        final long t3 = System.currentTimeMillis();
View Full Code Here

Examples of org.languagetool.JLanguageTool

  }

  MarkupAwareWikipediaResult checkWikipediaMarkup(URL url, MediaWikiContent wikiContent, Language language) throws IOException {
    final SwebleWikipediaTextFilter filter = new SwebleWikipediaTextFilter();
    final PlainTextMapping mapping = filter.filter(wikiContent.getContent());
    final JLanguageTool langTool = getLanguageTool(language);
    final List<AppliedRuleMatch> appliedMatches = new ArrayList<AppliedRuleMatch>();
    final List<RuleMatch> matches = langTool.check(mapping.getPlainText());
    int internalErrors = 0;
    for (RuleMatch match : matches) {
      final SuggestionReplacer replacer = new SuggestionReplacer(mapping, wikiContent.getContent());
      try {
        final List<RuleMatchApplication> ruleMatchApplications = replacer.applySuggestionsToOriginalText(match);
View Full Code Here

Examples of org.languagetool.JLanguageTool

    }
    return new MarkupAwareWikipediaResult(wikiContent, appliedMatches, internalErrors);
  }

  public WikipediaQuickCheckResult checkPage(String plainText, Language lang) throws IOException {
    final JLanguageTool langTool = getLanguageTool(lang);
    final List<RuleMatch> ruleMatches = langTool.check(plainText);
    return new WikipediaQuickCheckResult(plainText, ruleMatches, lang.getShortName());
  }
View Full Code Here

Examples of org.languagetool.JLanguageTool

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

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

Examples of org.languagetool.JLanguageTool

   */
  private Map<Language, Set<String>> getLanguageToIgnoreTokensMapping() throws IOException {
    final Map<Language, Set<String>> langToIgnoreTokens = new HashMap<>();
    for (Language lang : Language.REAL_LANGUAGES) {
      final Set<String> suggestionTokens = new HashSet<>();
      final JLanguageTool languageTool = new JLanguageTool(lang);
      final Rule spellcheckRule = getSpellcheckRule(languageTool);
      if (spellcheckRule == null) {
        System.out.println("No spellchecker rule found for " + lang);
        continue;
      }
      languageTool.activateDefaultPatternRules();
      final List<Rule> rules = languageTool.getAllRules();
      int tokenCount = 0;
      int noErrorCount = 0;
      for (Rule rule : rules) {
        final List<String> tokens = getSuggestionTokens(rule, lang);
        tokenCount += tokens.size();
        for (String token : tokens) {
          final AnalyzedSentence sentence = languageTool.getAnalyzedSentence(token);
          final RuleMatch[] matches = spellcheckRule.match(sentence);
          if (matches.length > 0) {
            suggestionTokens.add(token);
          } else {
            //System.out.println("No error matches for " + lang + ": " + token);
View Full Code Here

Examples of org.languagetool.JLanguageTool

  private final SentenceTokenizer sentenceTokenizer;

  public Indexer(Directory dir, Language language) {
    try {
      final Map<String, Analyzer> analyzerMap = new HashMap<String, Analyzer>();
      analyzerMap.put(FIELD_NAME, new LanguageToolAnalyzer(LUCENE_VERSION, new JLanguageTool(language), false));
      analyzerMap.put(FIELD_NAME_LOWERCASE, new LanguageToolAnalyzer(LUCENE_VERSION, new JLanguageTool(language), true));
      final Analyzer analyzer = new PerFieldAnalyzerWrapper(new DoNotUseAnalyzer(), analyzerMap);
      final IndexWriterConfig writerConfig = new IndexWriterConfig(LUCENE_VERSION, analyzer);
      writerConfig.setOpenMode(OpenMode.CREATE);
      writer = new IndexWriter(dir, writerConfig);
      sentenceTokenizer = language.getSentenceTokenizer();
View Full Code Here

Examples of org.languagetool.JLanguageTool

    assertMatches(" Eurlings: “De gegevens van de dienst zijn van cruciaal belang voor de veiligheid van de luchtvaart en de scheepvaart.", 1);
  }

  private void setUpRule(Language language) throws IOException {
    rule = new GenericUnpairedBracketsRule(TestTools.getEnglishMessages(), language);
    langTool = new JLanguageTool(language);
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.