Package org.languagetool.rules

Examples of org.languagetool.rules.RuleMatch


    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, 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 = SERIALIZER.ruleMatchesToXml(matches, text, 5, language, language);
    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


  @Test
  public void testRuleMatchesWithUrlToXML() throws IOException {
    final List<RuleMatch> matches = new ArrayList<>();
    final String text = "This is an test sentence. Here's another sentence with more text.";
    final RuleMatch match = new RuleMatch(new FakeRule() {
      @Override
      public URL getUrl() {
        try {
          return new URL("http://server.org?id=1&foo=bar");
        } catch (MalformedURLException e) {
          throw new RuntimeException(e);
        }
      }
    }, 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.contains(">\n" +
            "<error fromy=\"44\" fromx=\"98\" toy=\"45\" tox=\"99\" ruleId=\"FAKE_ID\" msg=\"myMessage\" " +
            "replacements=\"\" context=\"...s is an test...\" contextoffset=\"8\" offset=\"8\" errorlength=\"2\" url=\"http://server.org?id=1&amp;foo=bar\" " +
View Full Code Here

  @Test
  public void testRuleMatchesToXMLEscapeBug() throws IOException {
    final List<RuleMatch> matches = new ArrayList<>();
    final String text = "This is \"an test sentence. Here's another sentence with more text.";
    final RuleMatch match = new RuleMatch(new FakeRule(), 9, 11, "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.contains(">\n" +
            "<error fromy=\"44\" fromx=\"98\" toy=\"45\" tox=\"99\" ruleId=\"FAKE_ID\" msg=\"myMessage\" " +
            "replacements=\"\" context=\"... is &quot;an test...\" contextoffset=\"8\" offset=\"9\" errorlength=\"2\" " +
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

         ) {
        final String msg = "'wider' in 'widerspiegeln' wird mit 'i' statt mit 'ie' " +
                "geschrieben, z.B. 'Das spiegelt die Situation gut wider.'";
        final String shortMsg = "'wider' in 'widerspiegeln' wird mit 'i' geschrieben";
        final int pos = tokens[i].getStartPos();
        final RuleMatch ruleMatch = new RuleMatch(this, pos, pos + token.length(), msg, shortMsg);
        ruleMatch.setSuggestedReplacement("wider");
        ruleMatches.add(ruleMatch);
        foundSpiegelt = false;
        foundWieder = false;
        foundWider = false;
      }
View Full Code Here

          && prevToken.endsWith("-")) {
        final char firstChar = token.charAt(0);
        if (Character.isUpperCase(firstChar)) {
          final String msg = "Möglicherweise fehlt ein 'und' oder ein Komma, oder es wurde nach dem Wort " +
          "ein überflüssiges Leerzeichen eingefügt. Eventuell haben Sie auch versehentlich einen Bindestrich statt eines Punktes eingefügt.";
          final RuleMatch ruleMatch = new RuleMatch(this, tokens[i-1].getStartPos(),
              tokens[i-1].getStartPos()+prevToken.length()+1, msg);
          String prevTokenStr = tokens[i-1].getToken();
          ruleMatch.setSuggestedReplacements(Arrays.asList(prevTokenStr, prevTokenStr + ", "));
          ruleMatches.add(ruleMatch);
        }
      }     
      prevToken = token;
    }
View Full Code Here

 
  private RuleMatch ruleMatchWrongVerb(final AnalyzedTokenReadings token) {
    final String msg = "Möglicherweise fehlende grammatische Übereinstimmung zwischen Subjekt und Prädikat (" +
      token.getToken() + ") bezüglich Person oder Numerus (Einzahl, Mehrzahl - Beispiel: " +
      "'Max bist' statt 'Max ist').";
    return new RuleMatch(this, token.getStartPos(), token.getStartPos() + token.getToken().length(), msg);
  }
View Full Code Here

   
    List<String> suggestions = new ArrayList<>();
    List<String> verbSuggestions = new ArrayList<>();
    List<String> pronounSuggestions = new ArrayList<>();
   
    RuleMatch ruleMatch;
    if (subject.getStartPos() < verb.getStartPos()) {
      ruleMatch = new RuleMatch(this, subject.getStartPos(), verb.getStartPos() + verb.getToken().length(), msg);
      verbSuggestions.addAll(getVerbSuggestions(verb, expectedVerbPOS, false));
      for (String verbSuggestion : verbSuggestions) {
        suggestions.add(subject.getToken() + " " + verbSuggestion);
      }
      pronounSuggestions.addAll(getPronounSuggestions(verb, Character.isUpperCase(subject.getToken().charAt(0))));
      for (String pronounSuggestion : pronounSuggestions) {
        suggestions.add(pronounSuggestion + " " + verb.getToken());
      }
      ruleMatch.setSuggestedReplacements(suggestions);
    } else {
      ruleMatch = new RuleMatch(this, verb.getStartPos(), subject.getStartPos() + subject.getToken().length(), msg);
      verbSuggestions.addAll(getVerbSuggestions(verb, expectedVerbPOS, Character.isUpperCase(verb.getToken().charAt(0))));
      for (String verbSuggestion : verbSuggestions) {
        suggestions.add(verbSuggestion + " " + subject.getToken());
      }
      pronounSuggestions.addAll(getPronounSuggestions(verb, false));
      for (String pronounSuggestion : pronounSuggestions) {
        suggestions.add(verb.getToken() + " " + pronounSuggestion);
      }
      ruleMatch.setSuggestedReplacements(suggestions);
    }
   
    return ruleMatch;
  }
View Full Code Here

                       && "als".equals(tokens[i-1].getToken())
                       && "das".equals(tokens[i].getToken())) {
              // avoid false alarm for e.g. "weniger farbenprächtig als das anderer Papageien"
              continue;
            }
            final RuleMatch ruleMatch = checkDetAdjNounAgreement(tokens[i],
                nextToken, tokens[i+2]);
            if (ruleMatch != null) {
              ruleMatches.add(ruleMatch);
            }
          }
        } else if (GermanHelper.hasReadingOfType(nextToken, POSType.NOMEN)) {
          final RuleMatch ruleMatch = checkDetNounAgreement(tokens[i], tokens[i+1]);
          if (ruleMatch != null) {
            ruleMatches.add(ruleMatch);
          }
        }
      }
View Full Code Here

    final Set<String> set2 = getAgreementCategories(token2);
    if (set2 == null) {
      return null;
    }
    set1.retainAll(set2);
    RuleMatch ruleMatch = null;
    if (set1.size() == 0 && !isException(token1, token2)) {
      final List<String> errorCategories = getCategoriesCausingError(token1, token2);
      final String errorDetails = errorCategories.size() > 0 ?
              StringTools.listToString(errorCategories, " und ") : "Kasus, Genus oder Numerus";
      final String msg = "Möglicherweise fehlende grammatische Übereinstimmung zwischen Artikel und Nomen " +
            "bezüglich " + errorDetails + ".";
      final String shortMsg = "Möglicherweise keine Übereinstimmung bezüglich " + errorDetails;
      ruleMatch = new RuleMatch(this, token1.getStartPos(),
              token2.getStartPos() + token2.getToken().length(), msg, shortMsg);
      final AgreementSuggestor suggestor = new AgreementSuggestor(language.getSynthesizer(), token1, token2);
      final List<String> suggestions = suggestor.getSuggestions();
      ruleMatch.setSuggestedReplacements(suggestions);
    }
    return ruleMatch;
  }
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.