source: main/trunk/greenstone2/common-src/indexers/mg/lib/simplefrenchstem.c@ 37351

Last change on this file since 37351 was 37351, checked in by davidb, 14 months ago

More careful definition of function externs. Macs now treat an implicit declaration of a function as an error, not a warning, and so the mg source code needs to be tightened up on its include headers

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 2.4 KB
Line 
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 **************************************************************************/
20
21#include "unitool.h"
22#include "simplefrenchstem.h"
23
24
25
26/* =========================================================================
27 * Function: simplefrenchstem
28 * Description: a simple french stemmer
29 * Input: a word string with the length in the first byte
30 * Output: the stemmed word
31 * ========================================================================= */
32
33void simplefrenchstem (unsigned char *word) {
34 unsigned short out[256]; /* temp space */
35 unsigned short *wordstart; /* points to first letter of word */
36 int last; /* last points to the last character */
37
38 /* decode */
39 utf8_word_to_unicode (word, out, 255);
40 wordstart = out + 1;
41 last = out[0]-1;
42
43
44 if (last > 4) {
45 if (wordstart[last]=='x') {
46 if (wordstart[last-1]=='u' && wordstart[last-2]=='a') {
47 wordstart[last-1]='l';
48 }
49 last--;
50
51 } else {
52 if (last>=0 && wordstart[last]=='s') last--;
53 if (last>=0 && wordstart[last]=='r') last--;
54 if (last>=0 && wordstart[last]=='e') last--;
55
56 /* letter with accent e + ' -- there are two possible encodings */
57 if (last>=0 && wordstart[last]==0xe9) {
58 last--;
59 } else if (last>=1 && wordstart[last-1]=='e' && wordstart[last]==0x301) {
60 last -= 2;
61 }
62
63 if (last >= 1 && wordstart[last]==wordstart[last-1]) last--;
64 } /* end else */
65
66 out[0] = (unsigned char)(last+1);
67 } /* end if (len > 4) */
68
69 /* re-code, make sure the result is not longer than the input */
70 unicode_to_utf8_word (out, word, word[0]+1);
71}
Note: See TracBrowser for help on using the repository browser.