mittens 0.3.0 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (174) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +8 -0
  3. data/Gemfile +2 -1
  4. data/README.md +2 -2
  5. data/Rakefile +12 -5
  6. data/ext/mittens/extconf.rb +3 -1
  7. data/lib/mittens/version.rb +1 -1
  8. data/vendor/snowball/.github/workflows/ci.yml +144 -17
  9. data/vendor/snowball/.github/workflows/coverage.yml +117 -0
  10. data/vendor/snowball/.github/workflows/runtime-tests.yml +26 -0
  11. data/vendor/snowball/.gitignore +33 -7
  12. data/vendor/snowball/CONTRIBUTING.rst +7 -0
  13. data/vendor/snowball/COPYING +1 -1
  14. data/vendor/snowball/GNUmakefile +736 -298
  15. data/vendor/snowball/NEWS +1394 -7
  16. data/vendor/snowball/README.rst +8 -8
  17. data/vendor/snowball/ada/generate/generate.adb +5 -5
  18. data/vendor/snowball/ada/src/stemmer.adb +177 -188
  19. data/vendor/snowball/ada/src/stemmer.ads +86 -89
  20. data/vendor/snowball/ada/src/stemwords.adb +21 -5
  21. data/vendor/snowball/algorithms/czech.sbl +255 -0
  22. data/vendor/snowball/algorithms/danish.sbl +22 -10
  23. data/vendor/snowball/algorithms/english.sbl +7 -4
  24. data/vendor/snowball/algorithms/esperanto.sbl +6 -7
  25. data/vendor/snowball/algorithms/estonian.sbl +9 -4
  26. data/vendor/snowball/algorithms/finnish.sbl +33 -21
  27. data/vendor/snowball/algorithms/german.sbl +5 -0
  28. data/vendor/snowball/algorithms/indonesian.sbl +115 -96
  29. data/vendor/snowball/algorithms/italian.sbl +26 -1
  30. data/vendor/snowball/algorithms/lithuanian.sbl +13 -13
  31. data/vendor/snowball/algorithms/norwegian.sbl +17 -6
  32. data/vendor/snowball/algorithms/persian.sbl +387 -0
  33. data/vendor/snowball/algorithms/polish.sbl +177 -0
  34. data/vendor/snowball/algorithms/sesotho.sbl +115 -0
  35. data/vendor/snowball/algorithms/turkish.sbl +4 -4
  36. data/vendor/snowball/compiler/analyser.c +2002 -711
  37. data/vendor/snowball/compiler/driver.c +460 -298
  38. data/vendor/snowball/compiler/generator.c +439 -1965
  39. data/vendor/snowball/compiler/generator_ada.c +605 -430
  40. data/vendor/snowball/compiler/generator_c.c +2227 -0
  41. data/vendor/snowball/compiler/generator_csharp.c +365 -274
  42. data/vendor/snowball/compiler/generator_dart.c +1476 -0
  43. data/vendor/snowball/compiler/generator_go.c +348 -270
  44. data/vendor/snowball/compiler/generator_java.c +330 -233
  45. data/vendor/snowball/compiler/generator_js.c +534 -385
  46. data/vendor/snowball/compiler/generator_pascal.c +361 -320
  47. data/vendor/snowball/compiler/generator_php.c +1445 -0
  48. data/vendor/snowball/compiler/generator_python.c +399 -299
  49. data/vendor/snowball/compiler/generator_rust.c +370 -261
  50. data/vendor/snowball/compiler/generator_zig.c +1474 -0
  51. data/vendor/snowball/compiler/header.h +153 -86
  52. data/vendor/snowball/compiler/space.c +121 -63
  53. data/vendor/snowball/compiler/tokeniser.c +286 -182
  54. data/vendor/snowball/compiler/tokens.h +71 -0
  55. data/vendor/snowball/csharp/Snowball/Among.cs +14 -26
  56. data/vendor/snowball/csharp/Snowball/AssemblyInfo.cs +3 -3
  57. data/vendor/snowball/csharp/Snowball/Stemmer.cs +41 -45
  58. data/vendor/snowball/csharp/Stemwords/Program.cs +20 -14
  59. data/vendor/snowball/cxx/.gitignore +4 -0
  60. data/vendor/snowball/cxx/generate_algorithms.pl +87 -0
  61. data/vendor/snowball/cxx/stemmer.h +12 -0
  62. data/vendor/snowball/cxx/stemwords.cxx +176 -0
  63. data/vendor/snowball/cxx/utilities.cxx +2 -0
  64. data/vendor/snowball/dart/.gitignore +4 -0
  65. data/vendor/snowball/dart/analysis_options.yaml +1 -0
  66. data/vendor/snowball/dart/example/test_app.dart +65 -0
  67. data/vendor/snowball/dart/generate_algorithms.pl +21 -0
  68. data/vendor/snowball/dart/lib/snowball.dart +18 -0
  69. data/vendor/snowball/dart/lib/src/snowball.dart +339 -0
  70. data/vendor/snowball/dart/pubspec.yaml +17 -0
  71. data/vendor/snowball/doc/libstemmer_dart_README +37 -0
  72. data/vendor/snowball/doc/libstemmer_js_README +2 -2
  73. data/vendor/snowball/doc/libstemmer_php_README +38 -0
  74. data/vendor/snowball/doc/libstemmer_python_README +3 -3
  75. data/vendor/snowball/examples/stemwords.c +18 -3
  76. data/vendor/snowball/go/README.md +12 -4
  77. data/vendor/snowball/go/env.go +12 -14
  78. data/vendor/snowball/go/stemwords/main.go +2 -1
  79. data/vendor/snowball/java/org/tartarus/snowball/CharArraySequence.java +36 -0
  80. data/vendor/snowball/java/org/tartarus/snowball/SnowballProgram.java +17 -34
  81. data/vendor/snowball/java/org/tartarus/snowball/SnowballStemmer.java +0 -2
  82. data/vendor/snowball/javascript/base-stemmer.js +219 -252
  83. data/vendor/snowball/javascript/stemwords.js +86 -58
  84. data/vendor/snowball/libstemmer/mkmodules.pl +1 -1
  85. data/vendor/snowball/libstemmer/modules.txt +4 -0
  86. data/vendor/snowball/pascal/SnowballProgram.pas +18 -31
  87. data/vendor/snowball/php/base-stemmer.php +453 -0
  88. data/vendor/snowball/php/stemwords.php +25 -0
  89. data/vendor/snowball/python/create_init.py +16 -21
  90. data/vendor/snowball/python/pyproject.toml +3 -0
  91. data/vendor/snowball/python/setup.py +5 -7
  92. data/vendor/snowball/python/snowballstemmer/among.py +1 -2
  93. data/vendor/snowball/python/snowballstemmer/basestemmer.py +24 -33
  94. data/vendor/snowball/python/stemwords.py +72 -63
  95. data/vendor/snowball/runtime/api.c +11 -42
  96. data/vendor/snowball/runtime/api.h +11 -9
  97. data/vendor/snowball/runtime/snowball_runtime.h +110 -0
  98. data/vendor/snowball/runtime/utilities.c +282 -106
  99. data/vendor/snowball/rust/src/main.rs +2 -2
  100. data/vendor/snowball/rust/src/snowball/snowball_env.rs +7 -9
  101. data/vendor/snowball/tests/compilertest +62 -0
  102. data/vendor/snowball/tests/errors/ae-errors.sbl +53 -0
  103. data/vendor/snowball/tests/errors/ae-errors.stderr +8 -0
  104. data/vendor/snowball/tests/errors/bad-dollar.sbl +14 -0
  105. data/vendor/snowball/tests/errors/bad-dollar.stderr +4 -0
  106. data/vendor/snowball/tests/errors/bad-grouping-definition.sbl +9 -0
  107. data/vendor/snowball/tests/errors/bad-grouping-definition.stderr +6 -0
  108. data/vendor/snowball/tests/errors/missing-bra.sbl +6 -0
  109. data/vendor/snowball/tests/errors/missing-bra.stderr +3 -0
  110. data/vendor/snowball/tests/errors/missing-command.sbl +9 -0
  111. data/vendor/snowball/tests/errors/missing-command.stderr +1 -0
  112. data/vendor/snowball/tests/errors/missing-ket-backwardmode.sbl +3 -0
  113. data/vendor/snowball/tests/errors/missing-ket-backwardmode.stderr +1 -0
  114. data/vendor/snowball/tests/errors/missing-ket.sbl +7 -0
  115. data/vendor/snowball/tests/errors/missing-ket.stderr +6 -0
  116. data/vendor/snowball/tests/errors/notdefined.sbl +4 -0
  117. data/vendor/snowball/tests/errors/notdefined.stderr +2 -0
  118. data/vendor/snowball/tests/errors/string-omitted.sbl +5 -0
  119. data/vendor/snowball/tests/errors/string-omitted.stderr +1 -0
  120. data/vendor/snowball/tests/errors/undeclared.sbl +20 -0
  121. data/vendor/snowball/tests/errors/undeclared.stderr +9 -0
  122. data/vendor/snowball/tests/errors/unexpected-token.sbl +24 -0
  123. data/vendor/snowball/tests/errors/unexpected-token.stderr +17 -0
  124. data/vendor/snowball/tests/errors/wrongdirection.sbl +14 -0
  125. data/vendor/snowball/tests/errors/wrongdirection.stderr +1 -0
  126. data/vendor/snowball/tests/runtime/among.sbl +19 -0
  127. data/vendor/snowball/tests/runtime/arithmeticexpr.sbl +86 -0
  128. data/vendor/snowball/tests/runtime/attachinsert.sbl +47 -0
  129. data/vendor/snowball/tests/runtime/booleans.sbl +19 -0
  130. data/vendor/snowball/tests/runtime/externals.sbl +22 -0
  131. data/vendor/snowball/tests/runtime/hop.sbl +12 -0
  132. data/vendor/snowball/tests/runtime/integertests.sbl +60 -0
  133. data/vendor/snowball/tests/runtime/intlimits.sbl +25 -0
  134. data/vendor/snowball/tests/runtime/naming.sbl +20 -0
  135. data/vendor/snowball/tests/runtime/not.sbl +30 -0
  136. data/vendor/snowball/tests/runtime/or.sbl +17 -0
  137. data/vendor/snowball/tests/runtime/repeat.sbl +16 -0
  138. data/vendor/snowball/tests/runtime/setlimit.sbl +24 -0
  139. data/vendor/snowball/tests/runtime/sizelen.sbl +56 -0
  140. data/vendor/snowball/tests/runtime/slice.sbl +27 -0
  141. data/vendor/snowball/tests/runtime/stringdollar.sbl +39 -0
  142. data/vendor/snowball/tests/runtime/strings.sbl +66 -0
  143. data/vendor/snowball/tests/runtime/test.sbl +19 -0
  144. data/vendor/snowball/tests/stemtest.c +41 -1
  145. data/vendor/snowball/tests/syntax/canon.sbl +32 -0
  146. data/vendor/snowball/tests/syntax/canon.stderr +0 -0
  147. data/vendor/snowball/tests/syntax/canon.syntax +57 -0
  148. data/vendor/snowball/tests/syntax/emptyprogram.sbl +2 -0
  149. data/vendor/snowball/tests/syntax/emptyprogram.syntax +0 -0
  150. data/vendor/snowball/tests/syntax/groupings.sbl +11 -0
  151. data/vendor/snowball/tests/syntax/inline.sbl +144 -0
  152. data/vendor/snowball/tests/syntax/inline.stderr +0 -0
  153. data/vendor/snowball/tests/syntax/inline.syntax +121 -0
  154. data/vendor/snowball/tests/syntax/legacy.sbl +17 -0
  155. data/vendor/snowball/tests/syntax/legacy.stderr +5 -0
  156. data/vendor/snowball/tests/syntax/legacy.syntax +19 -0
  157. data/vendor/snowball/tests/syntax/loops.sbl +14 -0
  158. data/vendor/snowball/tests/syntax/loops.stderr +9 -0
  159. data/vendor/snowball/tests/syntax/loops.syntax +29 -0
  160. data/vendor/snowball/tests/syntax/noops.sbl +76 -0
  161. data/vendor/snowball/tests/syntax/noops.stderr +27 -0
  162. data/vendor/snowball/tests/syntax/noops.syntax +135 -0
  163. data/vendor/snowball/tests/syntax/simplifyae.sbl +21 -0
  164. data/vendor/snowball/tests/syntax/simplifyae.stderr +0 -0
  165. data/vendor/snowball/tests/syntax/simplifyae.syntax +39 -0
  166. data/vendor/snowball/tests/syntax/unused.sbl +18 -0
  167. data/vendor/snowball/tests/syntax/unused.stderr +7 -0
  168. data/vendor/snowball/tests/syntax/unused.syntax +3 -0
  169. data/vendor/snowball/zig/env.zig +599 -0
  170. data/vendor/snowball/zig/generate_algorithms.pl +19 -0
  171. data/vendor/snowball/zig/stemwords.zig +123 -0
  172. metadata +102 -4
  173. data/vendor/snowball/compiler/syswords.h +0 -86
  174. data/vendor/snowball/runtime/header.h +0 -62
@@ -36,18 +36,18 @@ package Stemmer with SPARK_Mode is
36
36
  type Context_Type is abstract tagged private;
37
37
 
38
38
  -- Apply the stemming algorithm on the word initialized in the context.
39
- procedure Stem (Context : in out Context_Type;
40
- Result : out Boolean) is abstract;
39
+ procedure Stem (Z : in out Context_Type;
40
+ Result : out Boolean) is abstract;
41
41
 
42
42
  -- Stem the word and return True if it was reduced.
43
- procedure Stem_Word (Context : in out Context_Type'Class;
44
- Word : in String;
45
- Result : out Boolean) with
43
+ procedure Stem_Word (Z : in out Context_Type'Class;
44
+ Word : in String;
45
+ Result : out Boolean) with
46
46
  Global => null,
47
47
  Pre => Word'Length < WORD_MAX_LENGTH;
48
48
 
49
49
  -- Get the stem or the input word unmodified.
50
- function Get_Result (Context : in Context_Type'Class) return String with
50
+ function Get_Result (Z : in Context_Type'Class) return String with
51
51
  Global => null,
52
52
  Post => Get_Result'Result'Length < WORD_MAX_LENGTH;
53
53
 
@@ -82,19 +82,19 @@ private
82
82
 
83
83
  type Among_Array_Type is array (Natural range <>) of Among_Type;
84
84
 
85
- function Eq_S (Context : in Context_Type'Class;
86
- S : in String) return Char_Index with
87
- Global => null,
88
- Pre => S'Length > 0,
89
- Post => Eq_S'Result = 0 or Eq_S'Result = S'Length;
85
+ procedure Eq_S (Z : in out Context_Type'Class;
86
+ S : in String;
87
+ Len : in Char_Index;
88
+ Result : out Boolean) with
89
+ Global => null;
90
90
 
91
- function Eq_S_Backward (Context : in Context_Type'Class;
92
- S : in String) return Char_Index with
93
- Global => null,
94
- Pre => S'Length > 0,
95
- Post => Eq_S_Backward'Result = 0 or Eq_S_Backward'Result = S'Length;
91
+ procedure Eq_S_Backward (Z : in out Context_Type'Class;
92
+ S : in String;
93
+ Len : in Char_Index;
94
+ Result : out Boolean) with
95
+ Global => null;
96
96
 
97
- procedure Find_Among (Context : in out Context_Type'Class;
97
+ procedure Find_Among (Z : in out Context_Type'Class;
98
98
  Amongs : in Among_Array_Type;
99
99
  Pattern : in String;
100
100
  Execute : access procedure
@@ -105,7 +105,7 @@ private
105
105
  Global => null,
106
106
  Pre => Pattern'Length > 0 and Amongs'Length > 0;
107
107
 
108
- procedure Find_Among_Backward (Context : in out Context_Type'Class;
108
+ procedure Find_Among_Backward (Z : in out Context_Type'Class;
109
109
  Amongs : in Among_Array_Type;
110
110
  Pattern : in String;
111
111
  Execute : access procedure
@@ -116,92 +116,89 @@ private
116
116
  Global => null,
117
117
  Pre => Pattern'Length > 0 and Amongs'Length > 0;
118
118
 
119
- function Skip_Utf8 (Context : in Context_Type'Class) return Result_Index with
119
+ function Skip_Utf8 (Z : in Context_Type'Class) return Result_Index with
120
120
  Global => null;
121
121
 
122
- function Skip_Utf8 (Context : in Context_Type'Class;
123
- N : in Integer) return Result_Index with
122
+ function Skip_Utf8 (Z : in Context_Type'Class;
123
+ N : in Integer) return Result_Index with
124
124
  Global => null;
125
125
 
126
- function Skip_Utf8_Backward (Context : in Context_Type'Class) return Result_Index with
126
+ function Skip_Utf8_Backward (Z : in Context_Type'Class) return Result_Index with
127
127
  Global => null;
128
128
 
129
- function Skip_Utf8_Backward (Context : in Context_Type'Class;
130
- N : in Integer) return Result_Index with
129
+ function Skip_Utf8_Backward (Z : in Context_Type'Class;
130
+ N : in Integer) return Result_Index with
131
131
  Global => null;
132
132
 
133
- procedure Get_Utf8 (Context : in Context_Type'Class;
134
- Value : out Utf8_Type;
135
- Count : out Natural);
136
-
137
- procedure Get_Utf8_Backward (Context : in Context_Type'Class;
138
- Value : out Utf8_Type;
139
- Count : out Natural);
140
-
141
- function Length_Utf8 (Context : in Context_Type'Class) return Natural;
142
-
143
- function Length_Utf8 (S : in String) return Natural;
144
-
145
- function Check_Among (Context : in Context_Type'Class;
146
- Pos : in Char_Index;
147
- Shift : in Natural;
148
- Mask : in Mask_Type) return Boolean;
149
-
150
- procedure Out_Grouping (Context : in out Context_Type'Class;
151
- S : in Grouping_Array;
152
- Min : in Utf8_Type;
153
- Max : in Utf8_Type;
154
- Repeat : in Boolean;
155
- Result : out Result_Index);
156
-
157
- procedure Out_Grouping_Backward (Context : in out Context_Type'Class;
158
- S : in Grouping_Array;
159
- Min : in Utf8_Type;
160
- Max : in Utf8_Type;
161
- Repeat : in Boolean;
162
- Result : out Result_Index);
163
-
164
- procedure In_Grouping (Context : in out Context_Type'Class;
165
- S : in Grouping_Array;
166
- Min : in Utf8_Type;
167
- Max : in Utf8_Type;
168
- Repeat : in Boolean;
169
- Result : out Result_Index);
170
-
171
- procedure In_Grouping_Backward (Context : in out Context_Type'Class;
172
- S : in Grouping_Array;
173
- Min : in Utf8_Type;
174
- Max : in Utf8_Type;
175
- Repeat : in Boolean;
176
- Result : out Result_Index);
177
-
178
- procedure Replace (Context : in out Context_Type'Class;
179
- C_Bra : in Char_Index;
180
- C_Ket : in Char_Index;
181
- S : in String;
182
- Adjustment : out Integer) with
133
+ procedure Get_Utf8 (Z : in Context_Type'Class;
134
+ Value : out Utf8_Type;
135
+ Count : out Natural);
136
+
137
+ procedure Get_Utf8_Backward (Z : in Context_Type'Class;
138
+ Value : out Utf8_Type;
139
+ Count : out Natural);
140
+
141
+ function Length_Utf8 (S : in String;
142
+ Len : in Char_Index) return Natural;
143
+
144
+ function Check_Among (Z : in Context_Type'Class;
145
+ Pos : in Char_Index;
146
+ Shift : in Natural;
147
+ Mask : in Mask_Type) return Boolean;
148
+
149
+ procedure Out_Grouping (Z : in out Context_Type'Class;
150
+ S : in Grouping_Array;
151
+ Min : in Utf8_Type;
152
+ Max : in Utf8_Type;
153
+ Repeat : in Boolean;
154
+ Result : out Result_Index);
155
+
156
+ procedure Out_Grouping_Backward (Z : in out Context_Type'Class;
157
+ S : in Grouping_Array;
158
+ Min : in Utf8_Type;
159
+ Max : in Utf8_Type;
160
+ Repeat : in Boolean;
161
+ Result : out Result_Index);
162
+
163
+ procedure In_Grouping (Z : in out Context_Type'Class;
164
+ S : in Grouping_Array;
165
+ Min : in Utf8_Type;
166
+ Max : in Utf8_Type;
167
+ Repeat : in Boolean;
168
+ Result : out Result_Index);
169
+
170
+ procedure In_Grouping_Backward (Z : in out Context_Type'Class;
171
+ S : in Grouping_Array;
172
+ Min : in Utf8_Type;
173
+ Max : in Utf8_Type;
174
+ Repeat : in Boolean;
175
+ Result : out Result_Index);
176
+
177
+ procedure Replace (Z : in out Context_Type'Class;
178
+ C_Bra : in Char_Index;
179
+ C_Ket : in Char_Index;
180
+ S : in String;
181
+ Len : in Char_Index) with
183
182
  Global => null,
184
- Pre => C_Ket >= C_Bra;
183
+ Pre => C_Bra <= C_Ket and C_Ket <= Z.Len
184
+ and Z.Len + Len - (C_Ket - C_Bra) < Z.P'Length;
185
185
 
186
- procedure Slice_Del (Context : in out Context_Type'Class) with
186
+ procedure Slice_Del (Z : in out Context_Type'Class) with
187
187
  Global => null,
188
- Pre => Context.Ket >= Context.Bra;
188
+ Pre => Z.Bra <= Z.Ket and Z.Ket <= Z.Len;
189
189
 
190
- procedure Slice_From (Context : in out Context_Type'Class;
191
- Text : in String) with
190
+ procedure Slice_From (Z : in out Context_Type'Class;
191
+ Text : in String;
192
+ Len : in Char_Index) with
192
193
  Global => null,
193
- Pre => Context.Ket >= Context.Bra
194
- and Context.Len - (Context.Ket - Context.Bra) + Text'Length < Context.P'Length;
195
-
196
- function Slice_To (Context : in Context_Type'Class) return String;
194
+ Pre => Z.Bra <= Z.Ket and Z.Ket <= Z.Len;
197
195
 
198
- procedure Insert (Context : in out Context_Type'Class;
199
- C_Bra : in Char_Index;
200
- C_Ket : in Char_Index;
201
- S : in String) with
196
+ procedure Insert (Z : in out Context_Type'Class;
197
+ S : in String;
198
+ Len : in Char_Index) with
202
199
  Global => null,
203
- Pre => C_Ket >= C_Bra
204
- and Context.Len - (C_Ket - C_Bra) + S'Length < Context.P'Length;
200
+ Pre => Z.C <= Z.Len
201
+ and Z.Len + Len < Z.P'Length;
205
202
 
206
203
  -- The context indexes follow the C paradigm: they start at 0 for the first character.
207
204
  -- This is necessary because several algorithms rely on this when they compare the
@@ -5,38 +5,54 @@ procedure Stemwords is
5
5
 
6
6
  use Stemmer.Factory;
7
7
 
8
- function Get_Language (Name : in String) return Language_Type;
8
+ function Get_Language (Name : in String;
9
+ Error: out Boolean) return Language_Type;
9
10
  function Is_Space (C : in Character) return Boolean;
11
+ procedure Show_Usage;
10
12
 
11
13
  function Is_Space (C : in Character) return Boolean is
12
14
  begin
13
15
  return C = ' ' or C = ASCII.HT;
14
16
  end Is_Space;
15
17
 
16
- function Get_Language (Name : in String) return Language_Type is
18
+ function Get_Language (Name : in String;
19
+ Error: out Boolean) return Language_Type is
17
20
  begin
21
+ Error := False;
18
22
  return Language_Type'Value ("L_" & Name);
19
23
 
20
24
  exception
21
25
  when Constraint_Error =>
22
26
  Ada.Text_IO.Put_Line ("Unsupported language: " & Name);
23
- return L_ENGLISH;
27
+ Error := True;
28
+ return Language_Type'Val (0);
24
29
 
25
30
  end Get_Language;
26
31
 
32
+ procedure Show_Usage is
33
+ begin
34
+ Ada.Text_IO.Put_Line ("Usage: stemwords <language> <input file> <output file>");
35
+ Ada.Command_Line.Set_Exit_Status(Ada.Command_Line.Failure);
36
+ end Show_Usage;
37
+
27
38
  Count : constant Natural := Ada.Command_Line.Argument_Count;
28
39
  begin
29
40
  if Count /= 3 then
30
- Ada.Text_IO.Put_Line ("Usage: stemwords <language> <input file> <output file>");
41
+ Show_Usage;
31
42
  return;
32
43
  end if;
33
44
  declare
34
- Lang : constant Language_Type := Get_Language (Ada.Command_Line.Argument (1));
45
+ Bad_Usage : Boolean := False;
46
+ Lang : constant Language_Type := Get_Language (Ada.Command_Line.Argument (1), Bad_Usage);
35
47
  Input : constant String := Ada.Command_Line.Argument (2);
36
48
  Output : constant String := Ada.Command_Line.Argument (3);
37
49
  Src_File : Ada.Text_IO.File_Type;
38
50
  Dst_File : Ada.Text_IO.File_Type;
39
51
  begin
52
+ if Bad_Usage then
53
+ Show_Usage;
54
+ return;
55
+ end if;
40
56
  Ada.Text_IO.Open (Src_File, Ada.Text_IO.In_File, Input);
41
57
  Ada.Text_IO.Create (Dst_File, Ada.Text_IO.Out_File, Output);
42
58
  while not Ada.Text_IO.End_Of_File (Src_File) loop
@@ -0,0 +1,255 @@
1
+ routines (
2
+ R1
3
+ palatalise_e
4
+ palatalise_i
5
+ mark_regions
6
+ possessive_suffix
7
+ case_suffix
8
+ )
9
+
10
+ externals ( stem )
11
+
12
+ integers ( p1 x )
13
+
14
+ groupings ( env_ending ev_ending v v_or_syllabic_c )
15
+
16
+ stringescapes {}
17
+
18
+ stringdef a' '{U+00E1}' // á
19
+ stringdef cv '{U+010D}' // č
20
+ stringdef dv '{U+010F}' // ď
21
+ stringdef e' '{U+00E9}' // é
22
+ stringdef ev '{U+011B}' // ě
23
+ stringdef i' '{U+00ED}' // í
24
+ stringdef nv '{U+0148}' // ň
25
+ stringdef o' '{U+00F3}' // ó
26
+ stringdef rv '{U+0159}' // ř
27
+ stringdef sv '{U+0161}' // š
28
+ stringdef tv '{U+0165}' // ť
29
+ stringdef u' '{U+00FA}' // ú
30
+ stringdef uo '{U+016F}' // ů
31
+ stringdef y' '{U+00FD}' // ý
32
+ stringdef zv '{U+017E}' // ž
33
+
34
+ define v 'aeiouy{a'}{ev}{e'}{i'}{o'}{u'}{uo}{y'}'
35
+
36
+ // Some consonants in Czech can be syllabic - if these occur between two other
37
+ // consonants then they act in a vowel-like way and it is helpful to include
38
+ // them in the definition of R1.
39
+ //
40
+ // Some sources also list 'm' and 'n' as syllabic consonants for Czech but they
41
+ // seem to be much rarer and including them makes no difference to the results
42
+ // of stemming any words in our sample vocabulary list. Checking on a larger
43
+ // vocabulary list (also from wikipedia but with a lower cut-off frequency)
44
+ // all but one of the affected words don't seem to actually be Czech words.
45
+ define v_or_syllabic_c v + 'lr'
46
+
47
+ // Letters that can occur before -ev. Actual known exceptions include
48
+ // 'j' (objev, projev, výjev) and 'ř' (ohřev)
49
+ define ev_ending 'hknrtz'
50
+
51
+ // Letters that can occur before -eň. Actual known exceptions include
52
+ // 'g' (Irgeň), 'l' (zeleň), 'm' (kameň) and 'ř' (třeň).
53
+ define env_ending 'bc{cv}dhkprs{sv}tvz{zv}'
54
+
55
+ define mark_regions as (
56
+
57
+ test (hop 3 setmark x) // Signals f if the input < 3 characters.
58
+
59
+ $p1 = limit
60
+ do (
61
+ // A syllabic consonant must occur between two consonants, or be
62
+ // preceded by a consonant and at the end of the word.
63
+ //
64
+ // Instead of literally testing that, we handle the first character
65
+ // specially by only checking if it's a vowel; for subsequent
66
+ // characters we know that the character before is a consonant because
67
+ // otherwise we'd have stopped already.
68
+ //
69
+ // We also don't actually need to check the character after, since
70
+ // if it's a vowel then that vowel means we'd end up at the same
71
+ // position after `gopast non-v` anyway, and if it's the end of the
72
+ // word then there's no non-v after it.
73
+ (v or (next gopast v_or_syllabic_c)) gopast non-v
74
+ setmark p1
75
+ try($p1 < x $p1 = x) // at least 3
76
+ )
77
+ )
78
+
79
+ backwardmode (
80
+
81
+ define R1 as $p1 <= cursor
82
+
83
+ define palatalise_e as (
84
+ [substring] among (
85
+ // -c -> -k
86
+ 'c'
87
+ (<- 'k')
88
+ 'nc' // e.g. finance
89
+ 'avc' // e.g. dravce
90
+ 'ovc' // e.g. jalovce
91
+ ()
92
+ '{i'}nc' // e.g. podmínce
93
+ (<- '{i'}nk')
94
+ )
95
+ )
96
+
97
+ define palatalise_i as (
98
+ [substring] among (
99
+ // -c -> -k
100
+ 'c'
101
+ (<- 'k')
102
+ 'nc' // e.g. financí
103
+ 'avc' // e.g. nástavci
104
+ 'ovc' // e.g. pískovci
105
+ ()
106
+ '{i'}nc' // e.g. Gruzínci
107
+ (<- '{i'}nk')
108
+
109
+ '{cv}t' (<- 'ck')
110
+
111
+ // -št -> -sk
112
+ '{sv}t' // e.g. čeština
113
+ (<-'sk')
114
+ '{a'}{sv}t' // e.g. plášti
115
+ 'de{sv}t' // e.g. dešti
116
+ 'i{sv}t' // e.g. bojišti
117
+ '{i'}{sv}t' // e.g. příští
118
+ 'le{sv}t' // e.g. kleští
119
+ 'pou{sv}t' // e.g. poušti, spouští
120
+ ()
121
+ )
122
+ )
123
+
124
+ define possessive_suffix as (
125
+ [substring] R1 among (
126
+ 'ov' '{uo}v'
127
+ (delete)
128
+ 'in'
129
+ (
130
+ delete
131
+ try palatalise_i
132
+ )
133
+ )
134
+ )
135
+
136
+ define case_suffix as (
137
+ setlimit tomark p1 for ( [substring] ) among (
138
+ 'atech'
139
+ 'at{uo}m'
140
+ '{a'}ch' '{y'}ch' 'ov{e'}' '{y'}mi'
141
+ 'ata' 'aty' 'ama' 'ami' 'ovi'
142
+ 'at' '{a'}m' 'us' '{uo}m' '{y'}m' 'mi' 'ou'
143
+ '{e'}ho' '{e'}m' '{e'}mu'
144
+ 'u' 'y' '{uo}' 'a' 'o' '{a'}' '{e'}' '{y'}'
145
+ (delete)
146
+ '{ev}' '{ev}tem' '{ev}mi' '{ev}te' '{ev}ti'
147
+ '{ev}m' // e.g. koněm
148
+ (
149
+ delete
150
+ )
151
+ 'e' 'ech' 'em' 'emi'
152
+ (
153
+ delete
154
+ try palatalise_e
155
+ )
156
+ 'ete' 'eti' 'etem'
157
+ (
158
+ // t-stem neuter nouns
159
+ among (
160
+ '{cv}' // e.g. dvojč-etem
161
+ 'l' // e.g. batol-ete
162
+ '{rv}' // e.g. zvíř-ete
163
+ 's' // e.g. pras-ete
164
+ '{zv}' // e.g. páž-ete
165
+ (delete)
166
+ 'e{cv}' // e.g. pečet-i
167
+ 'tl' // e.g. atlet-i
168
+ 'es' // e.g. deset-i
169
+ ''
170
+ (
171
+ // Remove -e, -i, or -em; stem now ends -et so no palatalise
172
+ // step is needed.
173
+ <-'et'
174
+ )
175
+ )
176
+ )
177
+ 'eb'
178
+ ( // Conflate e.g. skladeb with skladba, skladbě, skladby, etc.
179
+ test non-v
180
+ not 't{rv}' // potřeb
181
+ <-'b'
182
+ )
183
+ 'ec'
184
+ ( // Conflate e.g. obec with obce, obcemi, obci, obcí, obcích.
185
+ test non-v
186
+ delete attach 'c'
187
+ try palatalise_e
188
+ )
189
+ 'ek'
190
+ ( // Conflate e.g. článek with článkem, článku, článků, článkům, články.
191
+ test non-v
192
+ not among (
193
+ 'dot' // dotek
194
+ 'obl' // oblek
195
+ 'sn' // česnek
196
+ )
197
+ <-'k'
198
+ )
199
+ '{ev}k'
200
+ ( // Conflate e.g. daněk with daňka, daňkem, daňki, daňkovi, daňků, etc.
201
+ 'n'] <-'{nv}k'
202
+ )
203
+ 'e{nv}'
204
+ ( // Conflate e.g. Plzeň with Plzně, Plzni, Plzní.
205
+ test env_ending
206
+ <-'n' // -eň -> -n not -ň
207
+ )
208
+ // -eš can also lose the -e- but this seems very uncommon - the only
209
+ // example I've seen is Aleš (a male given name or diminutive name)
210
+ // but we require 3 characters before R1 so this won't be considered
211
+ // for stemming.
212
+ //
213
+ // Also this can decline as Alše or Aleše, etc, and these alternative
214
+ // declensions mean that just removing the -e- from Aleš would not
215
+ // really help (especially as the forms which keep the -e- seem
216
+ // more common, at least based on cs.wikipedia.org) so if we did this
217
+ // we would need to also remove -e- from Aleše, etc, which seems a lot
218
+ // of complication for a single word.
219
+ 'et'
220
+ ( // Conflate e.g. počet with počte, počtu, počty, etc.
221
+ among (
222
+ 'uc' // e.g. tucet but not dvacet.
223
+ '{cv}'
224
+ 'h'
225
+ 'ok' // e.g. loket but not paket.
226
+ 'kar' // e.g. karet but not cigaret.
227
+ )
228
+ <-'t'
229
+ )
230
+ 'ev'
231
+ ( // Conflate e.g. církev with církve, církve, církvemu, církví, etc.
232
+ ev_ending
233
+ <-'v'
234
+ )
235
+ '{tv}' '{tv}mi'
236
+ ( // Conflate e.g. oběť and oběťmi with obětech; hradišť with hradišti.
237
+ <-'t'
238
+ )
239
+ 'i'
240
+ '{i'}' '{i'}ch' '{i'}ho' '{i'}m' '{i'}mi' '{i'}mu'
241
+ (
242
+ delete
243
+ try palatalise_i
244
+ )
245
+ )
246
+ )
247
+ )
248
+
249
+ define stem as (
250
+ mark_regions // Signals f if the input has < 3 characters.
251
+ backwards (
252
+ do case_suffix
253
+ do possessive_suffix
254
+ )
255
+ )
@@ -10,9 +10,9 @@ externals ( stem )
10
10
 
11
11
  strings ( ch )
12
12
 
13
- integers ( p1 x )
13
+ integers ( p1 )
14
14
 
15
- groupings ( c v s_ending )
15
+ groupings ( undouble_c v s_ending )
16
16
 
17
17
  stringescapes {}
18
18
 
@@ -22,19 +22,29 @@ stringdef ae '{U+00E6}'
22
22
  stringdef ao '{U+00E5}'
23
23
  stringdef o/ '{U+00F8}'
24
24
 
25
- define c 'bcdfghjklmnpqrstvwxz'
25
+ // Consonants which get undoubled by routine `undouble`.
26
+ define undouble_c 'bdfgklmnprst'
26
27
 
27
28
  define v 'aeiouy{ae}{ao}{o/}'
28
29
 
29
- define s_ending 'abcdfghjklmnoprtvyz{ao}'
30
+ define s_ending 'abcdfghjklmnoprtvyz{ao}{'}'
30
31
 
31
32
  define mark_regions as (
32
-
33
33
  $p1 = limit
34
34
 
35
- test ( hop 3 setmark x )
36
- gopast v gopast non-v setmark p1
37
- try ( $p1 < x $p1 = x )
35
+ do (
36
+ (
37
+ // If there's an apostrophe, start R1 after it to handle
38
+ // acronym loanwords such as "pc'en" and "ep'en".
39
+ gopast '{'}'
40
+ ) or (
41
+ gopast v gopast non-v
42
+ )
43
+ setmark p1
44
+ )
45
+
46
+ // Ensure at least 3 characters before R1.
47
+ test (hop 3 do ($p1 < cursor $p1 = cursor))
38
48
  )
39
49
 
40
50
  backwardmode (
@@ -75,7 +85,7 @@ backwardmode (
75
85
  )
76
86
  )
77
87
  define undouble as (
78
- setlimit tomark p1 for ([c] ->ch)
88
+ setlimit tomark p1 for ([undouble_c] ->ch)
79
89
  ch
80
90
  delete
81
91
  )
@@ -83,11 +93,13 @@ backwardmode (
83
93
 
84
94
  define stem as (
85
95
 
86
- do mark_regions
96
+ mark_regions
87
97
  backwards (
88
98
  do main_suffix
89
99
  do consonant_pair
90
100
  do other_suffix
91
101
  do undouble
102
+ // Remove trailing apostrophe.
103
+ ['{'}'] delete
92
104
  )
93
105
  )
@@ -42,6 +42,7 @@ define mark_regions as (
42
42
  'later' // lateral/later
43
43
  'emerg' // emerge/emergency
44
44
  'organ' // organ/organic/organize
45
+ 'inter' // intern/internal/international/internment; interfere; interval
45
46
  // ... extensions possible here ...
46
47
  ) or (gopast v gopast non-v)
47
48
  setmark p1
@@ -83,11 +84,12 @@ backwardmode (
83
84
  'eed' 'eedly'
84
85
  (
85
86
  do (
87
+ R1
86
88
  among (
87
89
  'proc' 'exc' 'succ'
88
90
  (atlimit)
89
91
  ) or (
90
- R1 <-'ee'
92
+ <-'ee'
91
93
  )
92
94
  )
93
95
  )
@@ -99,7 +101,7 @@ backwardmode (
99
101
  // dying->die, lying->die, tying->tie, vying->vie
100
102
  'y'
101
103
  (test(non-v atlimit) ] <-'ie')
102
- // Leave inning, outing, etc along.
104
+ // Leave inning, outing, etc alone.
103
105
  'inn' 'out' 'cann' 'herr' 'earr' 'even'
104
106
  (atlimit)
105
107
  )
@@ -158,8 +160,8 @@ backwardmode (
158
160
 
159
161
  define Step_3 as (
160
162
  [substring] R1 among (
161
- 'tional' (<- 'tion')
162
- 'ational' (<- 'ate')
163
+ 'tional' (<-'tion')
164
+ 'ational' (<-'ate')
163
165
  'alize' (<-'al')
164
166
  'icate' 'iciti' 'ical'
165
167
  (<-'ic')
@@ -193,6 +195,7 @@ define exception1 as (
193
195
 
194
196
  /* special changes: */
195
197
 
198
+ 'skis' (<-'ski')
196
199
  'skies' (<-'sky')
197
200
 
198
201
  /* special -LY cases */