Package org.languagetool.rules.patterns

Examples of org.languagetool.rules.patterns.Match


        for (int i = 0; i < matchingTokens - startPositionCorrection
                + endPositionCorrection; i++) {
          final int position = text.getOriginalPosition(firstMatchToken
                  + correctedStPos + i);
          final Element myEl = patternElements.get(i+startPositionCorrection);
          final Match tmpMatchToken = new Match(myEl.getPOStag(), null,
                  true, myEl.getPOStag(), //myEl.isPOStagRegularExpression()
                  null, Match.CaseConversion.NONE, false, false,
                  Match.IncludeRange.NONE);
          tmpMatchToken.setToken(whTokens[position]);
          final String prevValue = whTokens[position].toString();
          final String prevAnot = whTokens[position]
                  .getHistoricalAnnotations();
          whTokens[position] = tmpMatchToken.filterReadings();
          annotateChange(whTokens[position], prevValue, prevAnot);
        }
        break;
      case IMMUNIZE:
        for (int i = 0; i < matchingTokens - startPositionCorrection + endPositionCorrection; i++) {
          whTokens[text.getOriginalPosition(firstMatchToken + correctedStPos + i)].immunize();
        }
        break;
      case FILTER:
        if (matchElement == null) { // same as REPLACE if using <match>
          final Match tmpMatchToken = new Match(disambiguatedPOS, null, true,
                  disambiguatedPOS, null, Match.CaseConversion.NONE,
                  false, false, Match.IncludeRange.NONE);
          tmpMatchToken.setToken(whTokens[fromPos]);
          final String prevValue = whTokens[fromPos].toString();
          final String prevAnot = whTokens[fromPos].getHistoricalAnnotations();
          whTokens[fromPos] = tmpMatchToken.filterReadings();
          annotateChange(whTokens[fromPos], prevValue, prevAnot);
          filtered = true;
        }
        // FALLTHROUGH
      case REPLACE:
View Full Code Here


      Match.IncludeRange includeRange = Match.IncludeRange.NONE;
      if (attrs.getValue("include_skipped") != null) {
        includeRange = Match.IncludeRange.toRange(attrs
            .getValue("include_skipped").toUpperCase());
      }
      final Match mWorker = new Match(attrs.getValue(POSTAG), attrs
          .getValue("postag_replace"), YES
          .equals(attrs.getValue(POSTAG_REGEXP)), attrs
          .getValue("regexp_match"), attrs.getValue("regexp_replace"),
          caseConversion, YES.equals(attrs.getValue("setpos")),
          YES.equals(attrs.getValue("suppress_mispelled")),
          includeRange);
      if (inDisambiguation) {
        if (attrs.getValue(NO) != null) {
          final int refNumber = Integer.parseInt(attrs.getValue(NO));
          if (refNumber > elementList.size()) {
            throw new SAXException(
                "Only backward references in match elements are possible, tried to specify token "
                    + refNumber
                    + "\n Line: "
                    + pLocator.getLineNumber()
                    + ", column: " + pLocator.getColumnNumber() + ".");
          }
          mWorker.setTokenRef(refNumber);
          posSelector = mWorker;
        }
      } else if (inToken) {
        if (attrs.getValue(NO) != null) {
          final int refNumber = Integer.parseInt(attrs.getValue(NO));
          if (refNumber > elementList.size()) {
            throw new SAXException(
                "Only backward references in match elements are possible, tried to specify token "
                    + refNumber
                    + "\n Line: "
                    + pLocator.getLineNumber()
                    + ", column: " + pLocator.getColumnNumber() + ".");
          }
          mWorker.setTokenRef(refNumber);
          tokenReference = mWorker;
          elements.append('\\');
          elements.append(refNumber);
        }
      }
View Full Code Here

  private AnalyzedTokenReadings getAnalyzedTokenReadings(String token, String posTag, String lemma) {
    return new AnalyzedTokenReadings(new AnalyzedToken(token, posTag, lemma), 0);
  }

  private Match getMatch(String posTag, String posTagReplace, boolean spell) throws IOException {
    final Match match = new Match(posTag, posTagReplace, true, null, null, CaseConversion.NONE, false, spell, IncludeRange.NONE);
    return match;
  }
View Full Code Here

    final Match match = new Match(posTag, posTagReplace, true, null, null, CaseConversion.NONE, false, spell, IncludeRange.NONE);
    return match;
  }

  private Match getTextMatch(String regexMatch, String regexpReplace, boolean spell) throws IOException {
    final Match match = new Match(null, null, false, regexMatch, regexpReplace, CaseConversion.NONE, false, spell, IncludeRange.NONE);
    return match;
  }
View Full Code Here

    return match;
  }

  public void testSpeller() throws Exception {
    //tests with synthesizer
    Match match = getMatch("POS1", "POS2", true);
    final Polish polish = new Polish();
    match.setSynthesizer(polish.getSynthesizer());
    match.setToken(getAnalyzedTokenReadings("inflectedform11", "POS1", "Lemma1"));
    //getting empty strings, which is what we want
    assertEquals("[]", Arrays.toString(match.toFinalString(polish)));

    // contrast with a speller = false!
    match = getMatch("POS1", "POS2", false);
    match.setSynthesizer(polish.getSynthesizer());
    match.setToken(getAnalyzedTokenReadings("inflectedform11", "POS1", "Lemma1"));
    assertEquals("[(inflectedform11)]", Arrays.toString(match.toFinalString(polish)));

    //and now a real word - we should get something
    match = getMatch("subst:sg:acc.nom:m3", "subst:sg:gen:m3", true);
    match.setSynthesizer(polish.getSynthesizer());
    match.setToken(getAnalyzedTokenReadings("AON", "subst:sg:acc.nom:m3", "AON"));
    assertEquals("[AON-u]", Arrays.toString(match.toFinalString(polish)));

    //and now pure text changes       
    match = getTextMatch("^(.*)$", "$0-u", true);
    match.setSynthesizer(polish.getSynthesizer());
    match.setLemmaString("AON");
    assertEquals("[AON-u]", Arrays.toString(match.toFinalString(polish)));
    match.setLemmaString("batalion");
    //should be empty
    assertEquals("[]", Arrays.toString(match.toFinalString(polish)));
    match.setLemmaString("ASEAN");
    //and this one not
    assertEquals("[ASEAN-u]", Arrays.toString(match.toFinalString(polish)));
  }
View Full Code Here

  private AnalyzedTokenReadings getAnalyzedTokenReadings(String token, String posTag, String lemma) {
    return new AnalyzedTokenReadings(new AnalyzedToken(token, posTag, lemma), 0);
  }

  private Match getMatch(String posTag, String posTagReplace, boolean spell) {
    final Match match = new Match(posTag, posTagReplace, true, null, null, CaseConversion.NONE, false, spell, IncludeRange.NONE);
    return match;
  }
View Full Code Here

    final Match match = new Match(posTag, posTagReplace, true, null, null, CaseConversion.NONE, false, spell, IncludeRange.NONE);
    return match;
  }

  private Match getTextMatch(String regexMatch, String regexpReplace, boolean spell) {
    final Match match = new Match(null, null, false, regexMatch, regexpReplace, CaseConversion.NONE, false, spell, IncludeRange.NONE);
    return match;
  }
View Full Code Here

    return match;
  }

  public void testSpeller() throws Exception {
    //tests with synthesizer
    Match match = getMatch("POS1", "POS2", true);
    final Polish polish = new Polish();
    MatchState matchState = new MatchState(match, polish.getSynthesizer());
    matchState.setToken(getAnalyzedTokenReadings("inflectedform11", "POS1", "Lemma1"));
    //getting empty strings, which is what we want
    assertEquals("[]", Arrays.toString(matchState.toFinalString(polish)));

    // contrast with a speller = false!
    match = getMatch("POS1", "POS2", false);
    matchState = new MatchState(match, polish.getSynthesizer());
    matchState.setToken(getAnalyzedTokenReadings("inflectedform11", "POS1", "Lemma1"));
    assertEquals("[(inflectedform11)]", Arrays.toString(matchState.toFinalString(polish)));

    //and now a real word - we should get something
    match = getMatch("subst:sg:acc.nom:m3", "subst:sg:gen:m3", true);
    matchState = new MatchState(match, polish.getSynthesizer());
    matchState.setToken(getAnalyzedTokenReadings("AON", "subst:sg:acc.nom:m3", "AON"));
    assertEquals("[AON-u]", Arrays.toString(matchState.toFinalString(polish)));

    //and now pure text changes       
    match = getTextMatch("^(.*)$", "$0-u", true);
    match.setSynthesizer(polish.getSynthesizer());
    match.setLemmaString("AON");
    matchState = new MatchState(match, polish.getSynthesizer());
    assertEquals("[AON-u]", Arrays.toString(matchState.toFinalString(polish)));
    match.setLemmaString("batalion");
    //should be empty
    matchState = new MatchState(match, polish.getSynthesizer());
    assertEquals("[]", Arrays.toString(matchState.toFinalString(polish)));
    match.setLemmaString("ASEAN");
    //and this one not
    matchState = new MatchState(match, polish.getSynthesizer());
    assertEquals("[ASEAN-u]", Arrays.toString(matchState.toFinalString(polish)));
  }
View Full Code Here

          Match.IncludeRange includeRange = Match.IncludeRange.NONE;
          if (attrs.getValue("include_skipped") != null) {
            includeRange = Match.IncludeRange.valueOf(attrs
                    .getValue("include_skipped").toUpperCase(Locale.ENGLISH));
          }
          final Match mWorker = new Match(attrs.getValue(POSTAG), attrs
                  .getValue("postag_replace"), YES
                  .equals(attrs.getValue(POSTAG_REGEXP)), attrs
                  .getValue("regexp_match"), attrs.getValue("regexp_replace"),
                  caseConversion, YES.equals(attrs.getValue("setpos")),
                  YES.equals(attrs.getValue("suppress_mispelled")),
                  includeRange);
          if (inDisambiguation) {
            if (attrs.getValue(NO) != null) {
              final int refNumber = Integer.parseInt(attrs.getValue(NO));
              refNumberSanityCheck(refNumber);
              mWorker.setTokenRef(refNumber);
              posSelector = mWorker;
            }
          } else if (inToken) {
            if (attrs.getValue(NO) != null) {
              final int refNumber = Integer.parseInt(attrs.getValue(NO));
              refNumberSanityCheck(refNumber);
              mWorker.setTokenRef(refNumber);
              tokenReference = mWorker;
              elements.append('\\');
              elements.append(refNumber);
            }
          }
View Full Code Here

TOP

Related Classes of org.languagetool.rules.patterns.Match

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.