class RegularIrregularParticipleFilter extends RuleFilter {

  private final Language language = new Portuguese();
  private final PortugueseSynthesizer synth = (PortugueseSynthesizer) language.getSynthesizer();

  @Override
  public RuleMatch acceptRuleMatch(RuleMatch match, Map<String, String> arguments, int patternTokenPos,
                                   AnalyzedTokenReadings[] patternTokens, List<Integer> tokenPositions) throws IOException {<FILL_FUNCTION_BODY>}

  boolean isRegular(String p) {
    String lp = p.toLowerCase();
    return lp.endsWith("do") || lp.endsWith("dos") || lp.endsWith("da") || lp.endsWith("das");
  }
}


    String direction = getRequired("direction", arguments); // RegularToIrregular or IrregularToRegular
    AnalyzedTokenReadings atr = null;
    for (AnalyzedTokenReadings token : patternTokens) {
      if (token.getStartPos() == match.getFromPos()) {
        atr = token;
        break;
      }
    }
    String replacement = null;
    if (atr.hasPosTagStartingWith("VMP")) {
      AnalyzedToken selectedAT = null;
      String desiredPostag = null;
      for (AnalyzedToken at : atr) {
        if (at.getPOSTag() != null && at.getPOSTag().startsWith("VMP")) {
          selectedAT = at;
          desiredPostag = at.getPOSTag();
        }
      }
      // assente SC assentado SM
      if (desiredPostag.endsWith("C")) {
        desiredPostag = desiredPostag.substring(0,desiredPostag.length() - 1) + "[MC]";
      } else {
        desiredPostag = desiredPostag.substring(0,desiredPostag.length() - 1) 
            + "["+ desiredPostag.substring(desiredPostag.length() - 1) + "C]";
      }
      
      String[] participles;
      try {
        participles = synth.synthesize(selectedAT, desiredPostag, true);
      } catch (IOException e) {
        throw new IOException("Cannot synthesize " + selectedAT.toString() + e);
      }
      if (participles != null && participles.length > 1) {
        if (direction.equalsIgnoreCase("RegularToIrregular") && isRegular(atr.getToken())) {
          if (!isRegular(participles[0])) {
            replacement = participles[0];
          } else if (!isRegular(participles[1])) {
            replacement = participles[1];
          }
        } else if (direction.equalsIgnoreCase("IrregularToRegular") && !isRegular(atr.getToken())) {
          if (isRegular(participles[0])) {
            replacement = participles[0];
          } else if (isRegular(participles[1])) {
            replacement = participles[1];
          }
        }
        if (replacement != null) {
          String message = match.getMessage();
          RuleMatch ruleMatch = new RuleMatch(match.getRule(), match.getSentence(), match.getFromPos(),
              match.getToPos(), message, match.getShortMessage());
          ruleMatch.setType(match.getType());
          String suggestion = match.getSuggestedReplacements().get(0).replace("{suggestion}", replacement);
          suggestion = suggestion.replace("{Suggestion}", StringTools.uppercaseFirstChar(replacement));
          suggestion = suggestion.replace("{SUGGESTION}", replacement.toUpperCase());
          ruleMatch.setSuggestedReplacement(suggestion);
          return ruleMatch;
        }
      }
    }
    return null;
  
<methods>public non-sealed void <init>() ,public abstract org.languagetool.rules.RuleMatch acceptRuleMatch(org.languagetool.rules.RuleMatch, Map<java.lang.String,java.lang.String>, int, org.languagetool.AnalyzedTokenReadings[], List<java.lang.Integer>) throws java.io.IOException,public boolean matches(Map<java.lang.String,java.lang.String>, org.languagetool.AnalyzedTokenReadings[], int, List<java.lang.Integer>) throws java.io.IOException<variables>