1
package org.apache.lucene.analysis.hu;
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.
21
* This algorithm is updated based on code located at:
22
* http://members.unine.ch/jacques.savoy/clef/
24
* Full copyright for that code follows:
28
* Copyright (c) 2005, Jacques Savoy
29
* All rights reserved.
31
* Redistribution and use in source and binary forms, with or without
32
* modification, are permitted provided that the following conditions are met:
34
* Redistributions of source code must retain the above copyright notice, this
35
* list of conditions and the following disclaimer. Redistributions in binary
36
* form must reproduce the above copyright notice, this list of conditions and
37
* the following disclaimer in the documentation and/or other materials
38
* provided with the distribution. Neither the name of the author nor the names
39
* of its contributors may be used to endorse or promote products derived from
40
* this software without specific prior written permission.
42
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
43
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
45
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
46
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
47
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
48
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
49
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
50
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
51
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
52
* POSSIBILITY OF SUCH DAMAGE.
55
import static org.apache.lucene.analysis.util.StemmerUtil.*;
58
* Light Stemmer for Hungarian.
60
* This stemmer implements the "UniNE" algorithm in:
61
* <i>Light Stemming Approaches for the French, Portuguese, German and Hungarian Languages</i>
64
public class HungarianLightStemmer {
65
public int stem(char s[], int len) {
66
for (int i = 0; i < len; i++)
68
case 'á': s[i] = 'a'; break;
70
case 'é': s[i] = 'e'; break;
71
case 'í': s[i] = 'i'; break;
75
case 'ö': s[i] = 'o'; break;
80
case 'ü': s[i] = 'u'; break;
83
len = removeCase(s, len);
84
len = removePossessive(s, len);
85
len = removePlural(s, len);
86
return normalize(s, len);
89
private int removeCase(char s[], int len) {
90
if (len > 6 && endsWith(s, len, "kent"))
94
if (endsWith(s, len, "nak") ||
95
endsWith(s, len, "nek") ||
96
endsWith(s, len, "val") ||
97
endsWith(s, len, "vel") ||
98
endsWith(s, len, "ert") ||
99
endsWith(s, len, "rol") ||
100
endsWith(s, len, "ban") ||
101
endsWith(s, len, "ben") ||
102
endsWith(s, len, "bol") ||
103
endsWith(s, len, "nal") ||
104
endsWith(s, len, "nel") ||
105
endsWith(s, len, "hoz") ||
106
endsWith(s, len, "hez") ||
107
endsWith(s, len, "tol"))
110
if (endsWith(s, len, "al") || endsWith(s, len, "el")) {
111
if (!isVowel(s[len-3]) && s[len-3] == s[len-4])
117
if (endsWith(s, len, "at") ||
118
endsWith(s, len, "et") ||
119
endsWith(s, len, "ot") ||
120
endsWith(s, len, "va") ||
121
endsWith(s, len, "ve") ||
122
endsWith(s, len, "ra") ||
123
endsWith(s, len, "re") ||
124
endsWith(s, len, "ba") ||
125
endsWith(s, len, "be") ||
126
endsWith(s, len, "ul") ||
127
endsWith(s, len, "ig"))
130
if ((endsWith(s, len, "on") || endsWith(s, len, "en")) && !isVowel(s[len-3]))
135
case 'n': return len - 1;
137
case 'e': if (s[len-2] == s[len-3] && !isVowel(s[len-2])) return len - 2;
144
private int removePossessive(char s[], int len) {
146
if (!isVowel(s[len-5]) &&
147
(endsWith(s, len, "atok") ||
148
endsWith(s, len, "otok") ||
149
endsWith(s, len, "etek")))
152
if (endsWith(s, len, "itek") || endsWith(s, len, "itok"))
157
if (!isVowel(s[len-4]) &&
158
(endsWith(s, len, "unk") ||
159
endsWith(s, len, "tok") ||
160
endsWith(s, len, "tek")))
163
if (isVowel(s[len-4]) && endsWith(s, len, "juk"))
166
if (endsWith(s, len, "ink"))
171
if (!isVowel(s[len-3]) &&
172
(endsWith(s, len, "am") ||
173
endsWith(s, len, "em") ||
174
endsWith(s, len, "om") ||
175
endsWith(s, len, "ad") ||
176
endsWith(s, len, "ed") ||
177
endsWith(s, len, "od") ||
178
endsWith(s, len, "uk")))
181
if (isVowel(s[len-3]) &&
182
(endsWith(s, len, "nk") ||
183
endsWith(s, len, "ja") ||
184
endsWith(s, len, "je")))
187
if (endsWith(s, len, "im") ||
188
endsWith(s, len, "id") ||
189
endsWith(s, len, "ik"))
196
case 'e': if (!isVowel(s[len-2])) return len - 1; break;
198
case 'd': if (isVowel(s[len-2])) return len - 1; break;
199
case 'i': return len - 1;
205
@SuppressWarnings("fallthrough")
206
private int removePlural(char s[], int len) {
207
if (len > 3 && s[len-1] == 'k')
211
case 'e': if (len > 4) return len - 2; /* intentional fallthru */
212
default: return len - 1;
217
private int normalize(char s[], int len) {
223
case 'o': return len - 1;
228
private boolean isVowel(char ch) {
235
case 'y': return true;
236
default: return false;