1 package org.apache.lucene.analysis.pt;
4 * Licensed to the Apache Software Foundation (ASF) under one or more
5 * contributor license agreements. See the NOTICE file distributed with
6 * this work for additional information regarding copyright ownership.
7 * The ASF licenses this file to You under the Apache License, Version 2.0
8 * (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
23 * Portuguese stemmer implementing the RSLP (Removedor de Sufixos da Lingua Portuguesa)
24 * algorithm. This is sometimes also referred to as the Orengo stemmer.
26 * @see RSLPStemmerBase
28 public class PortugueseStemmer extends RSLPStemmerBase {
29 private static final Step plural, feminine, adverb, augmentative, noun, verb, vowel;
32 Map<String,Step> steps = parse(PortugueseStemmer.class, "portuguese.rslp");
33 plural = steps.get("Plural");
34 feminine = steps.get("Feminine");
35 adverb = steps.get("Adverb");
36 augmentative = steps.get("Augmentative");
37 noun = steps.get("Noun");
38 verb = steps.get("Verb");
39 vowel = steps.get("Vowel");
43 * @param s buffer, oversized to at least <code>len+1</code>
44 * @param len initial valid length of buffer
45 * @return new valid length, stemmed
47 public int stem(char s[], int len) {
48 assert s.length >= len + 1 : "this stemmer requires an oversized array of at least 1";
50 len = plural.apply(s, len);
51 len = adverb.apply(s, len);
52 len = feminine.apply(s, len);
53 len = augmentative.apply(s, len);
56 len = noun.apply(s, len);
58 if (len == oldlen) { /* suffix not removed */
61 len = verb.apply(s, len);
63 if (len == oldlen) { /* suffix not removed */
64 len = vowel.apply(s, len);
68 // rslp accent removal
69 for (int i = 0; i < len; i++) {
76 case 'å': s[i] = 'a'; break;
77 case 'ç': s[i] = 'c'; break;
81 case 'ë': s[i] = 'e'; break;
85 case 'ï': s[i] = 'i'; break;
86 case 'ñ': s[i] = 'n'; break;
91 case 'ö': s[i] = 'o'; break;
95 case 'ü': s[i] = 'u'; break;
97 case 'ÿ': s[i] = 'y'; break;