1 | /**************************************************************************
|
---|
2 | *
|
---|
3 | * simplefrenchstem.c -- a simple french stemmer
|
---|
4 | *
|
---|
5 | * This program is free software; you can redistribute it and/or modify
|
---|
6 | * it under the terms of the GNU General Public License as published by
|
---|
7 | * the Free Software Foundation; either version 2 of the License, or
|
---|
8 | * (at your option) any later version.
|
---|
9 | *
|
---|
10 | * This program is distributed in the hope that it will be useful,
|
---|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
13 | * GNU General Public License for more details.
|
---|
14 | *
|
---|
15 | * You should have received a copy of the GNU General Public License
|
---|
16 | * along with this program; if not, write to the Free Software
|
---|
17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
18 | *
|
---|
19 | * $Id: simplefrenchstem.c 3745 2003-02-20 21:20:24Z mdewsnip $
|
---|
20 | *
|
---|
21 | **************************************************************************/
|
---|
22 |
|
---|
23 | #include "simplefrenchstem.h"
|
---|
24 |
|
---|
25 |
|
---|
26 |
|
---|
27 | /* =========================================================================
|
---|
28 | * Function: simplefrenchstem
|
---|
29 | * Description: a simple french stemmer
|
---|
30 | * Input: a word string with the length in the first byte
|
---|
31 | * Output: the stemmed word
|
---|
32 | * ========================================================================= */
|
---|
33 |
|
---|
34 | void simplefrenchstem (unsigned char *word) {
|
---|
35 | unsigned short out[256]; /* temp space */
|
---|
36 | unsigned short *wordstart; /* points to first letter of word */
|
---|
37 | int last; /* last points to the last character */
|
---|
38 |
|
---|
39 | /* decode */
|
---|
40 | utf8_word_to_unicode (word, out, 255);
|
---|
41 | wordstart = out + 1;
|
---|
42 | last = out[0]-1;
|
---|
43 |
|
---|
44 |
|
---|
45 | if (last > 4) {
|
---|
46 | if (wordstart[last]=='x') {
|
---|
47 | if (wordstart[last-1]=='u' && wordstart[last-2]=='a') {
|
---|
48 | wordstart[last-1]='l';
|
---|
49 | }
|
---|
50 | last--;
|
---|
51 |
|
---|
52 | } else {
|
---|
53 | if (last>=0 && wordstart[last]=='s') last--;
|
---|
54 | if (last>=0 && wordstart[last]=='r') last--;
|
---|
55 | if (last>=0 && wordstart[last]=='e') last--;
|
---|
56 |
|
---|
57 | /* letter with accent e + ' -- there are two possible encodings */
|
---|
58 | if (last>=0 && wordstart[last]==0xe9) {
|
---|
59 | last--;
|
---|
60 | } else if (last>=1 && wordstart[last-1]=='e' && wordstart[last]==0x301) {
|
---|
61 | last -= 2;
|
---|
62 | }
|
---|
63 |
|
---|
64 | if (last >= 1 && wordstart[last]==wordstart[last-1]) last--;
|
---|
65 | } /* end else */
|
---|
66 |
|
---|
67 | out[0] = (unsigned char)(last+1);
|
---|
68 | } /* end if (len > 4) */
|
---|
69 |
|
---|
70 | /* re-code, make sure the result is not longer than the input */
|
---|
71 | unicode_to_utf8_word (out, word, word[0]+1);
|
---|
72 | }
|
---|