pylucene 3.5.0-3
[pylucene.git] / lucene-java-3.5.0 / lucene / contrib / analyzers / common / src / java / org / apache / lucene / analysis / gl / GalicianStemmer.java
1 package org.apache.lucene.analysis.gl;
2
3 /**
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
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  */
19
20 import java.util.Map;
21
22 import org.apache.lucene.analysis.pt.RSLPStemmerBase;
23
24 /**
25  * Galician stemmer implementing "Regras do lematizador para o galego".
26  * 
27  * @see RSLPStemmerBase
28  * @see <a href="http://bvg.udc.es/recursos_lingua/stemming.jsp">Description of rules</a>
29  */
30 public class GalicianStemmer extends RSLPStemmerBase {
31   private static final Step plural, unification, adverb, augmentative, noun, verb, vowel;
32   
33   static {
34     Map<String,Step> steps = parse(GalicianStemmer.class, "galician.rslp");
35     plural = steps.get("Plural");
36     unification = steps.get("Unification");
37     adverb = steps.get("Adverb");
38     augmentative = steps.get("Augmentative");
39     noun = steps.get("Noun");
40     verb = steps.get("Verb");
41     vowel = steps.get("Vowel");
42   }
43   
44   /**
45    * @param s buffer, oversized to at least <code>len+1</code>
46    * @param len initial valid length of buffer
47    * @return new valid length, stemmed
48    */
49   public int stem(char s[], int len) {
50     assert s.length >= len + 1 : "this stemmer requires an oversized array of at least 1";
51     
52     len = plural.apply(s, len);
53     len = unification.apply(s, len);
54     len = adverb.apply(s, len);
55     
56     int oldlen;
57     do {
58       oldlen = len;
59       len = augmentative.apply(s, len);
60     } while (len != oldlen);
61     
62     oldlen = len;
63     len = noun.apply(s, len);
64     if (len == oldlen) { /* suffix not removed */
65       len = verb.apply(s, len);
66     }
67       
68     len = vowel.apply(s, len);
69     
70     // RSLG accent removal
71     for (int i = 0; i < len; i++)
72       switch(s[i]) {
73         case 'á': s[i] = 'a'; break;
74         case 'é':
75         case 'ê': s[i] = 'e'; break;
76         case 'í': s[i] = 'i'; break;
77         case 'ó': s[i] = 'o'; break;
78         case 'ú': s[i] = 'u'; break;
79       }
80     
81     return len;
82   }
83 }