mittens 0.3.1 → 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 (173) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +4 -0
  3. data/Gemfile +1 -0
  4. data/README.md +2 -2
  5. data/Rakefile +10 -3
  6. data/lib/mittens/version.rb +1 -1
  7. data/vendor/snowball/.github/workflows/ci.yml +144 -17
  8. data/vendor/snowball/.github/workflows/coverage.yml +117 -0
  9. data/vendor/snowball/.github/workflows/runtime-tests.yml +26 -0
  10. data/vendor/snowball/.gitignore +33 -7
  11. data/vendor/snowball/CONTRIBUTING.rst +7 -0
  12. data/vendor/snowball/COPYING +1 -1
  13. data/vendor/snowball/GNUmakefile +736 -298
  14. data/vendor/snowball/NEWS +1394 -7
  15. data/vendor/snowball/README.rst +8 -8
  16. data/vendor/snowball/ada/generate/generate.adb +5 -5
  17. data/vendor/snowball/ada/src/stemmer.adb +177 -188
  18. data/vendor/snowball/ada/src/stemmer.ads +86 -89
  19. data/vendor/snowball/ada/src/stemwords.adb +21 -5
  20. data/vendor/snowball/algorithms/czech.sbl +255 -0
  21. data/vendor/snowball/algorithms/danish.sbl +22 -10
  22. data/vendor/snowball/algorithms/english.sbl +7 -4
  23. data/vendor/snowball/algorithms/esperanto.sbl +6 -7
  24. data/vendor/snowball/algorithms/estonian.sbl +9 -4
  25. data/vendor/snowball/algorithms/finnish.sbl +33 -21
  26. data/vendor/snowball/algorithms/german.sbl +5 -0
  27. data/vendor/snowball/algorithms/indonesian.sbl +115 -96
  28. data/vendor/snowball/algorithms/italian.sbl +26 -1
  29. data/vendor/snowball/algorithms/lithuanian.sbl +13 -13
  30. data/vendor/snowball/algorithms/norwegian.sbl +17 -6
  31. data/vendor/snowball/algorithms/persian.sbl +387 -0
  32. data/vendor/snowball/algorithms/polish.sbl +177 -0
  33. data/vendor/snowball/algorithms/sesotho.sbl +115 -0
  34. data/vendor/snowball/algorithms/turkish.sbl +4 -4
  35. data/vendor/snowball/compiler/analyser.c +2002 -711
  36. data/vendor/snowball/compiler/driver.c +460 -298
  37. data/vendor/snowball/compiler/generator.c +439 -1965
  38. data/vendor/snowball/compiler/generator_ada.c +605 -430
  39. data/vendor/snowball/compiler/generator_c.c +2227 -0
  40. data/vendor/snowball/compiler/generator_csharp.c +365 -274
  41. data/vendor/snowball/compiler/generator_dart.c +1476 -0
  42. data/vendor/snowball/compiler/generator_go.c +348 -270
  43. data/vendor/snowball/compiler/generator_java.c +330 -233
  44. data/vendor/snowball/compiler/generator_js.c +534 -385
  45. data/vendor/snowball/compiler/generator_pascal.c +361 -320
  46. data/vendor/snowball/compiler/generator_php.c +1445 -0
  47. data/vendor/snowball/compiler/generator_python.c +399 -299
  48. data/vendor/snowball/compiler/generator_rust.c +370 -261
  49. data/vendor/snowball/compiler/generator_zig.c +1474 -0
  50. data/vendor/snowball/compiler/header.h +153 -86
  51. data/vendor/snowball/compiler/space.c +121 -63
  52. data/vendor/snowball/compiler/tokeniser.c +286 -182
  53. data/vendor/snowball/compiler/tokens.h +71 -0
  54. data/vendor/snowball/csharp/Snowball/Among.cs +14 -26
  55. data/vendor/snowball/csharp/Snowball/AssemblyInfo.cs +3 -3
  56. data/vendor/snowball/csharp/Snowball/Stemmer.cs +41 -45
  57. data/vendor/snowball/csharp/Stemwords/Program.cs +20 -14
  58. data/vendor/snowball/cxx/.gitignore +4 -0
  59. data/vendor/snowball/cxx/generate_algorithms.pl +87 -0
  60. data/vendor/snowball/cxx/stemmer.h +12 -0
  61. data/vendor/snowball/cxx/stemwords.cxx +176 -0
  62. data/vendor/snowball/cxx/utilities.cxx +2 -0
  63. data/vendor/snowball/dart/.gitignore +4 -0
  64. data/vendor/snowball/dart/analysis_options.yaml +1 -0
  65. data/vendor/snowball/dart/example/test_app.dart +65 -0
  66. data/vendor/snowball/dart/generate_algorithms.pl +21 -0
  67. data/vendor/snowball/dart/lib/snowball.dart +18 -0
  68. data/vendor/snowball/dart/lib/src/snowball.dart +339 -0
  69. data/vendor/snowball/dart/pubspec.yaml +17 -0
  70. data/vendor/snowball/doc/libstemmer_dart_README +37 -0
  71. data/vendor/snowball/doc/libstemmer_js_README +2 -2
  72. data/vendor/snowball/doc/libstemmer_php_README +38 -0
  73. data/vendor/snowball/doc/libstemmer_python_README +3 -3
  74. data/vendor/snowball/examples/stemwords.c +18 -3
  75. data/vendor/snowball/go/README.md +12 -4
  76. data/vendor/snowball/go/env.go +12 -14
  77. data/vendor/snowball/go/stemwords/main.go +2 -1
  78. data/vendor/snowball/java/org/tartarus/snowball/CharArraySequence.java +36 -0
  79. data/vendor/snowball/java/org/tartarus/snowball/SnowballProgram.java +17 -34
  80. data/vendor/snowball/java/org/tartarus/snowball/SnowballStemmer.java +0 -2
  81. data/vendor/snowball/javascript/base-stemmer.js +219 -252
  82. data/vendor/snowball/javascript/stemwords.js +86 -58
  83. data/vendor/snowball/libstemmer/mkmodules.pl +1 -1
  84. data/vendor/snowball/libstemmer/modules.txt +4 -0
  85. data/vendor/snowball/pascal/SnowballProgram.pas +18 -31
  86. data/vendor/snowball/php/base-stemmer.php +453 -0
  87. data/vendor/snowball/php/stemwords.php +25 -0
  88. data/vendor/snowball/python/create_init.py +16 -21
  89. data/vendor/snowball/python/pyproject.toml +3 -0
  90. data/vendor/snowball/python/setup.py +5 -7
  91. data/vendor/snowball/python/snowballstemmer/among.py +1 -2
  92. data/vendor/snowball/python/snowballstemmer/basestemmer.py +24 -33
  93. data/vendor/snowball/python/stemwords.py +72 -63
  94. data/vendor/snowball/runtime/api.c +11 -42
  95. data/vendor/snowball/runtime/api.h +11 -9
  96. data/vendor/snowball/runtime/snowball_runtime.h +110 -0
  97. data/vendor/snowball/runtime/utilities.c +282 -106
  98. data/vendor/snowball/rust/src/main.rs +2 -2
  99. data/vendor/snowball/rust/src/snowball/snowball_env.rs +7 -9
  100. data/vendor/snowball/tests/compilertest +62 -0
  101. data/vendor/snowball/tests/errors/ae-errors.sbl +53 -0
  102. data/vendor/snowball/tests/errors/ae-errors.stderr +8 -0
  103. data/vendor/snowball/tests/errors/bad-dollar.sbl +14 -0
  104. data/vendor/snowball/tests/errors/bad-dollar.stderr +4 -0
  105. data/vendor/snowball/tests/errors/bad-grouping-definition.sbl +9 -0
  106. data/vendor/snowball/tests/errors/bad-grouping-definition.stderr +6 -0
  107. data/vendor/snowball/tests/errors/missing-bra.sbl +6 -0
  108. data/vendor/snowball/tests/errors/missing-bra.stderr +3 -0
  109. data/vendor/snowball/tests/errors/missing-command.sbl +9 -0
  110. data/vendor/snowball/tests/errors/missing-command.stderr +1 -0
  111. data/vendor/snowball/tests/errors/missing-ket-backwardmode.sbl +3 -0
  112. data/vendor/snowball/tests/errors/missing-ket-backwardmode.stderr +1 -0
  113. data/vendor/snowball/tests/errors/missing-ket.sbl +7 -0
  114. data/vendor/snowball/tests/errors/missing-ket.stderr +6 -0
  115. data/vendor/snowball/tests/errors/notdefined.sbl +4 -0
  116. data/vendor/snowball/tests/errors/notdefined.stderr +2 -0
  117. data/vendor/snowball/tests/errors/string-omitted.sbl +5 -0
  118. data/vendor/snowball/tests/errors/string-omitted.stderr +1 -0
  119. data/vendor/snowball/tests/errors/undeclared.sbl +20 -0
  120. data/vendor/snowball/tests/errors/undeclared.stderr +9 -0
  121. data/vendor/snowball/tests/errors/unexpected-token.sbl +24 -0
  122. data/vendor/snowball/tests/errors/unexpected-token.stderr +17 -0
  123. data/vendor/snowball/tests/errors/wrongdirection.sbl +14 -0
  124. data/vendor/snowball/tests/errors/wrongdirection.stderr +1 -0
  125. data/vendor/snowball/tests/runtime/among.sbl +19 -0
  126. data/vendor/snowball/tests/runtime/arithmeticexpr.sbl +86 -0
  127. data/vendor/snowball/tests/runtime/attachinsert.sbl +47 -0
  128. data/vendor/snowball/tests/runtime/booleans.sbl +19 -0
  129. data/vendor/snowball/tests/runtime/externals.sbl +22 -0
  130. data/vendor/snowball/tests/runtime/hop.sbl +12 -0
  131. data/vendor/snowball/tests/runtime/integertests.sbl +60 -0
  132. data/vendor/snowball/tests/runtime/intlimits.sbl +25 -0
  133. data/vendor/snowball/tests/runtime/naming.sbl +20 -0
  134. data/vendor/snowball/tests/runtime/not.sbl +30 -0
  135. data/vendor/snowball/tests/runtime/or.sbl +17 -0
  136. data/vendor/snowball/tests/runtime/repeat.sbl +16 -0
  137. data/vendor/snowball/tests/runtime/setlimit.sbl +24 -0
  138. data/vendor/snowball/tests/runtime/sizelen.sbl +56 -0
  139. data/vendor/snowball/tests/runtime/slice.sbl +27 -0
  140. data/vendor/snowball/tests/runtime/stringdollar.sbl +39 -0
  141. data/vendor/snowball/tests/runtime/strings.sbl +66 -0
  142. data/vendor/snowball/tests/runtime/test.sbl +19 -0
  143. data/vendor/snowball/tests/stemtest.c +41 -1
  144. data/vendor/snowball/tests/syntax/canon.sbl +32 -0
  145. data/vendor/snowball/tests/syntax/canon.stderr +0 -0
  146. data/vendor/snowball/tests/syntax/canon.syntax +57 -0
  147. data/vendor/snowball/tests/syntax/emptyprogram.sbl +2 -0
  148. data/vendor/snowball/tests/syntax/emptyprogram.syntax +0 -0
  149. data/vendor/snowball/tests/syntax/groupings.sbl +11 -0
  150. data/vendor/snowball/tests/syntax/inline.sbl +144 -0
  151. data/vendor/snowball/tests/syntax/inline.stderr +0 -0
  152. data/vendor/snowball/tests/syntax/inline.syntax +121 -0
  153. data/vendor/snowball/tests/syntax/legacy.sbl +17 -0
  154. data/vendor/snowball/tests/syntax/legacy.stderr +5 -0
  155. data/vendor/snowball/tests/syntax/legacy.syntax +19 -0
  156. data/vendor/snowball/tests/syntax/loops.sbl +14 -0
  157. data/vendor/snowball/tests/syntax/loops.stderr +9 -0
  158. data/vendor/snowball/tests/syntax/loops.syntax +29 -0
  159. data/vendor/snowball/tests/syntax/noops.sbl +76 -0
  160. data/vendor/snowball/tests/syntax/noops.stderr +27 -0
  161. data/vendor/snowball/tests/syntax/noops.syntax +135 -0
  162. data/vendor/snowball/tests/syntax/simplifyae.sbl +21 -0
  163. data/vendor/snowball/tests/syntax/simplifyae.stderr +0 -0
  164. data/vendor/snowball/tests/syntax/simplifyae.syntax +39 -0
  165. data/vendor/snowball/tests/syntax/unused.sbl +18 -0
  166. data/vendor/snowball/tests/syntax/unused.stderr +7 -0
  167. data/vendor/snowball/tests/syntax/unused.syntax +3 -0
  168. data/vendor/snowball/zig/env.zig +599 -0
  169. data/vendor/snowball/zig/generate_algorithms.pl +19 -0
  170. data/vendor/snowball/zig/stemwords.zig +123 -0
  171. metadata +102 -4
  172. data/vendor/snowball/compiler/syswords.h +0 -86
  173. data/vendor/snowball/runtime/header.h +0 -62
@@ -0,0 +1,71 @@
1
+ struct token {
2
+ byte code; /* Token code (from enum token_code) */
3
+ byte s_size; /* Size of token */
4
+ const char s[14]; /* Token */
5
+ };
6
+
7
+ /* List of alphabetical tokens and their corresponding codes (symbol tokens are
8
+ * instead handled using `switch` in tokenise.c).
9
+ *
10
+ * Tokens below are ordered primarily by length, then by ASCII collating
11
+ * order amongst tokens of the same length.
12
+ */
13
+ static const struct token alpha_tokens[] = {
14
+ { c_as, 2, "as" },
15
+ { c_do, 2, "do" },
16
+ { c_or, 2, "or" },
17
+ { c_and, 3, "and" },
18
+ { c_for, 3, "for" },
19
+ { c_get, 3, "get" },
20
+ { c_hex, 3, "hex" },
21
+ { c_hop, 3, "hop" },
22
+ { c_len, 3, "len" },
23
+ { c_non, 3, "non" },
24
+ { c_not, 3, "not" },
25
+ { c_set, 3, "set" },
26
+ { c_try, 3, "try" },
27
+ { c_fail, 4, "fail" },
28
+ { c_goto, 4, "goto" },
29
+ { c_loop, 4, "loop" },
30
+ { c_next, 4, "next" },
31
+ { c_size, 4, "size" },
32
+ { c_test, 4, "test" },
33
+ { c_true, 4, "true" },
34
+ { c_among, 5, "among" },
35
+ { c_false, 5, "false" },
36
+ { c_lenof, 5, "lenof" },
37
+ { c_limit, 5, "limit" },
38
+ { c_unset, 5, "unset" },
39
+ { c_atmark, 6, "atmark" },
40
+ { c_attach, 6, "attach" },
41
+ { c_cursor, 6, "cursor" },
42
+ { c_define, 6, "define" },
43
+ { c_delete, 6, "delete" },
44
+ { c_gopast, 6, "gopast" },
45
+ { c_insert, 6, "insert" },
46
+ { c_maxint, 6, "maxint" },
47
+ { c_minint, 6, "minint" },
48
+ { c_repeat, 6, "repeat" },
49
+ { c_sizeof, 6, "sizeof" },
50
+ { c_tomark, 6, "tomark" },
51
+ { c_atleast, 7, "atleast" },
52
+ { c_atlimit, 7, "atlimit" },
53
+ { c_decimal, 7, "decimal" },
54
+ { c_reverse, 7, "reverse" },
55
+ { c_setmark, 7, "setmark" },
56
+ { c_strings, 7, "strings" },
57
+ { c_tolimit, 7, "tolimit" },
58
+ { c_booleans, 8, "booleans" },
59
+ { c_integers, 8, "integers" },
60
+ { c_routines, 8, "routines" },
61
+ { c_setlimit, 8, "setlimit" },
62
+ { c_backwards, 9, "backwards" },
63
+ { c_externals, 9, "externals" },
64
+ { c_groupings, 9, "groupings" },
65
+ { c_stringdef, 9, "stringdef" },
66
+ { c_substring, 9, "substring" },
67
+ { c_backwardmode, 12, "backwardmode" },
68
+ { c_stringescapes, 13, "stringescapes" }
69
+ };
70
+
71
+ #define NUM_ALPHA_TOKENS ((int)(sizeof(alpha_tokens) / sizeof(alpha_tokens[0])))
@@ -1,19 +1,20 @@
1
1
  // Copyright (c) 2001, Dr Martin Porter
2
2
  // Copyright (c) 2002, Richard Boulton
3
3
  // Copyright (c) 2015, Cesar Souza
4
+ // Copyright (c) 2025, Olly Betts
4
5
  // All rights reserved.
5
6
  //
6
7
  // Redistribution and use in source and binary forms, with or without
7
8
  // modification, are permitted provided that the following conditions are met:
8
9
  //
9
- // * Redistributions of source code must retain the above copyright notice,
10
- // * this list of conditions and the following disclaimer.
11
- // * Redistributions in binary form must reproduce the above copyright
12
- // * notice, this list of conditions and the following disclaimer in the
13
- // * documentation and/or other materials provided with the distribution.
14
- // * Neither the name of the copyright holders nor the names of its contributors
15
- // * may be used to endorse or promote products derived from this software
16
- // * without specific prior written permission.
10
+ // 1. Redistributions of source code must retain the above copyright notice,
11
+ // this list of conditions and the following disclaimer.
12
+ // 2. Redistributions in binary form must reproduce the above copyright
13
+ // notice, this list of conditions and the following disclaimer in the
14
+ // documentation and/or other materials provided with the distribution.
15
+ // 3. Neither the name of the Snowball project nor the names of its contributors
16
+ // may be used to endorse or promote products derived from this software
17
+ // without specific prior written permission.
17
18
  //
18
19
  // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
20
  // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@@ -56,10 +57,10 @@ namespace Snowball
56
57
  public int Result { get; private set; }
57
58
 
58
59
  /// <summary>
59
- /// Action to be invoked.
60
+ /// Condition function index (or 0 for no condition).
60
61
  /// </summary>
61
62
  ///
62
- public Func<bool> Action { get; private set; }
63
+ public int Condition { get; private set; }
63
64
 
64
65
  /// <summary>
65
66
  /// Initializes a new instance of the <see cref="Among"/> class.
@@ -68,27 +69,14 @@ namespace Snowball
68
69
  /// <param name="str">The search string.</param>
69
70
  /// <param name="index">The index to the longest matching substring.</param>
70
71
  /// <param name="result">The result of the lookup.</param>
72
+ /// <param name="condition">The index of the condition function (0 if none).</param>
71
73
  ///
72
- public Among(String str, int index, int result)
73
- : this(str, index, result, null)
74
- {
75
- }
76
-
77
- /// <summary>
78
- /// Initializes a new instance of the <see cref="Among"/> class.
79
- /// </summary>
80
- ///
81
- /// <param name="str">The search string.</param>
82
- /// <param name="index">The index to the longest matching substring.</param>
83
- /// <param name="result">The result of the lookup.</param>
84
- /// <param name="action">The action to be performed, if any.</param>
85
- ///
86
- public Among(String str, int index, int result, Func<bool> action)
74
+ public Among(String str, int index, int result, int condition)
87
75
  {
88
76
  this.SearchString = str;
89
77
  this.MatchIndex = index;
90
78
  this.Result = result;
91
- this.Action = action;
79
+ this.Condition = condition;
92
80
  }
93
81
 
94
82
  /// <summary>
@@ -10,7 +10,7 @@ using System.Runtime.InteropServices;
10
10
  [assembly: AssemblyConfiguration("")]
11
11
  [assembly: AssemblyCompany("")]
12
12
  [assembly: AssemblyProduct("Snowball")]
13
- [assembly: AssemblyCopyright("Copyright © 2015-2019")]
13
+ [assembly: AssemblyCopyright("Copyright © 2015-2025")]
14
14
  [assembly: AssemblyTrademark("")]
15
15
  [assembly: AssemblyCulture("")]
16
16
 
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
32
32
  // You can specify all the values or you can default the Build and Revision Numbers
33
33
  // by using the '*' as shown below:
34
34
  // [assembly: AssemblyVersion("1.0.*")]
35
- [assembly: AssemblyVersion(/*SNOWBALL_VERSION*/"3.0.1.0")]
36
- [assembly: AssemblyFileVersion(/*SNOWBALL_VERSION*/"3.0.1.0")]
35
+ [assembly: AssemblyVersion(/*SNOWBALL_VERSION*/"3.1.1.0")]
36
+ [assembly: AssemblyFileVersion(/*SNOWBALL_VERSION*/"3.1.1.0")]
@@ -1,20 +1,20 @@
1
1
  // Copyright (c) 2001, Dr Martin Porter
2
2
  // Copyright (c) 2002, Richard Boulton
3
3
  // Copyright (c) 2015, Cesar Souza
4
- // Copyright (c) 2018, Olly Betts
4
+ // Copyright (c) 2018-2026, Olly Betts
5
5
  // All rights reserved.
6
6
  //
7
7
  // Redistribution and use in source and binary forms, with or without
8
8
  // modification, are permitted provided that the following conditions are met:
9
9
  //
10
- // * Redistributions of source code must retain the above copyright notice,
11
- // * this list of conditions and the following disclaimer.
12
- // * Redistributions in binary form must reproduce the above copyright
13
- // * notice, this list of conditions and the following disclaimer in the
14
- // * documentation and/or other materials provided with the distribution.
15
- // * Neither the name of the copyright holders nor the names of its contributors
16
- // * may be used to endorse or promote products derived from this software
17
- // * without specific prior written permission.
10
+ // 1. Redistributions of source code must retain the above copyright notice,
11
+ // this list of conditions and the following disclaimer.
12
+ // 2. Redistributions in binary form must reproduce the above copyright
13
+ // notice, this list of conditions and the following disclaimer in the
14
+ // documentation and/or other materials provided with the distribution.
15
+ // 3. Neither the name of the Snowball project nor the names of its contributors
16
+ // may be used to endorse or promote products derived from this software
17
+ // without specific prior written permission.
18
18
  //
19
19
  // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
20
  // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@@ -30,6 +30,7 @@
30
30
  namespace Snowball
31
31
  {
32
32
  using System;
33
+ using System.Diagnostics;
33
34
  using System.Linq;
34
35
  using System.Text;
35
36
 
@@ -48,7 +49,7 @@ namespace Snowball
48
49
  }
49
50
 
50
51
  /// <summary>
51
- /// Gets the current string.
52
+ /// The current string.
52
53
  /// </summary>
53
54
  ///
54
55
  protected StringBuilder current;
@@ -72,13 +73,13 @@ namespace Snowball
72
73
  protected int limit_backward;
73
74
 
74
75
  /// <summary>
75
- /// Starting bracket position.
76
+ /// Start of the slice.
76
77
  /// </summary>
77
78
  ///
78
79
  protected int bra;
79
80
 
80
81
  /// <summary>
81
- /// Ending bracket position.
82
+ /// End of the slice.
82
83
  /// </summary>
83
84
  ///
84
85
  protected int ket;
@@ -114,6 +115,12 @@ namespace Snowball
114
115
  ///
115
116
  public abstract class Stemmer : Env
116
117
  {
118
+ /// <summary>
119
+ /// Among function being called.
120
+ /// </summary>
121
+ ///
122
+ protected int af;
123
+
117
124
  /// <summary>
118
125
  /// Initializes a new instance of the <see cref="Stemmer"/> class.
119
126
  /// </summary>
@@ -390,7 +397,7 @@ namespace Snowball
390
397
  /// forward.
391
398
  /// </summary>
392
399
  ///
393
- protected int find_among(Among[] v)
400
+ protected int find_among(Among[] v, Func<bool> call_among_func)
394
401
  {
395
402
  int i = 0;
396
403
  int j = v.Length;
@@ -465,14 +472,14 @@ namespace Snowball
465
472
  {
466
473
  cursor = c + w.SearchString.Length;
467
474
 
468
- if (w.Action == null)
475
+ if (w.Condition == 0)
469
476
  return w.Result;
470
477
 
471
- bool res = w.Action();
472
- cursor = c + w.SearchString.Length;
473
-
474
- if (res)
478
+ af = w.Condition;
479
+ if (call_among_func()) {
480
+ cursor = c + w.SearchString.Length;
475
481
  return w.Result;
482
+ }
476
483
  }
477
484
 
478
485
  i = w.MatchIndex;
@@ -488,7 +495,7 @@ namespace Snowball
488
495
  /// backwards.
489
496
  /// </summary>
490
497
  ///
491
- protected int find_among_b(Among[] v)
498
+ protected int find_among_b(Among[] v, Func<bool> call_among_func)
492
499
  {
493
500
  int i = 0;
494
501
  int j = v.Length;
@@ -558,14 +565,14 @@ namespace Snowball
558
565
  {
559
566
  cursor = c - w.SearchString.Length;
560
567
 
561
- if (w.Action == null)
568
+ if (w.Condition == 0)
562
569
  return w.Result;
563
570
 
564
- bool res = w.Action();
565
- cursor = c - w.SearchString.Length;
566
-
567
- if (res)
571
+ af = w.Condition;
572
+ if (call_among_func()) {
573
+ cursor = c - w.SearchString.Length;
568
574
  return w.Result;
575
+ }
569
576
  }
570
577
 
571
578
  i = w.MatchIndex;
@@ -597,25 +604,26 @@ namespace Snowball
597
604
  /// </summary>
598
605
  protected void slice_check()
599
606
  {
600
- if (bra < 0 || bra > ket || ket > limit || limit > current.Length)
601
- {
602
- System.Diagnostics.Trace.WriteLine("faulty slice operation");
603
- }
607
+ Debug.Assert(bra >= 0);
608
+ Debug.Assert(bra <= ket);
609
+ Debug.Assert(ket <= limit);
610
+ Debug.Assert(limit <= current.Length);
604
611
  }
605
612
 
606
613
  /// <summary>
607
- /// Replaces the contents of the bracket with the string s.
614
+ /// Replaces the contents of the slice with the string s.
608
615
  /// </summary>
609
616
  ///
610
- /// <param name="s">The s.</param>
617
+ /// <param name="s">The string.</param>
611
618
  protected void slice_from(String s)
612
619
  {
613
620
  slice_check();
614
621
  replace_s(bra, ket, s);
622
+ ket = bra + s.Length;
615
623
  }
616
624
 
617
625
  /// <summary>
618
- /// Removes the current bracket contents.
626
+ /// Removes the current slice contents.
619
627
  /// </summary>
620
628
  ///
621
629
  protected void slice_del()
@@ -635,18 +643,7 @@ namespace Snowball
635
643
  }
636
644
 
637
645
  /// <summary>
638
- /// Replaces the contents of the bracket with the string s.
639
- /// </summary>
640
- ///
641
- protected void insert(int c_bra, int c_ket, StringBuilder s)
642
- {
643
- int adjustment = replace_s(c_bra, c_ket, s.ToString());
644
- if (c_bra <= bra) bra += adjustment;
645
- if (c_bra <= ket) ket += adjustment;
646
- }
647
-
648
- /// <summary>
649
- /// Replaces the contents of the bracket with the string s.
646
+ /// Replaces the contents of s with the slice.
650
647
  /// </summary>
651
648
  ///
652
649
  protected void slice_to(StringBuilder s)
@@ -669,11 +666,10 @@ namespace Snowball
669
666
  /// <summary>
670
667
  /// Replaces a specific region of the buffer with another text.
671
668
  /// </summary>
672
- public static StringBuilder Replace(StringBuilder sb, int index, int length, string text)
669
+ public static void Replace(StringBuilder sb, int index, int length, string text)
673
670
  {
674
671
  sb.Remove(index, length - index);
675
672
  sb.Insert(index, text);
676
- return sb;
677
673
  }
678
674
 
679
675
  }
@@ -7,14 +7,14 @@
7
7
  // Redistribution and use in source and binary forms, with or without
8
8
  // modification, are permitted provided that the following conditions are met:
9
9
  //
10
- // * Redistributions of source code must retain the above copyright notice,
11
- // * this list of conditions and the following disclaimer.
12
- // * Redistributions in binary form must reproduce the above copyright
13
- // * notice, this list of conditions and the following disclaimer in the
14
- // * documentation and/or other materials provided with the distribution.
15
- // * Neither the name of the copyright holders nor the names of its contributors
16
- // * may be used to endorse or promote products derived from this software
17
- // * without specific prior written permission.
10
+ // 1. Redistributions of source code must retain the above copyright notice,
11
+ // this list of conditions and the following disclaimer.
12
+ // 2. Redistributions in binary form must reproduce the above copyright
13
+ // notice, this list of conditions and the following disclaimer in the
14
+ // documentation and/or other materials provided with the distribution.
15
+ // 3. Neither the name of the Snowball project nor the names of its contributors
16
+ // may be used to endorse or promote products derived from this software
17
+ // without specific prior written permission.
18
18
  //
19
19
  // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
20
  // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@@ -86,16 +86,22 @@ namespace Snowball
86
86
  return;
87
87
  }
88
88
 
89
- Console.WriteLine("Using " + stemmer.GetType());
90
-
91
- TextWriter output = System.Console.Out;
92
- if (outputName != null)
93
- output = new StreamWriter(outputName);
94
-
95
89
  TextReader input = System.Console.In;
96
90
  if (inputName != null)
97
91
  input = new StreamReader(inputName);
98
92
 
93
+ TextWriter output;
94
+ if (outputName != null) {
95
+ output = new StreamWriter(outputName);
96
+ } else {
97
+ // For some reason this is much faster than using
98
+ // System.Console.Out, at least with mono on Linux.
99
+ //
100
+ // `make check_sharp_tamil` takes 0.842s wallclock instead of
101
+ // 1.848s.
102
+ output = new StreamWriter(Console.OpenStandardOutput());
103
+ }
104
+
99
105
  while (true)
100
106
  {
101
107
  var line = input.ReadLine();
@@ -0,0 +1,4 @@
1
+ /stemwords
2
+ /stemmer.cxx
3
+ /*_stemmer.cxx
4
+ /*_stemmer.h
@@ -0,0 +1,87 @@
1
+ #!/usr/bin/env perl
2
+ use strict;
3
+ use 5.006;
4
+ use warnings;
5
+
6
+ my $progname = $0;
7
+
8
+ if (scalar @ARGV != 2) {
9
+ print "Usage: $progname <outfile> <modules description file>\n";
10
+ exit 1;
11
+ }
12
+
13
+ my $outname = shift(@ARGV);
14
+ my $modules = shift(@ARGV);
15
+
16
+ my @algorithms_by_length = ();
17
+
18
+ my %algorithm_name = ();
19
+
20
+ sub add_name {
21
+ my ($alias, $name) = @_;
22
+ $algorithm_name{$alias} = $name;
23
+ push @{$algorithms_by_length[length($alias)]}, $alias;
24
+ }
25
+
26
+ open my $out, '>', $outname or die "Can't open output file '$outname': $!\n";
27
+
28
+ print $out <<END;
29
+ #include "stemmer.h"
30
+ END
31
+
32
+ open my $in, '<', $modules or die $!;
33
+ while (<$in>) {
34
+ next if m/^\s*#/;
35
+ next if m/^\s*$/;
36
+ my ($alg, $encstr, $aliases) = split(/\s+/, $_);
37
+
38
+ print $out <<END;
39
+ #include "${alg}_stemmer.h"
40
+ END
41
+ foreach my $alias (split(/,/, $aliases)) {
42
+ add_name($alias, $alg);
43
+ }
44
+ }
45
+ close $in;
46
+
47
+ print $out <<END;
48
+ // $outname: Snowball stemmer factory
49
+ //
50
+ // This file is generated by $0 from a list of module names.
51
+ // Do not edit manually.
52
+
53
+ #include <string.h>
54
+
55
+ namespace Snowball {
56
+
57
+ Stemmer* make_stemmer(const char* language)
58
+ {
59
+ switch (strlen(language)) {
60
+ END
61
+
62
+ for (my $i = 1; $i < @algorithms_by_length; ++$i) {
63
+ my $l = $algorithms_by_length[$i];
64
+ next unless defined $l;
65
+ print $out <<END;
66
+ case $i:
67
+ END
68
+ for (@$l) {
69
+ my $class = $algorithm_name{$_};
70
+ $class =~ s/_(.)/\U$1/g;
71
+ $class = ucfirst $class . "Stemmer";
72
+ print $out <<END;
73
+ if (memcmp(language, "$_", $i) == 0) return new Snowball::$class();
74
+ END
75
+ }
76
+ print $out <<END;
77
+ break;
78
+ END
79
+ }
80
+
81
+ print $out <<END;
82
+ }
83
+ return NULL;
84
+ }
85
+
86
+ }
87
+ END
@@ -0,0 +1,12 @@
1
+ #include <string>
2
+
3
+ namespace Snowball {
4
+
5
+ class Stemmer {
6
+ public:
7
+ virtual std::string operator()(const std::string& word) = 0;
8
+ };
9
+
10
+ Stemmer* make_stemmer(const char* language);
11
+
12
+ }