Package org.languagetool.rules

Examples of org.languagetool.rules.RuleMatch


  }

  private RuleMatch checkDetAdjNounAgreement(final AnalyzedTokenReadings token1,
      final AnalyzedTokenReadings token2, final AnalyzedTokenReadings 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 (prevTokenIsDas && !nextTokenIsPersonalPronoun) {
      // e.g. essen -> Essen
      if (Character.isLowerCase(token.charAt(0)) && !substVerbenExceptions.contains(token) && tokenReadings.hasPartialPosTag("VER:INF")
              && !tokenReadings.isIgnoredBySpeller()) {
        final String msg = "Substantivierte Verben werden großgeschrieben.";
        final RuleMatch ruleMatch = new RuleMatch(this, tokenReadings.getStartPos(),
            tokenReadings.getStartPos() + token.length(), msg);
        final String word = tokenReadings.getToken();
        final String fixedWord = StringTools.uppercaseFirstChar(word);
        ruleMatch.setSuggestedReplacement(fixedWord);
        ruleMatches.add(ruleMatch);
      }
    }
  }
View Full Code Here

        !isAdverbAndNominalization(i, tokens) &&
        !isSpecialCase(i, tokens) &&
        !isAdjectiveAsNoun(i, tokens) &&
        !isExceptionPhrase(i, tokens)) {
      final String msg = "Außer am Satzanfang werden nur Nomen und Eigennamen großgeschrieben";
      final RuleMatch ruleMatch = new RuleMatch(this, tokens[i].getStartPos(),
          tokens[i].getStartPos() + token.length(), msg);
      final String word = tokens[i].getToken();
      final String fixedWord = Character.toLowerCase(word.charAt(0)) + word.substring(1);
      ruleMatch.setSuggestedReplacement(fixedWord);
      ruleMatches.add(ruleMatch);
    }
  }
View Full Code Here

    String urlString = args[0];
    MarkupAwareWikipediaResult result = check.checkPage(new URL(urlString), new ErrorMarker("***", "***"));
    int errorCount = 0;
    for (AppliedRuleMatch match : result.getAppliedRuleMatches()) {
      RuleMatchApplication matchApplication = match.getRuleMatchApplications().get(0);
      RuleMatch ruleMatch = match.getRuleMatch();
      Rule rule = ruleMatch.getRule();
      System.out.println("");
      String message = ruleMatch.getMessage().replace("<suggestion>", "'").replace("</suggestion>", "'");
      errorCount++;
      System.out.print(errorCount + ". " + message);
      if (rule instanceof PatternRule) {
        System.out.println(" (" + rule.getId() + "[" + ((PatternRule) rule).getSubId() + "])");
      } else {
View Full Code Here


          }
        }

        RuleMatch potentialRuleMatch = createRuleMatch(tokenReadings, reqTokenReadings, posTagsToFind);
        ruleMatches.add(potentialRuleMatch);
      }

      reqTokenReadings = null;
    }
View Full Code Here

      }
    }
       
    int pos = tokenReadings.getStartPos();

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

    potentialRuleMatch.setSuggestedReplacements(suggestions);

    return potentialRuleMatch;
  }
View Full Code Here

        if(!CYRILLIC_ONLY.matcher(tokenString).matches() || LIKELY_LATIN_NUMBER.matcher(tokenString).matches()) {
          replacements.add( toLatin(tokenString) );
        }

        if (replacements.size() > 0) {
          RuleMatch potentialRuleMatch = createRuleMatch(tokenReadings, replacements);
          ruleMatches.add(potentialRuleMatch);
        }
      }
      else if(LATIN_NUMBER_WITH_CYRILLICS.matcher(tokenString).matches()) {
        List<String> replacements = new ArrayList<>();
        replacements.add( toLatin(tokenString) );

        RuleMatch potentialRuleMatch = createRuleMatch(tokenReadings, replacements);
        ruleMatches.add(potentialRuleMatch);
      }
    }
    return toRuleMatchArray(ruleMatches);
  }
View Full Code Here

  private RuleMatch createRuleMatch(AnalyzedTokenReadings tokenReadings, List<String> replacements) {
    String tokenString = tokenReadings.getToken();
    String msg = tokenString + getSuggestion(tokenString) + StringUtils.join(replacements, ", ");
    int pos = tokenReadings.getStartPos();

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

    return potentialRuleMatch;
  }
View Full Code Here

    @Override
    protected List<RuleMatch> getRuleMatches(final String word, final int startPos)
    throws IOException {
        final List<RuleMatch> ruleMatches = new ArrayList<>();
        if (isMisspelled(speller1, word) && isNotCompound(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(speller1, word.toLowerCase(conversionLocale))) {
                List<String> suggestion = Arrays.asList(word.toLowerCase(conversionLocale));
                ruleMatch.setSuggestedReplacements(suggestion);
                ruleMatches.add(ruleMatch);
                return ruleMatches;
            }
            List<String> suggestions = speller1.getSuggestions(word);
            suggestions.addAll(0, getAdditionalTopSuggestions(suggestions, word));
            suggestions.addAll(getAdditionalSuggestions(suggestions, word));
            if (!suggestions.isEmpty()) {
                ruleMatch.setSuggestedReplacements(pruneSuggestions(orderSuggestions(suggestions,word)));
            }
            ruleMatches.add(ruleMatch);
        }
        return ruleMatches;
    }
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
          && matchLemmaList(tokens[i], verbsPortarDur)
          && !(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)
          && !isThereVerbBeforeList(tokens,i,verbsDeixarFer) // es deixen portar
          && !(isThereVerbBeforeList(tokens,i,verbsPotencialmentPronominals) && !isThereVerbBeforeList(tokens,i,excepVerbsPotencialmentPronominals))
          && !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
          ) {
        if (isVerbNumberPerson(tokens,i,VERB_3S//el vent m'ha portat les rondalles
            && !isThereBefore(tokens, i, LEMMA_ES, POSTAG_ES)
            && isThereSubject3SBefore(tokens,i,TRENCA_COMPTE))
          continue loop;
        // the rule matches
        String suggestion;
        if (tokens[i].hasLemma("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;
      }
     
      //COMPROVA: 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)
          && isThereVerbBeforeListLimit(tokens,i, verbsDeixarFer,3)
          && isThereRedundantPronoun(tokens,i)
          && 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], VERB_AUTO) || matchLemmaList(tokens[i],verbsPronominals)) {
        if (matchLemmaList(tokens[i],excepVerbsPronominals)) // atengué l'administració
          continue loop;
        if (matchPostagRegexp(tokens[i], VERB_PARTICIPI) && !tokens[i-1].hasLemma("haver"))
          continue loop;
        if (isThereVerbBeforeList(tokens,i, verbsDeixarFer// el fa agenollar
            && (isThereBefore(tokens, i, LEMMA_PRONOM_CD, POSTAG_PRONOM_CD)
                || isThereBefore(tokens, i, LEMMA_PRONOM_CI, POSTAG_PRONOM_CI)
                || isThereAfterWithoutPreposition(tokens, i, POSTAG_CD))) //van fer agenollar els presos
          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 (matchLemmaList(tokens[i], verbsNoPronominals)) {
        if (matchLemmaList(tokens[i], excepVerbsNoPronominals))
          continue loop;       
        if (!isThereReflexivePronoun(tokens, i))
          continue loop;
        //impersonal obligació: s'ha de baixar
        if (matchLemmaList(tokens[i],verbsNoPronominalsImpersonals2)
            && isThereBefore(tokens, i, LEMMA_ES, POSTAG_ES)
            && isThereBefore(tokens, i, LEMMA_DE, POSTAG_DE)
            && isThereVerbBeforeList(tokens,i,verbHaver) )
            continue loop;
        if (isThereVerbBeforeList(tokens,i,verbsSovintAmbComplement)
            || (isThereVerbBeforeList(tokens,i,verbsPotencialmentPronominals)&&!isThereVerbBeforeList(tokens,i,excepVerbsPotencialmentPronominals))
            || isThereVerbBefore(tokens,i,VERB_AUTO)
            || isThereVerbBeforeList(tokens,i,verbsPronominals)) //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 (matchLemmaList(tokens[i],verbsNoPronominalsImpersonals)
            && isPhraseImpersonalVerbS(tokens, i) ) 
          continue loop;
        if (matchLemmaList(tokens[i],verbsNoPronominalsImpersonals2)
            && isPhraseImpersonalVerbSP(tokens, i) ) 
          continue loop;
        if (tokens[i].hasLemma("olorar") && isThereNearLemma (tokens, i, partsCos))
          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 (matchLemmaList(tokens[i], verbsMoviment) && !matchPostagRegexp(tokens[i], VERB_AUXILIAR)) {
        if (matchLemmaList(tokens[i], excepVerbsMoviment))
          // 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)
            && isThereVerbBeforeList(tokens,i,verbHaver) )
            continue loop;
        if (isThereVerbBeforeList(tokens,i,verbsSovintAmbComplement) // per venir-vos a veure
            || (isThereVerbBeforeList(tokens,i,verbsPotencialmentPronominals)&&!isThereVerbBeforeList(tokens,i,excepVerbsPotencialmentPronominals))
            || isThereVerbBefore(tokens,i,VERB_AUTO)
            || isThereVerbBeforeList(tokens,i,verbsPronominals)) //et deixes anar/pujar 
          continue loop;
        if (isVerbNumberPerson(tokens,i,VERB_3S//em puja al cap
            && !isThereBefore(tokens, i, LEMMA_ES, POSTAG_ES)
            && isThereNearLemma(tokens, i, partsCos))
          continue loop;
        if (tokens[i].hasLemma("venir") || tokens[i].hasLemma("anar")) { //Em va bé
          if (i+1<tokens.length
              && isVerbNumberPerson(tokens,i,VERB_3S)
              && !isThereBefore(tokens, i, LEMMA_ES, POSTAG_ES)
              && matchPostagRegexp(tokens[i+1],POSTAG_ADVERBI)
              && !isThereNearWord(tokens, i, pronomJo) )
            continue loop;       
        }
        if (tokens[i].hasLemma("venir")) {
          if (i+2<tokens.length
              && tokens[i+1].getToken().equals("de") && tokens[i+2].getToken().equals("gust"))
            continue loop;
          if (isVerbNumberPerson(tokens,i,VERB_3S) //em vingui la inspiració
              && !isThereBefore(tokens, i, LEMMA_ES, POSTAG_ES)
              && isThereAfterWithoutPreposition(tokens, i, POSTAG_CD)
              && !isThereNearWord(tokens, i, pronomJo) )
            continue loop;
          if (isThereAfter(tokens, i, VERB_INF))
            continue loop;
        }
        if (tokens[i].hasLemma("anar")) {
          if (isThereAfter(tokens, i, VERB_GERUNDI))
            continue loop;
          if (isThereVerbAfterList(tokens,i,verbsPotencialmentPronominals)
              || isThereVerbAfter(tokens,i,VERB_AUTO)
              || isThereVerbAfterList(tokens,i,verbsPronominals))
            continue loop;
          if (isVerbNumberPerson(tokens,i,VERB_3S)
              && !isThereBefore(tokens, i, LEMMA_ES, POSTAG_ES)
              && isThereSubject3SBefore(tokens,i,TRENCA_COMPTE))
            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

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.