Package org.languagetool.rules

Examples of org.languagetool.rules.RuleMatch


              }
            }
          }
        }
        if (possibleReplacements.size() > 0) {
            RuleMatch potentialRuleMatch = createRuleMatch(tokenReadings,possibleReplacements);
            ruleMatches.add(potentialRuleMatch);
        }
      }
    }
    return toRuleMatchArray(ruleMatches);
View Full Code Here


  private RuleMatch createRuleMatch(AnalyzedTokenReadings tokenReadings,
      List<String> replacements) {
    String tokenString = tokenReadings.getToken();
    int pos = tokenReadings.getStartPos();

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

    if (StringTools.startsWithUppercase(tokenString)) {
      for (int i = 0; i < replacements.size(); i++) {
        replacements
            .set(i, StringTools.uppercaseFirstChar(replacements.get(i)));
      }
    }

    potentialRuleMatch.setSuggestedReplacements(replacements);

    return potentialRuleMatch;
  }
View Full Code Here

          }
        }
        if (theRuleMaches) {
          final String msg = "Reviseu la concordança de la paraula \u00AB"
              + token + "\u00BB.";
          final RuleMatch ruleMatch = new RuleMatch(this,
              tokens[i].getStartPos(),
              tokens[i].getStartPos() + token.length(), msg,
              "Reviseu la concordança.");
          ruleMatches.add(ruleMatch);
        }
View Full Code Here

        }

      }
      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

            msg += "<suggestion>" + replacements.get(k) + "</suggestion>";
          }
          msg += "?";
          final int startPos = prevTokensList.get(len - crtWordCount).getStartPos();
          final int endPos = prevTokensList.get(len - 1).getStartPos() + prevTokensList.get(len - 1).getToken().length();
          final RuleMatch potentialRuleMatch = new RuleMatch(this, startPos, endPos, msg, getShort());

          if (!isCaseSensitive() && StringTools.startsWithUppercase(crt)) {
            for (int k = 0; k < replacements.size(); k++) {
              replacements.set(k, StringTools.uppercaseFirstChar(replacements.get(k)));
            }
          }
          potentialRuleMatch.setSuggestedReplacements(replacements);
          ruleMatches.add(potentialRuleMatch);
          break;
        }
      }
    }
View Full Code Here

    assertThat(database.getLatestDate(language), is(new Date(0)));
    assertThat(database.list().size(), is(0));
    assertThat(database.getCheckDates().size(), is(0));
    FakeRule rule1 = new FakeRule(1);
    rule1.setCategory(new Category("My Category"));
    RuleMatch ruleMatch = new RuleMatch(rule1, 5, 10, "my message");
    AtomFeedItem feedItem1 = new AtomFeedItem("//id1?diff=123", "title", "summary1", new Date(10000));
    WikipediaRuleMatch wikiRuleMatch1 = new WikipediaRuleMatch(language, ruleMatch, "my context", feedItem1);
    database.add(wikiRuleMatch1);
    assertThat(database.list().size(), is(1));
    assertThat(database.list().get(0).getRuleId(), is("ID_1"));
    assertThat(database.list().get(0).getRuleDescription(), is("A fake rule"));
    assertThat(database.list().get(0).getRuleMessage(), is("my message"));
    assertThat(database.list().get(0).getTitle(), is("title"));
    assertThat(database.list().get(0).getErrorContext(), is("my context"));
    assertThat(database.list().get(0).getDiffId(), is(123L));
    assertThat(database.list().get(0).getFixDiffId(), is(0L));
    assertThat(database.list().get(0).getEditDate(), is(new Date(10000)));
    assertThat(database.getLatestDate(language), is(new Date(0)));
    assertNull(database.list().get(0).getRuleSubId());
    assertNull(database.list().get(0).getFixDate());
    assertThat(database.getCheckDates().size(), is(0));

    RuleMatch ruleMatch2 = new RuleMatch(new FakeRule(1), 9, 11, "my message")// same ID, different character positions
    AtomFeedItem feedItem2 = new AtomFeedItem("//id2?diff=124", "title", "summary2", new Date(9000000000L));
    WikipediaRuleMatch wikiRuleMatch2 = new WikipediaRuleMatch(language, ruleMatch2, "my context", feedItem2);
    int affected = database.markedFixed(wikiRuleMatch2);
    assertThat(affected, is(1));
    assertThat(database.list().get(0).getFixDate(), is(new Date(9000000000L)));
View Full Code Here

  }
 
  private List<WikipediaRuleMatch> makeMatches(int... ids) {
    List<WikipediaRuleMatch> matches = new ArrayList<>();
    for (int id : ids) {
      RuleMatch ruleMatch = new RuleMatch(new FakeRule(id), 10, 20, "error1");
      AtomFeedItem feedItem = new AtomFeedItem("id1", "title1", "summary1", new Date(10000));
      matches.add(new WikipediaRuleMatch(LANGUAGE, ruleMatch, "error context", feedItem));
    }
    return matches;
  }
View Full Code Here

        }
      }

      if (allElementsMatch && tokenPositions.size() == patternSize) {
        //System.out.println("YES");
        final RuleMatch ruleMatch = createRuleMatch(tokenPositions,
            tokens, firstMatchToken, lastMatchToken, firstMarkerMatchToken, lastMarkerMatchToken);
        if (ruleMatch != null) {
          ruleMatches.add(ruleMatch);
        }
      }
View Full Code Here

    int toPos = token.getStartPos() + token.getToken().length();
    if (fromPos < toPos) { // this can happen with some skip="-1" when the last token is not matched
      //now do some spell-checking:
      if (!(errMessage.contains(PatternRuleHandler.PLEASE_SPELL_ME) && errMessage.contains(MISTAKE))) {
        final String clearMsg = errMessage.replaceAll(PatternRuleHandler.PLEASE_SPELL_ME, "").replaceAll(MISTAKE, "");
        final RuleMatch ruleMatch = new RuleMatch(rule, fromPos, toPos, clearMsg,
                shortErrMessage, startsWithUppercase, suggestionsOutMsg);
        if (rule.getFilter() != null) {
          RuleFilterEvaluator evaluator = new RuleFilterEvaluator(rule.getFilter());
          AnalyzedTokenReadings[] patternTokens = Arrays.copyOfRange(tokens, firstMatchToken, lastMatchToken + 1);
          return evaluator.runFilter(rule.getFilterArguments(), ruleMatch, patternTokens, tokenPositions);
View Full Code Here

            }
            msg += "<suggestion>" + replacements.get(k) + "</suggestion>";
          }
          final int startPos = prevTokensList.get(len - crtWordCount).getStartPos();
          final int endPos = prevTokensList.get(len - 1).getStartPos() + prevTokensList.get(len - 1).getToken().length();
          final RuleMatch potentialRuleMatch = new RuleMatch(this, startPos, endPos, msg, getShort());

          if (!isCaseSensitive() && StringTools.startsWithUppercase(crt)) {
            for (int k = 0; k < replacements.size(); k++) {
              replacements.set(k, StringTools.uppercaseFirstChar(replacements.get(k)));
            }
          }
          potentialRuleMatch.setSuggestedReplacements(replacements);
          ruleMatches.add(potentialRuleMatch);
          break;
        }
      }
    }
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.