Step 1
Search for the longest among the following suffixes in R1, and perform the action indicated.
355333
private function step1()
    {
        //  erte   ert
        //      replace with er
        if ( ($position = $this->searchIfInR1(array('erte', 'ert'))) !== false) {
            $this->word = preg_replace('#(erte|ert)$#u', 'er', $this->word);
            return true;
        }

         // a   e   ede   ande   ende   ane   ene   hetene   en   heten   ar   er   heter   as   es   edes   endes   enes   hetenes   ens   hetens   ers   ets   et   het   ast
        //      delete
        if ( ($position = $this->searchIfInR1(array(
            'hetenes', 'hetene', 'hetens', 'heten', 'endes', 'heter', 'ande', 'ende', 'enes', 'edes', 'ede', 'ane',
            'ene', 'het', 'ers', 'ets', 'ast', 'ens', 'en', 'ar', 'er', 'as', 'es', 'et', 'a', 'e'
        ))) !== false) {
            $this->word = Utf8::substr($this->word, 0, $position);
            return true;
        }

        //  s
        //      delete if preceded by a valid s-ending
        if ( ($position = $this->searchIfInR1(array('s'))) !== false) {
            $word = Utf8::substr($this->word, 0, $position);
            if ($this->hasValidSEnding($word)) {
                $this->word = $word;
            }
            return true;
        }
    }
886621
private static function r1($word, &$r1, &$r1Index)
    {
        list($index, $value) = self::rx($word);

        $r1 = $value;
        $r1Index = $index;

        return true;
    }
68106
def prefix(filename):
    '''  '''
    return os.path.split(re.sub(_afni_suffix_regex,"",str(filename)))[1]
1193943
def longest(*args):
    """"""
    internal_assert(len(args) >= 2, "longest expects at least two args")
    matcher = args[0] + skip_whitespace
    for elem in args[1:]:
        matcher ^= elem + skip_whitespace
    return matcher
829124
private void advance() {
        try {
            // loop until we find a word in the reader, or there are no more
            // words
            while (true) {
                // if we haven't looked at any lines yet, or if the index into
                // the current line is already at the end 
                if (curLine == null || !matcher.find()) {

                    String line = br.readLine();
                    
                    // if there aren't any more lines in the reader, then mark
                    // next as null to indicate that there are no more words
                    if (line == null) {
                        next = null;
                        br.close();
                        return;
                    }
                    
                    // create a new matcher to find all the tokens in this line
                    matcher = notWhiteSpace.matcher(line);
                    curLine = line;
                    
                    // skip lines with no matches
                    if (!matcher.find())
                        continue;                    
                }

                next = curLine.substring(matcher.start(), matcher.end());
                break;
            }
        } catch (IOException ioe) {
            throw new IOError(ioe);
        }
    }
251642
static boolean checkWildCards(final SearchableString value, final Literal[] suffixes, final int start,
            final int end) {

        if (suffixes == null) {
            // No wildcards
            return start == end + 1;
        }

        // One wildcard
        if (suffixes.length == 0) {
            return start <= end + 1;
        }

        int from = start;
        for (final Literal suffix : suffixes) {

            final int match = checkWildCard(value, suffix, from);
            if (match == -1) {
                return false;
            }

            from = suffix.getLength() + match;
            if (from > end + 1) {
                return false;
            }
        }

        return true;
    }
269989
public function step1()
    {
        // delete if in R2
        if ( ($position = $this->search(array(
            'amentos', 'imentos', 'adoras', 'adores', 'amento', 'imento', 'adora', 'istas', 'ismos', 'antes', 'ância',
            'ezas', 'eza', 'icos', 'icas', 'ismo', 'ável', 'ível', 'ista', 'oso',
            'osos', 'osas', 'osa', 'ico', 'ica', 'ador', 'aça~o', 'aço~es' , 'ante'))) !== false) {

            if ($this->inR2($position)) {
                $this->word = Utf8::substr($this->word, 0, $position);
            }
            return true;
        }

        // logía   logías
        //      replace with log if in R2
        if ( ($position = $this->search(array('logías', 'logía'))) !== false) {
            if ($this->inR2($position)) {
                $this->word = preg_replace('#(logías|logía)$#u', 'log', $this->word);
            }
            return true;
        }

        // ución   uciones
        //      replace with u if in R2
        if ( ($position = $this->search(array('uciones', 'ución'))) !== false) {
            if ($this->inR2($position)) {
                $this->word = preg_replace('#(uciones|ución)$#u', 'u', $this->word);
            }
            return true;
        }

        // ência    ências
        //      replace with ente if in R2
        if ( ($position = $this->search(array('ências', 'ência'))) !== false) {
            if ($this->inR2($position)) {
                $this->word = preg_replace('#(ências|ência)$#u', 'ente', $this->word);
            }
            return true;
        }

        // amente
        //      delete if in R1
        //      if preceded by iv, delete if in R2 (and if further preceded by at, delete if in R2), otherwise,
        //      if preceded by os, ic or ad, delete if in R2
        if ( ($position = $this->search(array('amente'))) !== false) {

            // delete if in R1
            if ($this->inR1($position)) {
                $this->word = Utf8::substr($this->word, 0, $position);
            }

            // if preceded by iv, delete if in R2 (and if further preceded by at, delete if in R2), otherwise,
            if ( ($position2 = $this->searchIfInR2(array('iv'))) !== false) {
                $this->word = Utf8::substr($this->word, 0, $position2);
                if ( ($position3 = $this->searchIfInR2(array('at'))) !== false) {
                    $this->word = Utf8::substr($this->word, 0, $position3);
                }

                // if preceded by os, ic or ad, delete if in R2
            } elseif ( ($position4 = $this->searchIfInR2(array('os', 'ic', 'ad'))) !== false) {
                $this->word = Utf8::substr($this->word, 0, $position4);
            }
            return true;
        }

        // mente
        //      delete if in R2
        //      if preceded by ante, avel or ível, delete if in R2
        if ( ($position = $this->search(array('mente'))) !== false) {

            // delete if in R2
            if ($this->inR2($position)) {
                $this->word = Utf8::substr($this->word, 0, $position);
            }

            // if preceded by ante, avel or ível, delete if in R2
            if ( ($position2 = $this->searchIfInR2(array('ante', 'avel', 'ível'))) != false) {
                $this->word = Utf8::substr($this->word, 0, $position2);
            }
            return true;
        }

        // idade   idades
        //      delete if in R2
        //      if preceded by abil, ic or iv, delete if in R2
        if ( ($position = $this->search(array('idades', 'idade'))) !== false) {

            // delete if in R2
            if ($this->inR2($position)) {
                $this->word = Utf8::substr($this->word, 0, $position);
            }

            // if preceded by abil, ic or iv, delete if in R2
            if ( ($position2 = $this->searchIfInR2(array('abil', 'ic', 'iv'))) !== false) {
                $this->word = Utf8::substr($this->word, 0, $position2);
            }
            return true;
        }

        // iva   ivo   ivas   ivos
        //      delete if in R2
        //      if preceded by at, delete if in R2
        if ( ($position = $this->search(array('ivas', 'ivos', 'iva', 'ivo'))) !== false) {

            // delete if in R2
            if ($this->inR2($position)) {
                $this->word = Utf8::substr($this->word, 0, $position);
            }

            // if preceded by at, delete if in R2
            if ( ($position2 = $this->searchIfInR2(array('at'))) !== false) {
                $this->word = Utf8::substr($this->word, 0, $position2);
            }
            return true;
        }

        // ira   iras
        //      replace with ir if in RV and preceded by e
        if ( ($position = $this->search(array('iras', 'ira'))) !== false) {

            if ($this->inRv($position)) {
                $before = $position -1;
                $letter = Utf8::substr($this->word, $before, 1);

                if ($letter == 'e') {
                    $this->word = preg_replace('#(iras|ira)$#u', 'ir', $this->word);
                }
            }
            return true;
        }

        return false;
    }
577976
public static boolean match(final String stringToMatch, final String suffixes[])
	{
		for (final String suffix : suffixes)
		{
			final int suffixesLength = suffix.length();
			final int stringToMatchLength = stringToMatch.length();
			final int result = stringToMatchLength - suffixesLength;
			final String extensionToMatch = stringToMatch.substring(result, stringToMatchLength);
			final boolean equals = extensionToMatch.equalsIgnoreCase(suffix);
			if (stringToMatchLength >= suffixesLength && equals)
			{
				return true;
			}
		}
		return false;
	}
509320
public static Pattern longest(final Pattern... patterns) {
    return new Pattern() {
      @Override
      public int match(CharSequence src, int begin, int end) {
        int r = MISMATCH;
        for (Pattern pattern : patterns) {
          int l = pattern.match(src, begin, end);
          if (l > r)
            r = l;
        }
        return r;
      }
    };
  }
374784
def delete_suffixes(self, word):
        
        length = len(word)
        suffixes = ['al', 'ance', 'ence', 'er', 'ic', 'able', 'ible',
                    'ant', 'ement', 'ment', 'ent', 'ism', 'ate',
                    'iti', 'ous', 'ive', 'ize']

        for suffix in suffixes:
            if word.endswith(suffix) and self.r2 <= (length - len(suffix)):
                word = word[:-len(suffix)]
                return word

        if word.endswith('ion') and self.r2 <= (length - 3):
            if word[length - 4] in 'st':
                word = word[:-3]

        return word
623489
private function step0()
    {
        if ( ($position = $this->search(array("'s'", "'s", "'"))) !== false) {
            $this->word = Utf8::substr($this->word, 0, $position);
        }
    }
671388
private final void step4() {
        switch (b[k]) {
            case 'e':
                if (endWith("icate")) {
                    r("ic");
                    break;
                }
                if (endWith("ative")) {
                    r("");
                    break;
                }
                if (endWith("alize")) {
                    r("al");
                    break;
                }
                break;
            case 'i':
                if (endWith("iciti")) {
                    r("ic");
                    break;
                }
                break;
            case 'l':
                if (endWith("ical")) {
                    r("ic");
                    break;
                }
                if (endWith("ful")) {
                    r("");
                    break;
                }
                break;
            case 's':
                if (endWith("ness")) {
                    r("");
                    break;
                }
                break;
        }
    }
86001
def step1c(self):
        """"""
        if self.ends("y") and self.vowelinstem():
            self.b = self.b[: self.k] + "i" + self.b[self.k + 1 :]
1157489
def find_next_word_beginning(self, count=1, WORD=False):
        
        if count < 0:
            return self.find_previous_word_beginning(count=-count, WORD=WORD)

        regex = _FIND_BIG_WORD_RE if WORD else _FIND_WORD_RE
        iterator = regex.finditer(self.text_after_cursor)

        try:
            for i, match in enumerate(iterator):
                # Take first match, unless it's the word on which we're right now.
                if i == 0 and match.start(1) == 0:
                    count += 1

                if i + 1 == count:
                    return match.start(1)
        except StopIteration:
            pass
1018651
public int findFirst(String str, String search) {
        return (str == null || search == null) ? -1 :
            str.indexOf(search);
    }
791583
protected function r1()
    {
        list($this->r1Index, $this->r1) = $this->rx($this->word);
    }
1324101
protected List<HString> longestMatchFirst(@NonNull HString source) {
      List<HString> results = new LinkedList<>();
      List<Annotation> tokens = source.tokens();
      Predicate<HString> prefix = (this instanceof PrefixSearchable)
                                  ? Cast.<PrefixSearchable>as(this)::isPrefixMatch
                                  : h -> true;

      for (int i = 0; i < tokens.size(); ) {
         Annotation token = tokens.get(i);
         if (prefix.test(token)) {

            LexiconMatch bestMatch = null;
            for (int j = i + 1; j <= tokens.size() && j < (i + 1 + longestLemma); j++) {
               HString temp = HString.union(tokens.subList(i, j));
               List<LexiconEntry> entries = getEntries(temp);
               if (entries.size() > 0) {
                  bestMatch = new LexiconMatch(temp, entries.get(0));
               }
               if (!prefix.test(temp)) {
                  break;
               }
            }

            if (bestMatch != null) {
               results.add(createFragment(bestMatch));
               i += bestMatch.getSpan().tokenLength();
            } else {
               i++;
            }

         } else if (test(token)) {
            results.add(createFragment(new LexiconMatch(token, getEntries(token).get(0))));
            i++;
         } else {
            i++;
         }
      }

      return results;
   }