Debian Codegraph @

algorithms/finnish.sbl

raw
1 /* Finnish stemmer.
2
3 Numbers in square brackets refer to the sections in
4 Fred Karlsson, Finnish: An Essential Grammar. Routledge, 1999
5 ISBN 0-415-20705-3
6
7 */
8
9 routines (
10 mark_regions
11 R2
12 particle_etc possessive
13 LONG VI
14 case_ending
15 i_plural
16 t_plural
17 other_endings
18 tidy
19 )
20
21 externals ( stem )
22
23 integers ( p1 p2 )
24 strings ( x )
25 booleans ( ending_removed )
26 groupings ( AEI V1 V2 particle_end )
27
28 stringescapes {}
29
30 /* special characters (in ISO Latin I) */
31
32 stringdef a" hex 'E4'
33 stringdef o" hex 'F6'
34
35 define AEI 'a{a"}ei'
36 define V1 'aeiouy{a"}{o"}'
37 define V2 'aeiou{a"}{o"}'
38 define particle_end V1 + 'nt'
39
40 define mark_regions as (
41
42 $p1 = limit
43 $p2 = limit
44
45 goto V1 gopast non-V1 setmark p1
46 goto V1 gopast non-V1 setmark p2
47 )
48
49 backwardmode (
50
51 define R2 as $p2 <= cursor
52
53 define particle_etc as (
54 setlimit tomark p1 for ([substring])
55 among(
56 'kin'
57 'kaan' 'k{a"}{a"}n'
58 'ko' 'k{o"}'
59 'han' 'h{a"}n'
60 'pa' 'p{a"}' // Particles [91]
61 (particle_end)
62 'sti' // Adverb [87]
63 (R2)
64 )
65 delete
66 )
67 define possessive as ( // [36]
68 setlimit tomark p1 for ([substring])
69 among(
70 'si'
71 (not 'k' delete) // take 'ksi' as the Comitative case
72 'ni'
73 (delete ['kse'] <- 'ksi') // kseni = ksi + ni
74 'nsa' 'ns{a"}'
75 'mme'
76 'nne'
77 (delete)
78 /* Now for Vn possessives after case endings: [36] */
79 'an'
80 (among('ta' 'ssa' 'sta' 'lla' 'lta' 'na') delete)
81 '{a"}n'
82 (among('t{a"}' 'ss{a"}' 'st{a"}'
83 'll{a"}' 'lt{a"}' 'n{a"}') delete)
84 'en'
85 (among('lle' 'ine') delete)
86 )
87 )
88
89 define LONG as
90 among('aa' 'ee' 'ii' 'oo' 'uu' '{a"}{a"}' '{o"}{o"}')
91
92 define VI as ('i' V2)
93
94 define case_ending as (
95 setlimit tomark p1 for ([substring])
96 among(
97 'han' ('a') //-.
98 'hen' ('e') // |
99 'hin' ('i') // |
100 'hon' ('o') // |
101 'h{a"}n' ('{a"}') // Illative [43]
102 'h{o"}n' ('{o"}') // |
103 'siin' VI // |
104 'seen' LONG //-'
105
106 'den' VI
107 'tten' VI // Genitive plurals [34]
108 ()
109 'n' // Genitive or Illative
110 ( try ( LONG // Illative
111 or 'ie' // Genitive
112 and next ]
113 )
114 /* otherwise Genitive */
115 )
116
117 'a' '{a"}' //-.
118 (V1 non-V1) // |
119 'tta' 'tt{a"}' // Partitive [32]
120 ('e') // |
121 'ta' 't{a"}' //-'
122
123 'ssa' 'ss{a"}' // Inessive [41]
124 'sta' 'st{a"}' // Elative [42]
125
126 'lla' 'll{a"}' // Adessive [44]
127 'lta' 'lt{a"}' // Ablative [51]
128 'lle' // Allative [46]
129 'na' 'n{a"}' // Essive [49]
130 'ksi' // Translative[50]
131 'ine' // Comitative [51]
132
133 /* Abessive and Instructive are too rare for
134 inclusion [51] */
135
136 )
137 delete
138 set ending_removed
139 )
140 define other_endings as (
141 setlimit tomark p2 for ([substring])
142 among(
143 'mpi' 'mpa' 'mp{a"}'
144 'mmi' 'mma' 'mm{a"}' // Comparative forms [85]
145 (not 'po') //-improves things
146 'impi' 'impa' 'imp{a"}'
147 'immi' 'imma' 'imm{a"}' // Superlative forms [86]
148 'eja' 'ej{a"}' // indicates agent [93.1B]
149 )
150 delete
151 )
152 define i_plural as ( // [26]
153 setlimit tomark p1 for ([substring])
154 among(
155 'i' 'j'
156 )
157 delete
158 )
159 define t_plural as ( // [26]
160 setlimit tomark p1 for (
161 ['t'] test V1
162 delete
163 )
164 setlimit tomark p2 for ([substring])
165 among(
166 'mma' (not 'po') //-mmat endings
167 'imma' //-immat endings
168 )
169 delete
170 )
171 define tidy as (
172 setlimit tomark p1 for (
173 do ( LONG and ([next] delete ) ) // undouble vowel
174 do ( [AEI] non-V1 delete ) // remove trailing a, a", e, i
175 do ( ['j'] 'o' or 'u' delete )
176 do ( ['o'] 'j' delete )
177 )
178 goto non-V1 [next] -> x x delete // undouble consonant
179 )
180 )
181
182 define stem as (
183
184 do mark_regions
185 unset ending_removed
186 backwards (
187 do particle_etc
188 do possessive
189 do case_ending
190 do other_endings
191 (ending_removed do i_plural) or do t_plural
192 do tidy
193 )
194 )