Examples of RuleMatch


Examples of org.languagetool.rules.RuleMatch

  private RuleMatch createRuleMatch(AnalyzedTokenReadings tokenReadings, List<String> replacements) {
    String tokenString = tokenReadings.getToken();
    String msg = tokenString + getSuggestion(tokenString) + StringUtils.join(replacements, ", ");
    int pos = tokenReadings.getStartPos();

    RuleMatch potentialRuleMatch = new RuleMatch(this, pos, pos + tokenString.length(), msg, getShort());

    potentialRuleMatch.setSuggestedReplacements(replacements);

    return potentialRuleMatch;
  }
View Full Code Here

Examples of org.languagetool.rules.RuleMatch

        default:
      }

      final RuleMatch[] thisMatches = rule.match(analyzedSentence);
      for (final RuleMatch element1 : thisMatches) {
        final RuleMatch thisMatch = adjustRuleMatchPos(element1,
            tokenCount, columnCount, lineCount, sentence);   
        sentenceMatches.add(thisMatch);
        if (rule.isParagraphBackTrack()) {
          rule.addRuleMatch(thisMatch);
        }
View Full Code Here

Examples of org.languagetool.rules.RuleMatch

   * @param sentence The text being checked
   * @return The RuleMatch object with adjustments.
   */
  public RuleMatch adjustRuleMatchPos(final RuleMatch match, int sentLen,
      int columnCount, int lineCount, final String sentence) {
    final RuleMatch thisMatch = new RuleMatch(match.getRule(),
        match.getFromPos() + sentLen, match.getToPos() + sentLen, match.getMessage(), match.getShortMessage());
    thisMatch.setSuggestedReplacements(match.getSuggestedReplacements());
    final String sentencePartToError = sentence.substring(0, match.getFromPos());
    final String sentencePartToEndOfError = sentence.substring(0,match.getToPos());
    final int lastLineBreakPos = sentencePartToError.lastIndexOf('\n');
    final int column;
    final int endColumn;
    if (lastLineBreakPos == -1) {
      column = sentencePartToError.length() + columnCount;
    } else {
      column = sentencePartToError.length() - lastLineBreakPos;
    }
    final int lastLineBreakPosInError = sentencePartToEndOfError.lastIndexOf('\n');
    if (lastLineBreakPosInError == -1) {
      endColumn = sentencePartToEndOfError.length() + columnCount;
    } else {
      endColumn = sentencePartToEndOfError.length() - lastLineBreakPosInError;
    }
    final int lineBreaksToError = countLineBreaks(sentencePartToError);
    final int lineBreaksToEndOfError = countLineBreaks(sentencePartToEndOfError);
    thisMatch.setLine(lineCount + lineBreaksToError);
    thisMatch.setEndLine(lineCount + lineBreaksToEndOfError);
    thisMatch.setColumn(column);
    thisMatch.setEndColumn(endColumn);
    thisMatch.setOffset(match.getFromPos() + sentLen);
    return thisMatch;
  }
View Full Code Here

Examples of org.languagetool.rules.RuleMatch

         }

      }
      if (replacement != null) {
        final String msg = "Si \u00E9s un nom o un adjectiu, ha de portar accent.";
        final RuleMatch ruleMatch = new RuleMatch(this, tokens[i].getStartPos(), tokens[i].getStartPos()+token.length(), msg, "Falta un accent");
        ruleMatch.setSuggestedReplacement(replacement);
        ruleMatches.add(ruleMatch);
      }
    }
    return toRuleMatchArray(ruleMatches);
  }
View Full Code Here

Examples of org.languagetool.rules.RuleMatch

      if (msg != null) {
        final int fromPos = tokens[i - 1].getStartPos();
        final int toPos = tokens[i - 1].getStartPos() + fixLen
            + tokens[i - 1].getToken().length();
        final RuleMatch ruleMatch = new RuleMatch(this, fromPos, toPos, msg,
            "Insérer un espace insécable");
        if (suggestionText != null) {
          ruleMatch.setSuggestedReplacement(suggestionText);
        }
        ruleMatches.add(ruleMatch);
      }
      prevToken = token;
    }
View Full Code Here

Examples of org.languagetool.rules.RuleMatch

    final String message = "Did you mean: <suggestion>where</suggestion> or <suggestion>we</suggestion>?";
    final PatternRule rule = new PatternRule("MY_ID", Language.DEMO, Collections.singletonList(element), "desc", message, "msg");
    final RuleMatch[] matches = rule.match(langTool.getAnalyzedSentence("Were are in the process of ..."));

    assertEquals(1, matches.length);
    final RuleMatch match = matches[0];
    final List<String> replacements = match.getSuggestedReplacements();
    assertEquals(2, replacements.size());
    assertEquals("Where", replacements.get(0));
    assertEquals("We", replacements.get(1));
  }
View Full Code Here

Examples of org.languagetool.rules.RuleMatch

      }

      if (repetition) {
        final String msg = "Повтор слов в предложении";
        final int pos = tokens[i].getStartPos();
        final RuleMatch ruleMatch = new RuleMatch(this, pos, pos
            + token.length(), msg, "Повтор слов в предложении");       
  //////////
  //       ruleMatch.setSuggestedReplacement(tokens[i].getAnalyzedToken(0).getLemma());
  //       example how to correct word
  //////////
View Full Code Here

Examples of org.languagetool.rules.RuleMatch

    //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

Examples of org.languagetool.rules.RuleMatch

      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

Examples of org.languagetool.rules.RuleMatch

            break;
          }
        }

        if (allElementsMatch && matchingTokens == patternSize) {
          final RuleMatch ruleMatch = createRuleMatch(tokenPositions, tokens,
              firstMatchToken, lastMatchToken, matchingTokens);
          if (ruleMatch != null) {
            ruleMatches.add(ruleMatch);
          }
        }
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.