/[sdx]/sdx_v2/src/java/fr/gouv/culture/sdx/search/lucene/analysis/filter/ISOLatin1AccentFilter.java
ViewVC logotype

Contents of /sdx_v2/src/java/fr/gouv/culture/sdx/search/lucene/analysis/filter/ISOLatin1AccentFilter.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.8 - (show annotations) (download)
Mon Nov 15 11:35:29 2004 UTC (19 years, 4 months ago) by mdelperier
Branch: MAIN
Changes since 1.7: +65 -65 lines
unicode value in ISOLatin1AccentFilter.java

1 /*
2 SDX: Documentary System in XML.
3 Copyright (C) 2000, 2001, 2002 Ministere de la culture et de la communication (France), AJLSM
4
5 Ministere de la culture et de la communication,
6 Mission de la recherche et de la technologie
7 3 rue de Valois, 75042 Paris Cedex 01 (France)
8 mrt@culture.fr, michel.bottin@culture.fr
9
10 AJLSM, 17, rue Vital Carles, 33000 Bordeaux (France)
11 sevigny@ajlsm.com
12
13 This program is free software; you can redistribute it and/or
14 modify it under the terms of the GNU General Public License
15 as published by the Free Software Foundation; either version 2
16 of the License, or (at your option) any later version.
17
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
21 See the GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the
25 Free Software Foundation, Inc.
26 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
27 or connect to:
28 http://www.fsf.org/copyleft/gpl.html
29 */
30 package fr.gouv.culture.sdx.search.lucene.analysis.filter;
31
32 import org.apache.avalon.framework.logger.LogEnabled;
33 import org.apache.avalon.framework.logger.Logger;
34 import org.apache.lucene.analysis.Token;
35 import org.apache.lucene.analysis.TokenFilter;
36 import org.apache.lucene.analysis.TokenStream;
37
38 /**
39 * A filter that transforms accented characters in the ISO Latin 1 character set to their unaccented counterparts.
40 *
41 * <p>
42 * For example, the letter 'é' will be converted to 'e'.
43 * <p>
44 * This filter does'nt change the character case. If one wants to lowercase letters, it should
45 * also use another filter.
46 */
47 public class ISOLatin1AccentFilter extends TokenFilter implements LogEnabled {
48
49 /** Avalon super.getLog() to write information. */
50 private org.apache.avalon.framework.logger.Logger logger;
51
52 /**Builds a new filter*/
53 public ISOLatin1AccentFilter() {
54 }
55
56 /**
57 * Builds a filter from a token stream.
58 *
59 * @param in The input token stream.
60 */
61 public void setUp(TokenStream in) {
62 // Just keep a reference to the token stream.
63 this.input = in;
64 }
65
66 /**
67 * Transform ISOLatin1 accented characters to their unaccented counterparts.
68 */
69 public final Token next() throws java.io.IOException {
70 // We will work on the following available token.
71 Token t = input.next();
72 if (t == null) return null;
73
74 String tokenText = t.termText();
75 StringBuffer chars = new StringBuffer();
76
77 // Loop over the characters, replace those that need to be.
78 for (int i = 0; i < tokenText.length(); i++) {
79 switch (tokenText.charAt(i)) {
80 case '\u00C0':
81 case '\u00C1':
82 case '\u00C2':
83 case '\u00C3':
84 case '\u00C4':
85 case '\u00C5':
86 chars.append("A");
87 break;
88 case '\u00C6':
89 chars.append("AE");
90 break;
91 case '\u00C7':
92 chars.append("C");
93 break;
94 case '\u00C8':
95 case '\u00C9':
96 case '\u00CA':
97 case '\u00CB':
98 chars.append("E");
99 break;
100 case '\u00CC':
101 case '\u00CD':
102 case '\u00CE':
103 case '\u00CF':
104 chars.append("I");
105 break;
106 case '\u00D0':
107 chars.append("D");
108 break;
109 case '\u00D1':
110 chars.append("N");
111 break;
112 case '\u00D2':
113 case '\u00D3':
114 case '\u00D4':
115 case '\u00D5':
116 case '\u00D6':
117 case '\u00D8':
118 chars.append("O");
119 break;
120 case '\u0152':
121 chars.append("OE");
122 break;
123 case '\u00DE':
124 chars.append("TH");
125 break;
126 case '\u00D9':
127 case '\u00DA':
128 case '\u00DB':
129 case '\u00DC':
130 chars.append("U");
131 break;
132 case '\u00DD':
133 case '\u0178':
134 chars.append("Y");
135 break;
136 case '\u00E0':
137 case '\u00E1':
138 case '\u00E2':
139 case '\u00E3':
140 case '\u00E4':
141 case '\u00E5':
142 chars.append("a");
143 break;
144 case '\u00E6':
145 chars.append("ae");
146 break;
147 case '\u00E7':
148 chars.append("c");
149 break;
150 case '\u00E8':
151 case '\u00E9':
152 case '\u00EA':
153 case '\u00EB':
154 chars.append("e");
155 break;
156 case '\u00EC':
157 case '\u00ED':
158 case '\u00EE':
159 case '\u00EF':
160 chars.append("i");
161 break;
162 case '\u00F0':
163 chars.append("d");
164 break;
165 case '\u00F1':
166 chars.append("n");
167 break;
168 case '\u00F2':
169 case '\u00F3':
170 case '\u00F4':
171 case '\u00F5':
172 case '\u00F6':
173 case '\u00F8':
174 chars.append("o");
175 break;
176 case '\u0153':
177 chars.append("oe");
178 break;
179 case '\u00DF':
180 chars.append("ss");
181 break;
182 case '\u00FE':
183 chars.append("th");
184 break;
185 case '\u00F9':
186 case '\u00FA':
187 case '\u00FB':
188 case '\u00FC':
189 chars.append("u");
190 break;
191 case '\u00FD':
192 case '\u00FF':
193 chars.append("y");
194 break;
195 default:
196 chars.append(tokenText.charAt(i));
197 break;
198 }
199 }
200 // Finally we return a new token with transformed characters.
201 return new Token(chars.toString(), t.startOffset(), t.endOffset(), t.type());
202 }
203
204 /** Set's the super.getLog()
205 *
206 * @param logger The super.getLog() to use.
207 */
208 public void enableLogging(Logger logger) {
209 this.logger = logger;
210 }
211
212 }

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26