Package org.languagetool.rules

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


            break;
          }
        }

        if (allElementsMatch && matchingTokens == patternSize) {
          final RuleMatch ruleMatch = createRuleMatch(tokenPositions, tokens,
              firstMatchToken, lastMatchToken, matchingTokens);
          if (ruleMatch != null) {
            ruleMatches.add(ruleMatch);
          }
        }
View Full Code Here

        //now do some spell-checking:
      if (!(errMessage.contains("<pleasespellme/>") && errMessage
          .contains("<mistake/>"))) {
        final String clearMsg = errMessage.replaceAll("<pleasespellme/>", "")
            .replaceAll("<mistake/>", "");
        return new RuleMatch(rule, fromPos, toPos, clearMsg,
            rule.getShortMessage(), startsWithUppercase, suggestionsOutMsg);
      }
      } // failed to create any rule match...
      return null;
    }
View Full Code Here

      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

      }
      lastToken = readings;
      i++;
    }
    if (!verbFound && lastToken != null && i - 1 >= MIN_TOKENS_FOR_ERROR) {
      RuleMatch match = new RuleMatch(this, 0, lastToken.getStartPos() + lastToken.getToken().length(), "Dieser Satz scheint kein Verb zu enthalten");
      return new RuleMatch[]{ match };
    }
    return new RuleMatch[0];
  }
View Full Code Here

  private void assertBad(String s, String... expectedSuggestions) throws IOException {
    RuleMatch[] matches = rule.match(langTool.getAnalyzedSentence(s));
    assertEquals("Did not find one match in sentence '" + s + "'", 1, matches.length);
    if (expectedSuggestions.length > 0) {
      RuleMatch match = matches[0];
      List<String> suggestions = match.getSuggestedReplacements();
      assertThat(suggestions, is(Arrays.asList(expectedSuggestions)));
    }
  }
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

  private void assertBad(String s, int n, String... expectedSuggestions) throws IOException {
    RuleMatch[] matches = rule.match(langTool.getAnalyzedSentence(s));
    assertEquals("Did not find " + n + " match(es) in sentence '" + s + "'", n, matches.length);
    if (expectedSuggestions.length > 0) {
      RuleMatch match = matches[0];
      // When two errors are reported by the rule (so TODO above), it might happen that the first match does not have the suggestions, but the second one
      if(matches.length > 1 && match.getSuggestedReplacements().size()==0) {
        match = matches[1];
      }
      List<String> suggestions = match.getSuggestedReplacements();
      assertThat(suggestions, is(Arrays.asList(expectedSuggestions)));
    }
  }
View Full Code Here

    final String message = "Did you mean: <suggestion>where</suggestion> or <suggestion>we</suggestion>?";
    final PatternRule rule = new PatternRule("MY_ID", language, 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

  @Test
  public void testRuleMatchesToXML() throws IOException {
    final List<RuleMatch> matches = new ArrayList<>();
    final String text = "This is an test sentence. Here's another sentence with more text.";
    final FakeRule rule = new FakeRule();
    final RuleMatch match = new RuleMatch(rule, 8, 10, "myMessage");
    match.setColumn(99);
    match.setEndColumn(100);
    match.setLine(44);
    match.setEndLine(45);
    matches.add(match);
    final String xml = SERIALIZER.ruleMatchesToXml(matches, text, 5, language);
    assertTrue(xml.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"));
    final Pattern matchesPattern =
            Pattern.compile(".*<matches software=\"LanguageTool\" version=\"" + JLanguageTool.VERSION + "\" buildDate=\".*?\">.*", Pattern.DOTALL);
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.