tracker-0.16.2/src/libstemmer/stem_UTF_8_norwegian.c

No issues found

  1 /*
  2  * Copyright (c) 2001, Dr Martin Porter
  3  * All rights reserved.
  4  *
  5  * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
  6  * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  7  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  8  * Neither the name of the <ORGANIZATION> nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
  9  *
 10  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 11  */
 12 
 13 
 14 
 15 /* This file was generated automatically by the Snowball to ANSI C compiler */
 16 
 17 #include "header.h"
 18 
 19 extern int norwegian_UTF_8_stem(struct SN_env * z);
 20 static int r_other_suffix(struct SN_env * z);
 21 static int r_consonant_pair(struct SN_env * z);
 22 static int r_main_suffix(struct SN_env * z);
 23 static int r_mark_regions(struct SN_env * z);
 24 
 25 extern struct SN_env * norwegian_UTF_8_create_env(void);
 26 extern void norwegian_UTF_8_close_env(struct SN_env * z);
 27 
 28 static symbol s_0_0[1] = { 'a' };
 29 static symbol s_0_1[1] = { 'e' };
 30 static symbol s_0_2[3] = { 'e', 'd', 'e' };
 31 static symbol s_0_3[4] = { 'a', 'n', 'd', 'e' };
 32 static symbol s_0_4[4] = { 'e', 'n', 'd', 'e' };
 33 static symbol s_0_5[3] = { 'a', 'n', 'e' };
 34 static symbol s_0_6[3] = { 'e', 'n', 'e' };
 35 static symbol s_0_7[6] = { 'h', 'e', 't', 'e', 'n', 'e' };
 36 static symbol s_0_8[4] = { 'e', 'r', 't', 'e' };
 37 static symbol s_0_9[2] = { 'e', 'n' };
 38 static symbol s_0_10[5] = { 'h', 'e', 't', 'e', 'n' };
 39 static symbol s_0_11[2] = { 'a', 'r' };
 40 static symbol s_0_12[2] = { 'e', 'r' };
 41 static symbol s_0_13[5] = { 'h', 'e', 't', 'e', 'r' };
 42 static symbol s_0_14[1] = { 's' };
 43 static symbol s_0_15[2] = { 'a', 's' };
 44 static symbol s_0_16[2] = { 'e', 's' };
 45 static symbol s_0_17[4] = { 'e', 'd', 'e', 's' };
 46 static symbol s_0_18[5] = { 'e', 'n', 'd', 'e', 's' };
 47 static symbol s_0_19[4] = { 'e', 'n', 'e', 's' };
 48 static symbol s_0_20[7] = { 'h', 'e', 't', 'e', 'n', 'e', 's' };
 49 static symbol s_0_21[3] = { 'e', 'n', 's' };
 50 static symbol s_0_22[6] = { 'h', 'e', 't', 'e', 'n', 's' };
 51 static symbol s_0_23[3] = { 'e', 'r', 's' };
 52 static symbol s_0_24[3] = { 'e', 't', 's' };
 53 static symbol s_0_25[2] = { 'e', 't' };
 54 static symbol s_0_26[3] = { 'h', 'e', 't' };
 55 static symbol s_0_27[3] = { 'e', 'r', 't' };
 56 static symbol s_0_28[3] = { 'a', 's', 't' };
 57 
 58 static struct among a_0[29] =
 59 {
 60 /*  0 */ { 1, s_0_0, -1, 1, 0},
 61 /*  1 */ { 1, s_0_1, -1, 1, 0},
 62 /*  2 */ { 3, s_0_2, 1, 1, 0},
 63 /*  3 */ { 4, s_0_3, 1, 1, 0},
 64 /*  4 */ { 4, s_0_4, 1, 1, 0},
 65 /*  5 */ { 3, s_0_5, 1, 1, 0},
 66 /*  6 */ { 3, s_0_6, 1, 1, 0},
 67 /*  7 */ { 6, s_0_7, 6, 1, 0},
 68 /*  8 */ { 4, s_0_8, 1, 3, 0},
 69 /*  9 */ { 2, s_0_9, -1, 1, 0},
 70 /* 10 */ { 5, s_0_10, 9, 1, 0},
 71 /* 11 */ { 2, s_0_11, -1, 1, 0},
 72 /* 12 */ { 2, s_0_12, -1, 1, 0},
 73 /* 13 */ { 5, s_0_13, 12, 1, 0},
 74 /* 14 */ { 1, s_0_14, -1, 2, 0},
 75 /* 15 */ { 2, s_0_15, 14, 1, 0},
 76 /* 16 */ { 2, s_0_16, 14, 1, 0},
 77 /* 17 */ { 4, s_0_17, 16, 1, 0},
 78 /* 18 */ { 5, s_0_18, 16, 1, 0},
 79 /* 19 */ { 4, s_0_19, 16, 1, 0},
 80 /* 20 */ { 7, s_0_20, 19, 1, 0},
 81 /* 21 */ { 3, s_0_21, 14, 1, 0},
 82 /* 22 */ { 6, s_0_22, 21, 1, 0},
 83 /* 23 */ { 3, s_0_23, 14, 1, 0},
 84 /* 24 */ { 3, s_0_24, 14, 1, 0},
 85 /* 25 */ { 2, s_0_25, -1, 1, 0},
 86 /* 26 */ { 3, s_0_26, 25, 1, 0},
 87 /* 27 */ { 3, s_0_27, -1, 3, 0},
 88 /* 28 */ { 3, s_0_28, -1, 1, 0}
 89 };
 90 
 91 static symbol s_1_0[2] = { 'd', 't' };
 92 static symbol s_1_1[2] = { 'v', 't' };
 93 
 94 static struct among a_1[2] =
 95 {
 96 /*  0 */ { 2, s_1_0, -1, -1, 0},
 97 /*  1 */ { 2, s_1_1, -1, -1, 0}
 98 };
 99 
100 static symbol s_2_0[3] = { 'l', 'e', 'g' };
101 static symbol s_2_1[4] = { 'e', 'l', 'e', 'g' };
102 static symbol s_2_2[2] = { 'i', 'g' };
103 static symbol s_2_3[3] = { 'e', 'i', 'g' };
104 static symbol s_2_4[3] = { 'l', 'i', 'g' };
105 static symbol s_2_5[4] = { 'e', 'l', 'i', 'g' };
106 static symbol s_2_6[3] = { 'e', 'l', 's' };
107 static symbol s_2_7[3] = { 'l', 'o', 'v' };
108 static symbol s_2_8[4] = { 'e', 'l', 'o', 'v' };
109 static symbol s_2_9[4] = { 's', 'l', 'o', 'v' };
110 static symbol s_2_10[7] = { 'h', 'e', 't', 's', 'l', 'o', 'v' };
111 
112 static struct among a_2[11] =
113 {
114 /*  0 */ { 3, s_2_0, -1, 1, 0},
115 /*  1 */ { 4, s_2_1, 0, 1, 0},
116 /*  2 */ { 2, s_2_2, -1, 1, 0},
117 /*  3 */ { 3, s_2_3, 2, 1, 0},
118 /*  4 */ { 3, s_2_4, 2, 1, 0},
119 /*  5 */ { 4, s_2_5, 4, 1, 0},
120 /*  6 */ { 3, s_2_6, -1, 1, 0},
121 /*  7 */ { 3, s_2_7, -1, 1, 0},
122 /*  8 */ { 4, s_2_8, 7, 1, 0},
123 /*  9 */ { 4, s_2_9, 7, 1, 0},
124 /* 10 */ { 7, s_2_10, 9, 1, 0}
125 };
126 
127 static unsigned char g_v[] = { 17, 65, 16, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 48, 0, 128 };
128 
129 static unsigned char g_s_ending[] = { 119, 125, 149, 1 };
130 
131 static symbol s_0[] = { 'k' };
132 static symbol s_1[] = { 'e', 'r' };
133 
134 static int r_mark_regions(struct SN_env * z) {
135     z->I[0] = z->l;
136     {	int c_test = z->c; /* test, line 30 */
137 	{   int c = skip_utf8(z->p, z->c, 0, z->l, + 3);
138 	    if (c < 0) return 0;
139 	    z->c = c; /* hop, line 30 */
140 	}
141 	z->I[1] = z->c; /* setmark x, line 30 */
142 	z->c = c_test;
143     }
144     while(1) { /* goto, line 31 */
145 	int c = z->c;
146 	if (!(in_grouping_U(z, g_v, 97, 248))) goto lab0;
147 	z->c = c;
148 	break;
149     lab0:
150 	z->c = c;
151 	{   int c = skip_utf8(z->p, z->c, 0, z->l, 1);
152 	    if (c < 0) return 0;
153 	    z->c = c; /* goto, line 31 */
154 	}
155     }
156     while(1) { /* gopast, line 31 */
157 	if (!(out_grouping_U(z, g_v, 97, 248))) goto lab1;
158 	break;
159     lab1:
160 	{   int c = skip_utf8(z->p, z->c, 0, z->l, 1);
161 	    if (c < 0) return 0;
162 	    z->c = c; /* gopast, line 31 */
163 	}
164     }
165     z->I[0] = z->c; /* setmark p1, line 31 */
166      /* try, line 32 */
167     if (!(z->I[0] < z->I[1])) goto lab2;
168     z->I[0] = z->I[1];
169 lab2:
170     return 1;
171 }
172 
173 static int r_main_suffix(struct SN_env * z) {
174     int among_var;
175     {	int m3; /* setlimit, line 38 */
176 	int m = z->l - z->c; (void) m;
177 	if (z->c < z->I[0]) return 0;
178 	z->c = z->I[0]; /* tomark, line 38 */
179 	m3 = z->lb; z->lb = z->c;
180 	z->c = z->l - m;
181 	z->ket = z->c; /* [, line 38 */
182 	among_var = find_among_b(z, a_0, 29); /* substring, line 38 */
183 	if (!(among_var)) { z->lb = m3; return 0; }
184 	z->bra = z->c; /* ], line 38 */
185 	z->lb = m3;
186     }
187     switch(among_var) {
188 	case 0: return 0;
189 	case 1:
190 	    {	int ret;
191 		ret = slice_del(z); /* delete, line 44 */
192 		if (ret < 0) return ret;
193 	    }
194 	    break;
195 	case 2:
196 	    {	int m = z->l - z->c; (void) m; /* or, line 46 */
197 		if (!(in_grouping_b_U(z, g_s_ending, 98, 122))) goto lab1;
198 		goto lab0;
199 	    lab1:
200 		z->c = z->l - m;
201 		if (!(eq_s_b(z, 1, s_0))) return 0;
202 		if (!(out_grouping_b_U(z, g_v, 97, 248))) return 0;
203 	    }
204 	lab0:
205 	    {	int ret;
206 		ret = slice_del(z); /* delete, line 46 */
207 		if (ret < 0) return ret;
208 	    }
209 	    break;
210 	case 3:
211 	    {	int ret;
212 		ret = slice_from_s(z, 2, s_1); /* <-, line 48 */
213 		if (ret < 0) return ret;
214 	    }
215 	    break;
216     }
217     return 1;
218 }
219 
220 static int r_consonant_pair(struct SN_env * z) {
221     {	int m_test = z->l - z->c; /* test, line 53 */
222 	{   int m3; /* setlimit, line 54 */
223 	    int m = z->l - z->c; (void) m;
224 	    if (z->c < z->I[0]) return 0;
225 	    z->c = z->I[0]; /* tomark, line 54 */
226 	    m3 = z->lb; z->lb = z->c;
227 	    z->c = z->l - m;
228 	    z->ket = z->c; /* [, line 54 */
229 	    if (!(find_among_b(z, a_1, 2))) { z->lb = m3; return 0; } /* substring, line 54 */
230 	    z->bra = z->c; /* ], line 54 */
231 	    z->lb = m3;
232 	}
233 	z->c = z->l - m_test;
234     }
235     {	int c = skip_utf8(z->p, z->c, z->lb, 0, -1);
236 	if (c < 0) return 0;
237 	z->c = c; /* next, line 59 */
238     }
239     z->bra = z->c; /* ], line 59 */
240     {	int ret;
241 	ret = slice_del(z); /* delete, line 59 */
242 	if (ret < 0) return ret;
243     }
244     return 1;
245 }
246 
247 static int r_other_suffix(struct SN_env * z) {
248     int among_var;
249     {	int m3; /* setlimit, line 63 */
250 	int m = z->l - z->c; (void) m;
251 	if (z->c < z->I[0]) return 0;
252 	z->c = z->I[0]; /* tomark, line 63 */
253 	m3 = z->lb; z->lb = z->c;
254 	z->c = z->l - m;
255 	z->ket = z->c; /* [, line 63 */
256 	among_var = find_among_b(z, a_2, 11); /* substring, line 63 */
257 	if (!(among_var)) { z->lb = m3; return 0; }
258 	z->bra = z->c; /* ], line 63 */
259 	z->lb = m3;
260     }
261     switch(among_var) {
262 	case 0: return 0;
263 	case 1:
264 	    {	int ret;
265 		ret = slice_del(z); /* delete, line 67 */
266 		if (ret < 0) return ret;
267 	    }
268 	    break;
269     }
270     return 1;
271 }
272 
273 extern int norwegian_UTF_8_stem(struct SN_env * z) {
274     {	int c = z->c; /* do, line 74 */
275 	{   int ret = r_mark_regions(z);
276 	    if (ret == 0) goto lab0; /* call mark_regions, line 74 */
277 	    if (ret < 0) return ret;
278 	}
279     lab0:
280 	z->c = c;
281     }
282     z->lb = z->c; z->c = z->l; /* backwards, line 75 */
283 
284     {	int m = z->l - z->c; (void) m; /* do, line 76 */
285 	{   int ret = r_main_suffix(z);
286 	    if (ret == 0) goto lab1; /* call main_suffix, line 76 */
287 	    if (ret < 0) return ret;
288 	}
289     lab1:
290 	z->c = z->l - m;
291     }
292     {	int m = z->l - z->c; (void) m; /* do, line 77 */
293 	{   int ret = r_consonant_pair(z);
294 	    if (ret == 0) goto lab2; /* call consonant_pair, line 77 */
295 	    if (ret < 0) return ret;
296 	}
297     lab2:
298 	z->c = z->l - m;
299     }
300     {	int m = z->l - z->c; (void) m; /* do, line 78 */
301 	{   int ret = r_other_suffix(z);
302 	    if (ret == 0) goto lab3; /* call other_suffix, line 78 */
303 	    if (ret < 0) return ret;
304 	}
305     lab3:
306 	z->c = z->l - m;
307     }
308     z->c = z->lb;
309     return 1;
310 }
311 
312 extern struct SN_env * norwegian_UTF_8_create_env(void) { return SN_create_env(0, 2, 0); }
313 
314 extern void norwegian_UTF_8_close_env(struct SN_env * z) { SN_close_env(z); }