Package org.languagetool.rules

Examples of org.languagetool.rules.RuleMatch


  private RuleMatch ruleMatchWrongVerbSubject(final AnalyzedTokenReadings subject, final AnalyzedTokenReadings verb) {
    final String msg = "Möglicherweise fehlende grammatische Übereinstimmung zwischen Subjekt (" + subject.getToken() +
      ") und Prädikat (" + verb.getToken() + ") bezüglich Person oder Numerus (Einzahl, Mehrzahl - Beispiel: " +
      "'ich sind' statt 'ich bin').";
    if (subject.getStartPos() < verb.getStartPos()) {
      return new RuleMatch(this, subject.getStartPos(), verb.getStartPos() + verb.getToken().length(), msg);
    } else {
      return new RuleMatch(this, verb.getStartPos(), subject.getStartPos() + subject.getToken().length(), msg);
    }
  }
View Full Code Here


            break;
          final AnalyzedGermanTokenReadings nextNextToken = (AnalyzedGermanTokenReadings)tokens[tokenPos];
          if (nextNextToken.hasReadingOfType(POSType.NOMEN)) {
            // TODO: add a case (checkAdjNounAgreement) for special cases like "deren",
            // e.g. "deren komisches Geschenke" isn't yet detected as incorrect
            final RuleMatch ruleMatch = checkDetAdjNounAgreement((AnalyzedGermanTokenReadings)tokens[i],
                nextToken, (AnalyzedGermanTokenReadings)tokens[i+2]);
            if (ruleMatch != null) {
              ruleMatches.add(ruleMatch);
            }
          }
        } else if (nextToken.hasReadingOfType(POSType.NOMEN)) {
          final RuleMatch ruleMatch = checkDetNounAgreement((AnalyzedGermanTokenReadings)tokens[i],
              (AnalyzedGermanTokenReadings)tokens[i+1]);
          if (ruleMatch != null) {
            ruleMatches.add(ruleMatch);
          }
        }
View Full Code Here

    return false;
  }

  private RuleMatch checkDetNounAgreement(final AnalyzedGermanTokenReadings token1,
      final AnalyzedGermanTokenReadings token2) {
    RuleMatch ruleMatch = null;
    final Set<String> set1 = getAgreementCategories(token1);
    if (set1 == null) {
      return null// word not known, assume it's correct
    }
    final Set<String> set2 = getAgreementCategories(token2);
    if (set2 == null) {
      return null;
    }
    set1.retainAll(set2);
    if (set1.size() == 0) {
      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);
    }
    return ruleMatch;
  }
View Full Code Here

  }

  private RuleMatch checkDetAdjNounAgreement(final AnalyzedGermanTokenReadings token1,
      final AnalyzedGermanTokenReadings token2, final AnalyzedGermanTokenReadings token3) {
    final Set<String> set = retainCommonCategories(token1, token2, token3, null);
    RuleMatch ruleMatch = null;
    if (set.size() == 0) {
      // TODO: more detailed error message:
      final String msg = "Möglicherweise fehlende grammatische Übereinstimmung zwischen Artikel, Adjektiv und " +
            "Nomen bezüglich Kasus, Numerus oder Genus. Beispiel: 'mein kleiner Haus' " +
            "statt 'mein kleines Haus'";
      final String shortMsg = "Möglicherweise keine Übereinstimmung bezüglich Kasus, Numerus oder Genus";
      ruleMatch = new RuleMatch(this, token1.getStartPos(),
          token3.getStartPos()+token3.getToken().length(), msg, shortMsg);
    }
    return ruleMatch;
  }
View Full Code Here

      }

      if (repetition) {
        final String msg = "Powtórzony wyraz w zdaniu";
        final int pos = tokens[i].getStartPos();
        final RuleMatch ruleMatch = new RuleMatch(this, pos, pos
            + token.length(), msg, "Powtórzenie wyrazu");       
        ruleMatches.add(ruleMatch);
        repetition = false;
      }
View Full Code Here

      if (matcher.matches()) {
        if (!tokens[i - 1].getToken().equals(" ")) {
          final String replacement = " " + token;
          final String msg = getSuggestion();
          final int pos = tokens[i].getStartPos();
          final RuleMatch potentialRuleMatch = new RuleMatch(this, pos, pos
              + token.length(), msg, getShort());
          potentialRuleMatch.setSuggestedReplacement(replacement);
          ruleMatches.add(potentialRuleMatch);
        }
      }
    }
    return toRuleMatchArray(ruleMatches);
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

        // LEN create a new RuleMatch object, passing in the rule itself, the pos of the previous token, the
        //     length of the prev token, the repetition msg, and the short version of the repetition msg
        //     This results in the specific violation of the rule being shown in the popup
        // LEN Note: not multiple rules, but multiple suggestions, therefore we need to
        //     use RuleMatch.setSuggestedReplacements(final List<String> replacement)   
        final RuleMatch ruleMatch = new RuleMatch(this, prevPos, pos+prevToken.length(), msg,
                messages.getString("desc_repetition_short"));
        final List<String> replacementSuggs = new ArrayList<>(); // LEN create empty list of suggestion strings
        replacementSuggs.add(prevToken+" "+token)// LEN case 1: replace zero-width space w/ real space
        replacementSuggs.add(prevToken);      // LEN case 2: remove repeated word - same as original suggestion
        replacementSuggs.add(prevToken+"ៗ");      // LEN case 3: same as case 2, just add "repetition character"
        ruleMatch.setSuggestedReplacements(replacementSuggs); // LEN the suggestions to use
        ruleMatches.add(ruleMatch); // LEN add rule to list of rules
      }
      prevToken = token;
    }
View Full Code Here

        if (isPhraseImpersonalVerbS(tokens, i) ) 
          continue loop;
       
        // the rule matches
        final String msg = "Expressió incorrecta si equival a 'adonar-se', correcta si vol dir 'retre compte'.";
        final RuleMatch ruleMatch = new RuleMatch(this,
            tokens[i].getStartPos(), tokens[i].getStartPos()
                + token.length(), msg,
            "Possible error");
        ruleMatches.add(ruleMatch);
      }
     
      // Comprova: portar-se/emportar-se
      if (i+2<tokens.length
          && matchLemmaRegexp(tokens[i], VERBS_PORTAR_DUR)
          && ! (matchPostagRegexp(tokens[i], VERB_INF) && isThereBefore(tokens,i,LEMMA_PREP_A_PER,POSTAG_PREPOSICIO))
          && !hasVerbMultipleReadings(tokens[i]) //em duràs un mocador
          && isThereReflexivePronoun(tokens, i) // ens portem, ens hem de portar
          && isThereAfterWithoutPreposition(tokens, i, POSTAG_CD)
          && !isThereVerbBefore(tokens,i,VERBS_DEIXAR_FER) // es deixen portar
          && !(isThereVerbBefore(tokens,i,VERBS_POTENCIALMENT_PRONOMINALS)&&!isThereVerbBefore(tokens,i,NO_VERBS_POTENCIALMENT_PRONOMINALS))
          && !matchPostagRegexp(tokens[i+1], POSTAG_ADVERBI) // es porten bé
          && !matchPostagRegexp(tokens[i+2], POSTAG_ADVERBI) // hem de portar-nos bé
          && !matchLemmaRegexp(tokens[i+2], ANYMESDIA) // ens portem tres anys
          && !isPhraseImpersonalVerbSP(tokens, i) // Es va portar l'any passat
          ) {
        // the rule matches
        String suggestion;
        if (matchLemmaRegexp(tokens[i], VERB_PORTAR)) {suggestion= "em"+token; }
          else if (token.equalsIgnoreCase("du")) {suggestion="endú"; }
          else {suggestion= "en"+token; }
        final String msg="¿Volíeu dir <suggestion>"+suggestion+"</suggestion>?";
        final RuleMatch ruleMatch = new RuleMatch(this,
            tokens[i].getStartPos(), tokens[i].getStartPos()
                + token.length(), msg, "Possible error");
        ruleMatches.add(ruleMatch);   
        continue loop;
      }
     
      //PERÍFRASI AMB VERB PRONOMINAL: el fan *agenollar-se/agenollar
      if (i+1<tokens.length
          && matchPostagRegexp(tokens[i], VERB_INF)
          && !matchPostagRegexp(tokens[i - 1], POSTAG_PREPOSICIO)
          && isThereVerbBefore(tokens,i,VERBS_DEIXAR_FER)
          && isThereBefore(tokens, i, LEMMA_PRONOM_CD, POSTAG_PRONOM_CD
          && matchRegexp(tokens[i + 1].getToken(), REFLEXIU_POSPOSAT) ) {
          // the rule matches
          final String msg = "En aquesta perífrasi verbal el pronom reflexiu posterior és redundant.";
          final RuleMatch ruleMatch = new RuleMatch(this,
              tokens[i+1].getStartPos(), tokens[i+1].getStartPos()
                  + tokens[i+1].getToken().length(), msg, "Pronom redundant");
          ruleMatches.add(ruleMatch);
          continue loop;
      }

      //VERBS PRONOMINALS: Cal que hi hagi pronom reflexiu.
      if (matchLemmaRegexp(tokens[i], VERBS_PRONOMINALS)) {
        if (matchLemmaRegexp(tokens[i], NO_VERBS_PRONOMINALS))
          // atengué l'administració
          continue loop;
        if (matchPostagRegexp(tokens[i], VERB_PARTICIPI) && !matchLemmaRegexp(tokens[i - 1], VERB_HAVER))
          continue loop;
        if (isThereVerbBefore(tokens,i,VERBS_DEIXAR_FER// el fa agenollar
            && isThereBefore(tokens, i, LEMMA_PRONOM_CD, POSTAG_PRONOM_CD) )
          continue loop;
        if (isThereReflexivePronoun(tokens, i))
          continue loop;
        // the rule matches
        final String msg = "Aquest verb és pronominal. Probablement falta un pronom.";
        final RuleMatch ruleMatch = new RuleMatch(this,
            tokens[i].getStartPos(), tokens[i].getStartPos()
                + token.length(), msg,
            "Verb pronominal: falta un pronom");
        ruleMatches.add(ruleMatch);
        continue loop;
      }
     
      //VERBS NO PRONOMINALS: No hi ha d'haver pronom reflexiu.
      if (matchLemmaRegexp(tokens[i], VERBS_NO_PRONOMINALS)) {
        if (matchLemmaRegexp(tokens[i], NO_VERBS_NO_PRONOMINALS))
          continue loop;       
        if (!isThereReflexivePronoun(tokens, i))
          continue loop;
        //impersonal obligació: s'ha de baixar
        if (matchLemmaRegexp(tokens[i],VERBS_NO_PRONOMINALS_IMPERSONALS2)
            && isThereBefore(tokens, i, LEMMA_ES, POSTAG_ES)
            && isThereBefore(tokens, i, LEMMA_DE, POSTAG_DE)
            && isThereVerbBefore(tokens,i,VERB_HAVER) )
            continue loop;
        if (isThereVerbBefore(tokens,i,VERBS_SOVINT_AMB_COMPLEMENT)
            || (isThereVerbBefore(tokens,i,VERBS_POTENCIALMENT_PRONOMINALS)&&!isThereVerbBefore(tokens,i,NO_VERBS_POTENCIALMENT_PRONOMINALS))
            || isThereVerbBefore(tokens,i,VERBS_PRONOMINALS)) //et deixes caure, et fas témer,
          continue loop;
        //FRASE IMPERSONAL
        // És frase impersonal si hi ha el pronom 'es', llevat que es pugui identificar un subjecte "personal"
        if (matchLemmaRegexp(tokens[i],VERBS_NO_PRONOMINALS_IMPERSONALS)
            && isPhraseImpersonalVerbS(tokens, i) ) 
          continue loop;
        if (matchLemmaRegexp(tokens[i],VERBS_NO_PRONOMINALS_IMPERSONALS2)
            && isPhraseImpersonalVerbSP(tokens, i) ) 
          continue loop;
       
        // the rule matches
        final String msg = "Aquest verb no és pronominal. Probablement sobra un pronom.";
        final RuleMatch ruleMatch = new RuleMatch(this,
            tokens[i].getStartPos(), tokens[i].getStartPos()
                + token.length(), msg,
            "Verb no pronominal");
        ruleMatches.add(ruleMatch);
      }
     
      //VERBS DE MOVIMENT: si hi ha pronom reflexiu cal el pronom 'en'.
      if (matchLemmaRegexp(tokens[i], VERBS_MOVIMENT) && !matchPostagRegexp(tokens[i], VERB_AUXILIAR)) {
        if (matchLemmaRegexp(tokens[i], VERBS_NO_MOVIMENT))
          // atengué l'administració
          continue loop;
        //impersonal obligació: s'ha de baixar
        if (isThereBefore(tokens, i, LEMMA_ES, POSTAG_ES)
            && isThereBefore(tokens, i, LEMMA_DE, POSTAG_DE)
            && isThereVerbBefore(tokens,i,VERB_HAVER) )
            continue loop;
        if (isThereVerbBefore(tokens,i,VERBS_SOVINT_AMB_COMPLEMENT)
            || (isThereVerbBefore(tokens,i,VERBS_POTENCIALMENT_PRONOMINALS)&&!isThereVerbBefore(tokens,i,NO_VERBS_POTENCIALMENT_PRONOMINALS))
            || isThereVerbBefore(tokens,i,VERBS_PRONOMINALS) //et deixes anar/pujar
            || isThereVerbAfter(tokens,i,VERBS_SOVINT_AMB_COMPLEMENT) ) // per venir-vos a veure
          continue loop;
        if (matchLemmaRegexp(tokens[i], VERB_VENIR)) {
          if (isThereAfter(tokens, i, VERB_INF))
            continue loop;
        }
        if (matchLemmaRegexp(tokens[i], VERB_ANAR)) {
          if (isThereAfter(tokens, i, VERB_GERUNDI))
            continue loop;
          if (isThereVerbAfter(tokens, i,
              VERBS_POTENCIALMENT_PRONOMINALS)
              ||isThereVerbAfter(tokens,i,VERBS_PRONOMINALS))
            continue loop;
          if (hasVerbMultipleReadings(tokens[i]) && isThereAfter(tokens,i,POSTAG_ADVERBI))
            continue loop;
          //FRASE IMPERSONAL
          if (isThereBefore(tokens, i, LEMMA_ES, POSTAG_ES)
              && !isThereBefore(tokens, i, LEMMA_PRONOM_CI, POSTAG_PRONOM_CI)
              && (!isTherePersonalSubjectBefore(tokens,i,TRENCA_COMPTE) || isThereBefore(tokens, i, LEMMA_HI, POSTAG_HI))
              && isVerbNumberPerson(tokens,i,VERB_3S))
            continue loop;
        }
        else {
          // FRASE IMPERSONAL
          if (isThereBefore(tokens, i, LEMMA_ES, POSTAG_ES)
              && !isThereBefore(tokens, i, LEMMA_PRONOM_CI, POSTAG_PRONOM_CI)
              && !isTherePersonalSubjectBefore(tokens, i,  TRENCA_COMPTE))
            continue loop;
        }
        if (isThereReflexivePronoun(tokens, i) && (!isTherePronoun(tokens, i, LEMMA_EN, POSTAG_EN))) {
          // the rule matches
          final String msg = "No useu com a pronominal aquest verb, o bé afegiu-hi el pronom 'en'."; //Cal canviar el missatge
          final RuleMatch ruleMatch = new RuleMatch(this,
              tokens[i].getStartPos(), tokens[i].getStartPos()
                  + token.length(), msg,
              "Falta el pronom 'en'");
          ruleMatches.add(ruleMatch);
        }
View Full Code Here

      final String origToken = token;
      final String replacement = isCaseSensitive()?wrongWords.get(token):wrongWords.get(token.toLowerCase(getLocale()));
      if (replacement != null) {
        final String msg = token + getSuggestion() + replacement;
        final int pos = tokens[i].getStartPos();
        final RuleMatch potentialRuleMatch = new RuleMatch(this, pos, pos
            + origToken.length(), msg, getShort());
        if (!isCaseSensitive() && StringTools.startsWithUppercase(token)) {
          potentialRuleMatch.setSuggestedReplacement(StringTools.uppercaseFirstChar(replacement));
        } else {
          potentialRuleMatch.setSuggestedReplacement(replacement);
        }
        ruleMatches.add(potentialRuleMatch);
      }
    }
    return toRuleMatchArray(ruleMatches);
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.