Package org.languagetool.rules

Examples of org.languagetool.rules.RuleMatch


        // LEN create a new RuleMatch object, passing in the rule itself, the pos of the previous token, the
        //     length of the prev token, the repetition msg, and the short version of the repetition msg
        //     This results in the specific violation of the rule being shown in the popup
        // LEN Note: not multiple rules, but multiple suggestions, therefore we need to
        //     use RuleMatch.setSuggestedReplacements(final List<String> replacement)
        final RuleMatch ruleMatch = new RuleMatch(this, prevPos, pos+prevToken.length(), msg,
                messages.getString("desc_repetition_short"));
        final List<String> replacementSuggs = new ArrayList<>(); // LEN create empty list of suggestion strings
        replacementSuggs.add(prevToken+" "+token)// LEN case 1: replace zero-width space w/ real space
        replacementSuggs.add(prevToken);      // LEN case 2: remove repeated word - same as original suggestion
        replacementSuggs.add(prevToken+"ៗ");      // LEN case 3: same as case 2, just add "repetition character"
        ruleMatch.setSuggestedReplacements(replacementSuggs); // LEN the suggestions to use
        ruleMatches.add(ruleMatch); // LEN add rule to list of rules
      }
      prevToken = token;
    }
View Full Code Here


      String preContext = xPath.evaluate("precontext", error);
      String errorText = preContext + " " + string;
      int fromPos = text.getPlainText().indexOf(errorText) + preContext.length() + 1;
      int toPos = fromPos + string.length();
      NodeList suggestions = (NodeList)xPath.evaluate("suggestions", error, XPathConstants.NODESET);
      RuleMatch ruleMatch = new RuleMatch(new AtdRule(),
              text.getOriginalTextPositionFor(fromPos), text.getOriginalTextPositionFor(toPos), description);
      for (int j = 0; j < suggestions.getLength(); j++) {
        Node option = suggestions.item(j);
        String optionStr = xPath.evaluate("option", option);
        ruleMatch.setSuggestedReplacement(optionStr);
      }
      matches.add(ruleMatch);
    }
    return matches;
  }
View Full Code Here

  }

  protected List<RuleMatch> getRuleMatches(final String word, final int startPos) throws IOException {
    final List<RuleMatch> ruleMatches = new ArrayList<>();
    if (isMisspelled(speller1, word)) {
      final RuleMatch ruleMatch = new RuleMatch(this, startPos, startPos
          + word.length(), messages.getString("spelling"),
          messages.getString("desc_spelling_short"));
      List<String> suggestions = speller1.getSuggestions(word);
      if (suggestions.size() == 0 && word.length() >= 5) {
        // speller1 uses a maximum edit distance of 1, it won't find suggestion for "garentee", "greatful" ezc.
        suggestions.addAll(speller2.getSuggestions(word));
      }
      suggestions.addAll(0, getAdditionalTopSuggestions(suggestions, word));
      suggestions.addAll(getAdditionalSuggestions(suggestions, word));
      if (!suggestions.isEmpty()) {
        ruleMatch.setSuggestedReplacements(orderSuggestions(suggestions, word));
      }
      ruleMatches.add(ruleMatch);
    }
    return ruleMatches;
  }
View Full Code Here

      boolean isAlphabetic = true;
      if (word.length() == 1) { // hunspell dictionaries usually do not contain punctuation
        isAlphabetic = Character.isAlphabetic(word.charAt(0));
      }
      if (isAlphabetic && !word.equals("--") && hunspellDict.misspelled(word)) {
        final RuleMatch ruleMatch = new RuleMatch(this,
            len, len + word.length(),
            messages.getString("spelling"),
            messages.getString("desc_spelling_short"));
        final List<String> suggestions = getSuggestions(word);
        suggestions.addAll(0, getAdditionalTopSuggestions(suggestions, word));
        suggestions.addAll(getAdditionalSuggestions(suggestions, word));
        if (!suggestions.isEmpty()) {
          ruleMatch.setSuggestedReplacements(suggestions);
        }
        ruleMatches.add(ruleMatch);
      }
      len += word.length() + 1;
    }
View Full Code Here

    //This is just heuristics, checking word count
    if (sourceText.getTokensWithoutWhitespace().length > 3
        && getPureText(sourceText).equals(getPureText(targetText))) {
      final AnalyzedTokenReadings[] tokens = targetText.getTokens();
      final int len = tokens[tokens.length - 1].getStartPos() + tokens[tokens.length - 1].getToken().length();
      return new RuleMatch[] { new RuleMatch(this, 1, len, getMessage()) };
    }
    return new RuleMatch[0];
  }
View Full Code Here

      AnalyzedSentence targetText) throws IOException {
  
    if (isLengthDifferent(getPureText(sourceText), getPureText(targetText))) {
      final AnalyzedTokenReadings[] tokens = targetText.getTokens();
      final int len = tokens[tokens.length - 1].getStartPos() + tokens[tokens.length - 1].getToken().length();
      return new RuleMatch[] { new RuleMatch(this, 0, len, getMessage()) };
    }
    return new RuleMatch[0];
  }
View Full Code Here

  public void testPositionsWithEnglish() throws IOException {
    final JLanguageTool tool = new JLanguageTool(new AmericanEnglish());
    final List<RuleMatch> matches = tool.check("A sentence with no period\n" +
        "A sentence. A typoh.");
    assertEquals(1, matches.size());
    final RuleMatch match = matches.get(0);
    assertEquals(1, match.getLine());
    assertEquals(15, match.getColumn());
  }
View Full Code Here

  public void testPositionsWithEnglishTwoLineBreaks() throws IOException {
    final JLanguageTool tool = new JLanguageTool(new AmericanEnglish());
    final List<RuleMatch> matches = tool.check("This sentence.\n\n" +
        "A sentence. A typoh.");
    assertEquals(1, matches.size());
    final RuleMatch match = matches.get(0);
    assertEquals(2, match.getLine());
    assertEquals(14, match.getColumn());   // TODO: should actually be 15, as in testPositionsWithEnglish()
  }
View Full Code Here

    List<RuleMatch> ruleMatches = super.getRuleMatches(word, startPos);
    if (ruleMatches.size() > 0) {
      // so 'word' is misspelled:
      IrregularForms forms = getIrregularFormsOrNull(word);
      if (forms != null) {
        RuleMatch oldMatch = ruleMatches.get(0);
        RuleMatch newMatch = new RuleMatch(this, oldMatch.getFromPos(), oldMatch.getToPos(),
                "Possible spelling mistake. Did you mean <suggestion>" + forms.forms.get(0) +
                "</suggestion>, the irregular " + forms.formName + " form of the " + forms.posName +
                " '" + forms.baseform + "'?");
        List<String> allSuggestions = new ArrayList<>();
        allSuggestions.addAll(forms.forms);
        for (String repl : oldMatch.getSuggestedReplacements()) {
          if (!allSuggestions.contains(repl)) {
            allSuggestions.add(repl);
          }
        }
        newMatch.setSuggestedReplacements(allSuggestions);
        ruleMatches.set(0, newMatch);
      }
    }
    return ruleMatches;
  }
View Full Code Here

        }
        msg = "Use <suggestion>" + replacement + "</suggestion> instead of '" + prevToken + "' if the following "+
            "word doesn't start with a vowel sound, e.g. 'a sentence', 'a university'";
      }
      if (msg != null) {
        final RuleMatch ruleMatch = new RuleMatch(this, prevPos, prevPos + prevToken.length(), msg, "Wrong article");
        ruleMatches.add(ruleMatch);
      }
      if (tokens[i].hasPosTag("DT")) {
        prevToken = token;
        prevPos = tokens[i].getStartPos();
View Full Code Here

TOP

Related Classes of org.languagetool.rules.RuleMatch

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.