Package org.languagetool.rules

Examples of org.languagetool.rules.RuleMatch


  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

        }
        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

  public void testPositionsWithGerman() throws IOException {
    final JLanguageTool tool = new JLanguageTool(new German());
    tool.activateDefaultPatternRules();
    final List<RuleMatch> matches = tool.check("Stundenkilometer");
    assertEquals(1, matches.size());
    final RuleMatch match = matches.get(0);
    // TODO: values should be either 0-based or 1-based, it should not be mixed up!
    assertEquals(0, match.getLine());
    assertEquals(1, match.getColumn());
  }
View Full Code Here

  }

  private List<RuleMatch> getRuleMatch(final String word, final int startPos) {
    final List<RuleMatch> ruleMatches = new ArrayList<>();
    if (isMisspelled(speller, word)) {
      final RuleMatch ruleMatch = new RuleMatch(this, startPos, startPos
          + word.length(), messages.getString("spelling"),
          messages.getString("desc_spelling_short"));
      //If lower case word is not a misspelled word, return it as the only suggestion
      if (!isMisspelled(speller, word.toLowerCase(conversionLocale))) {
        List<String> suggestion = Arrays.asList(word.toLowerCase(conversionLocale));
        ruleMatch.setSuggestedReplacements(suggestion);
        ruleMatches.add(ruleMatch);
        return ruleMatches;
      }
      List<String> suggestions = speller.getSuggestions(word);
      suggestions = 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 = StringTools.isAlphabetic(word.charAt(0));
      }
      if (isAlphabetic && dictionary.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);
        if (suggestions != null) {
          ruleMatch.setSuggestedReplacements(suggestions);
        }
        ruleMatches.add(ruleMatch);
      }
      len += word.length() + 1;
    }
View Full Code Here

          "palabra comienza por 'a' o 'ha' t\u00f3nicas, por ejemplo 'el hampa', "
          + "'un agua'";


        if (replacement != null) {
          final RuleMatch ruleMatch = new RuleMatch(this, prevPos, prevPos+prevToken.length(), msg, "Art\u00edculo incorrecto");
          ruleMatches.add(ruleMatch);
        }
        if (tokens[i].hasPosTag("DA0FS0") || tokens[i].hasPosTag("DI0FS0")  ) {         
          prevToken = token;
          prevPos = tokens[i].getStartPos();
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

  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 = StringTools.ruleMatchesToXML(matches, text, 5, StringTools.XmlPrintMode.NORMAL_XML);
    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

    final List<RuleMatch> matches = new ArrayList<>();
    final String text = "This is a test sentence.";
    final List<Element> elements = Collections.emptyList();
    final Rule patternRule = new PatternRule("MY_ID", Language.DEMO, elements, "my description", "my message", "short message");
    patternRule.setCategory(new Category("MyCategory"));
    final RuleMatch match = new RuleMatch(patternRule, 8, 10, "myMessage");
    match.setColumn(99);
    match.setEndColumn(100);
    match.setLine(44);
    match.setEndLine(45);
    matches.add(match);
    final String xml = StringTools.ruleMatchesToXML(matches, text, 5, StringTools.XmlPrintMode.NORMAL_XML);
    assertTrue(xml.contains(">\n" +
            "<error fromy=\"44\" fromx=\"98\" toy=\"45\" tox=\"99\" ruleId=\"MY_ID\" msg=\"myMessage\" " +
            "replacements=\"\" context=\"...s is a test ...\" contextoffset=\"8\" offset=\"8\" errorlength=\"2\" category=\"MyCategory\" " +
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.