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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/Gemfile +2 -1
- data/README.md +2 -2
- data/Rakefile +12 -5
- data/ext/mittens/extconf.rb +3 -1
- data/lib/mittens/version.rb +1 -1
- data/vendor/snowball/.github/workflows/ci.yml +144 -17
- data/vendor/snowball/.github/workflows/coverage.yml +117 -0
- data/vendor/snowball/.github/workflows/runtime-tests.yml +26 -0
- data/vendor/snowball/.gitignore +33 -7
- data/vendor/snowball/CONTRIBUTING.rst +7 -0
- data/vendor/snowball/COPYING +1 -1
- data/vendor/snowball/GNUmakefile +736 -298
- data/vendor/snowball/NEWS +1394 -7
- data/vendor/snowball/README.rst +8 -8
- data/vendor/snowball/ada/generate/generate.adb +5 -5
- data/vendor/snowball/ada/src/stemmer.adb +177 -188
- data/vendor/snowball/ada/src/stemmer.ads +86 -89
- data/vendor/snowball/ada/src/stemwords.adb +21 -5
- data/vendor/snowball/algorithms/czech.sbl +255 -0
- data/vendor/snowball/algorithms/danish.sbl +22 -10
- data/vendor/snowball/algorithms/english.sbl +7 -4
- data/vendor/snowball/algorithms/esperanto.sbl +6 -7
- data/vendor/snowball/algorithms/estonian.sbl +9 -4
- data/vendor/snowball/algorithms/finnish.sbl +33 -21
- data/vendor/snowball/algorithms/german.sbl +5 -0
- data/vendor/snowball/algorithms/indonesian.sbl +115 -96
- data/vendor/snowball/algorithms/italian.sbl +26 -1
- data/vendor/snowball/algorithms/lithuanian.sbl +13 -13
- data/vendor/snowball/algorithms/norwegian.sbl +17 -6
- data/vendor/snowball/algorithms/persian.sbl +387 -0
- data/vendor/snowball/algorithms/polish.sbl +177 -0
- data/vendor/snowball/algorithms/sesotho.sbl +115 -0
- data/vendor/snowball/algorithms/turkish.sbl +4 -4
- data/vendor/snowball/compiler/analyser.c +2002 -711
- data/vendor/snowball/compiler/driver.c +460 -298
- data/vendor/snowball/compiler/generator.c +439 -1965
- data/vendor/snowball/compiler/generator_ada.c +605 -430
- data/vendor/snowball/compiler/generator_c.c +2227 -0
- data/vendor/snowball/compiler/generator_csharp.c +365 -274
- data/vendor/snowball/compiler/generator_dart.c +1476 -0
- data/vendor/snowball/compiler/generator_go.c +348 -270
- data/vendor/snowball/compiler/generator_java.c +330 -233
- data/vendor/snowball/compiler/generator_js.c +534 -385
- data/vendor/snowball/compiler/generator_pascal.c +361 -320
- data/vendor/snowball/compiler/generator_php.c +1445 -0
- data/vendor/snowball/compiler/generator_python.c +399 -299
- data/vendor/snowball/compiler/generator_rust.c +370 -261
- data/vendor/snowball/compiler/generator_zig.c +1474 -0
- data/vendor/snowball/compiler/header.h +153 -86
- data/vendor/snowball/compiler/space.c +121 -63
- data/vendor/snowball/compiler/tokeniser.c +286 -182
- data/vendor/snowball/compiler/tokens.h +71 -0
- data/vendor/snowball/csharp/Snowball/Among.cs +14 -26
- data/vendor/snowball/csharp/Snowball/AssemblyInfo.cs +3 -3
- data/vendor/snowball/csharp/Snowball/Stemmer.cs +41 -45
- data/vendor/snowball/csharp/Stemwords/Program.cs +20 -14
- data/vendor/snowball/cxx/.gitignore +4 -0
- data/vendor/snowball/cxx/generate_algorithms.pl +87 -0
- data/vendor/snowball/cxx/stemmer.h +12 -0
- data/vendor/snowball/cxx/stemwords.cxx +176 -0
- data/vendor/snowball/cxx/utilities.cxx +2 -0
- data/vendor/snowball/dart/.gitignore +4 -0
- data/vendor/snowball/dart/analysis_options.yaml +1 -0
- data/vendor/snowball/dart/example/test_app.dart +65 -0
- data/vendor/snowball/dart/generate_algorithms.pl +21 -0
- data/vendor/snowball/dart/lib/snowball.dart +18 -0
- data/vendor/snowball/dart/lib/src/snowball.dart +339 -0
- data/vendor/snowball/dart/pubspec.yaml +17 -0
- data/vendor/snowball/doc/libstemmer_dart_README +37 -0
- data/vendor/snowball/doc/libstemmer_js_README +2 -2
- data/vendor/snowball/doc/libstemmer_php_README +38 -0
- data/vendor/snowball/doc/libstemmer_python_README +3 -3
- data/vendor/snowball/examples/stemwords.c +18 -3
- data/vendor/snowball/go/README.md +12 -4
- data/vendor/snowball/go/env.go +12 -14
- data/vendor/snowball/go/stemwords/main.go +2 -1
- data/vendor/snowball/java/org/tartarus/snowball/CharArraySequence.java +36 -0
- data/vendor/snowball/java/org/tartarus/snowball/SnowballProgram.java +17 -34
- data/vendor/snowball/java/org/tartarus/snowball/SnowballStemmer.java +0 -2
- data/vendor/snowball/javascript/base-stemmer.js +219 -252
- data/vendor/snowball/javascript/stemwords.js +86 -58
- data/vendor/snowball/libstemmer/mkmodules.pl +1 -1
- data/vendor/snowball/libstemmer/modules.txt +4 -0
- data/vendor/snowball/pascal/SnowballProgram.pas +18 -31
- data/vendor/snowball/php/base-stemmer.php +453 -0
- data/vendor/snowball/php/stemwords.php +25 -0
- data/vendor/snowball/python/create_init.py +16 -21
- data/vendor/snowball/python/pyproject.toml +3 -0
- data/vendor/snowball/python/setup.py +5 -7
- data/vendor/snowball/python/snowballstemmer/among.py +1 -2
- data/vendor/snowball/python/snowballstemmer/basestemmer.py +24 -33
- data/vendor/snowball/python/stemwords.py +72 -63
- data/vendor/snowball/runtime/api.c +11 -42
- data/vendor/snowball/runtime/api.h +11 -9
- data/vendor/snowball/runtime/snowball_runtime.h +110 -0
- data/vendor/snowball/runtime/utilities.c +282 -106
- data/vendor/snowball/rust/src/main.rs +2 -2
- data/vendor/snowball/rust/src/snowball/snowball_env.rs +7 -9
- data/vendor/snowball/tests/compilertest +62 -0
- data/vendor/snowball/tests/errors/ae-errors.sbl +53 -0
- data/vendor/snowball/tests/errors/ae-errors.stderr +8 -0
- data/vendor/snowball/tests/errors/bad-dollar.sbl +14 -0
- data/vendor/snowball/tests/errors/bad-dollar.stderr +4 -0
- data/vendor/snowball/tests/errors/bad-grouping-definition.sbl +9 -0
- data/vendor/snowball/tests/errors/bad-grouping-definition.stderr +6 -0
- data/vendor/snowball/tests/errors/missing-bra.sbl +6 -0
- data/vendor/snowball/tests/errors/missing-bra.stderr +3 -0
- data/vendor/snowball/tests/errors/missing-command.sbl +9 -0
- data/vendor/snowball/tests/errors/missing-command.stderr +1 -0
- data/vendor/snowball/tests/errors/missing-ket-backwardmode.sbl +3 -0
- data/vendor/snowball/tests/errors/missing-ket-backwardmode.stderr +1 -0
- data/vendor/snowball/tests/errors/missing-ket.sbl +7 -0
- data/vendor/snowball/tests/errors/missing-ket.stderr +6 -0
- data/vendor/snowball/tests/errors/notdefined.sbl +4 -0
- data/vendor/snowball/tests/errors/notdefined.stderr +2 -0
- data/vendor/snowball/tests/errors/string-omitted.sbl +5 -0
- data/vendor/snowball/tests/errors/string-omitted.stderr +1 -0
- data/vendor/snowball/tests/errors/undeclared.sbl +20 -0
- data/vendor/snowball/tests/errors/undeclared.stderr +9 -0
- data/vendor/snowball/tests/errors/unexpected-token.sbl +24 -0
- data/vendor/snowball/tests/errors/unexpected-token.stderr +17 -0
- data/vendor/snowball/tests/errors/wrongdirection.sbl +14 -0
- data/vendor/snowball/tests/errors/wrongdirection.stderr +1 -0
- data/vendor/snowball/tests/runtime/among.sbl +19 -0
- data/vendor/snowball/tests/runtime/arithmeticexpr.sbl +86 -0
- data/vendor/snowball/tests/runtime/attachinsert.sbl +47 -0
- data/vendor/snowball/tests/runtime/booleans.sbl +19 -0
- data/vendor/snowball/tests/runtime/externals.sbl +22 -0
- data/vendor/snowball/tests/runtime/hop.sbl +12 -0
- data/vendor/snowball/tests/runtime/integertests.sbl +60 -0
- data/vendor/snowball/tests/runtime/intlimits.sbl +25 -0
- data/vendor/snowball/tests/runtime/naming.sbl +20 -0
- data/vendor/snowball/tests/runtime/not.sbl +30 -0
- data/vendor/snowball/tests/runtime/or.sbl +17 -0
- data/vendor/snowball/tests/runtime/repeat.sbl +16 -0
- data/vendor/snowball/tests/runtime/setlimit.sbl +24 -0
- data/vendor/snowball/tests/runtime/sizelen.sbl +56 -0
- data/vendor/snowball/tests/runtime/slice.sbl +27 -0
- data/vendor/snowball/tests/runtime/stringdollar.sbl +39 -0
- data/vendor/snowball/tests/runtime/strings.sbl +66 -0
- data/vendor/snowball/tests/runtime/test.sbl +19 -0
- data/vendor/snowball/tests/stemtest.c +41 -1
- data/vendor/snowball/tests/syntax/canon.sbl +32 -0
- data/vendor/snowball/tests/syntax/canon.stderr +0 -0
- data/vendor/snowball/tests/syntax/canon.syntax +57 -0
- data/vendor/snowball/tests/syntax/emptyprogram.sbl +2 -0
- data/vendor/snowball/tests/syntax/emptyprogram.syntax +0 -0
- data/vendor/snowball/tests/syntax/groupings.sbl +11 -0
- data/vendor/snowball/tests/syntax/inline.sbl +144 -0
- data/vendor/snowball/tests/syntax/inline.stderr +0 -0
- data/vendor/snowball/tests/syntax/inline.syntax +121 -0
- data/vendor/snowball/tests/syntax/legacy.sbl +17 -0
- data/vendor/snowball/tests/syntax/legacy.stderr +5 -0
- data/vendor/snowball/tests/syntax/legacy.syntax +19 -0
- data/vendor/snowball/tests/syntax/loops.sbl +14 -0
- data/vendor/snowball/tests/syntax/loops.stderr +9 -0
- data/vendor/snowball/tests/syntax/loops.syntax +29 -0
- data/vendor/snowball/tests/syntax/noops.sbl +76 -0
- data/vendor/snowball/tests/syntax/noops.stderr +27 -0
- data/vendor/snowball/tests/syntax/noops.syntax +135 -0
- data/vendor/snowball/tests/syntax/simplifyae.sbl +21 -0
- data/vendor/snowball/tests/syntax/simplifyae.stderr +0 -0
- data/vendor/snowball/tests/syntax/simplifyae.syntax +39 -0
- data/vendor/snowball/tests/syntax/unused.sbl +18 -0
- data/vendor/snowball/tests/syntax/unused.stderr +7 -0
- data/vendor/snowball/tests/syntax/unused.syntax +3 -0
- data/vendor/snowball/zig/env.zig +599 -0
- data/vendor/snowball/zig/generate_algorithms.pl +19 -0
- data/vendor/snowball/zig/stemwords.zig +123 -0
- metadata +102 -4
- data/vendor/snowball/compiler/syswords.h +0 -86
- data/vendor/snowball/runtime/header.h +0 -62
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
Snowball stemming library for PHP
|
|
2
|
+
=================================
|
|
3
|
+
|
|
4
|
+
This is an automatically-generated pure PHP implementation of the Snowball
|
|
5
|
+
stemming algorithms.
|
|
6
|
+
|
|
7
|
+
The generated code is compatible with PHP 8.3 and later. The `mbstring`
|
|
8
|
+
extension is required.
|
|
9
|
+
|
|
10
|
+
It would be possible to extend support to older PHP (back to 7.4) if there's
|
|
11
|
+
demand for it. Please contact us if this would be useful to you.
|
|
12
|
+
|
|
13
|
+
This library is intended for situations where the convenience of a pure PHP
|
|
14
|
+
implementation is more important than performance. If performance
|
|
15
|
+
matters we recommend using the C implementation via bindings instead,
|
|
16
|
+
(for example, using https://github.com/amaccis/php-stemmer).
|
|
17
|
+
|
|
18
|
+
If you want both the convenience of pure PHP and reasonable performance, we
|
|
19
|
+
suggest avoiding PHP 8.3 as we've noticed the generated stemmers seem to run
|
|
20
|
+
4-5 times faster with PHP >= 8.4 than with 8.3 (this performance gain seems
|
|
21
|
+
much higher than we've seen reported for other PHP code, presumably due to
|
|
22
|
+
something atypical the generated stemmer code does).
|
|
23
|
+
|
|
24
|
+
How to use library
|
|
25
|
+
------------------
|
|
26
|
+
|
|
27
|
+
You can stem a word from PHP as follows:
|
|
28
|
+
|
|
29
|
+
.. code-block:: php
|
|
30
|
+
|
|
31
|
+
require 'base-stemmer.php';
|
|
32
|
+
require 'english-stemmer.php';
|
|
33
|
+
$stemmer = new SnowballEnglishStemmer;
|
|
34
|
+
$word = 'compiled';
|
|
35
|
+
$stem = $stemmer->stemWord($word);
|
|
36
|
+
printf("%s => %s\n", $word, $stem );
|
|
37
|
+
|
|
38
|
+
// prints "compiled => compil"
|
|
@@ -3,7 +3,7 @@ Snowball stemming library collection for Python
|
|
|
3
3
|
|
|
4
4
|
Python 3 (>= 3.3) is supported. We no longer support Python 2 as the Python
|
|
5
5
|
developers stopped supporting it at the start of 2020. Snowball 2.1.0 was the
|
|
6
|
-
last release to officially support Python 2; Snowball 3.0.
|
|
6
|
+
last release to officially support Python 2; Snowball 3.0.1 was the last
|
|
7
7
|
release which had the code to support Python 2, but we were no longer testing
|
|
8
8
|
it.
|
|
9
9
|
|
|
@@ -45,8 +45,8 @@ The ``snowballstemmer.stemmer`` function takes an algorithm name and returns a
|
|
|
45
45
|
|
|
46
46
|
import snowballstemmer
|
|
47
47
|
|
|
48
|
-
stemmer = snowballstemmer.stemmer('english')
|
|
49
|
-
print(stemmer.stemWords("We are the world".split()))
|
|
48
|
+
stemmer = snowballstemmer.stemmer('english')
|
|
49
|
+
print(stemmer.stemWords("We are the world".split()))
|
|
50
50
|
|
|
51
51
|
Generally you should create a stemmer object and reuse it rather than creating
|
|
52
52
|
a fresh object for each word stemmed (since there's some cost to creating and
|
|
@@ -7,6 +7,11 @@
|
|
|
7
7
|
#include <string.h> /* for memmove */
|
|
8
8
|
#include <ctype.h> /* for isupper, tolower */
|
|
9
9
|
|
|
10
|
+
#ifdef __cplusplus
|
|
11
|
+
// Support compiling as C++ to test code generated by `snowball -c++`.
|
|
12
|
+
# include <exception>
|
|
13
|
+
#endif
|
|
14
|
+
|
|
10
15
|
#include "libstemmer.h"
|
|
11
16
|
|
|
12
17
|
const char * progname;
|
|
@@ -97,7 +102,9 @@ usage(int n)
|
|
|
97
102
|
"\n"
|
|
98
103
|
"If -c is given, the argument is the character encoding of the input\n"
|
|
99
104
|
"and output files. If it is omitted, the UTF-8 encoding is used.\n"
|
|
100
|
-
"\n"
|
|
105
|
+
"\n",
|
|
106
|
+
progname);
|
|
107
|
+
printf(
|
|
101
108
|
"If -p is given the output file consists of each word of the input\n"
|
|
102
109
|
"file followed by \"->\" followed by its stemmed equivalent.\n"
|
|
103
110
|
"If -p2 is given the output file is a two column layout containing\n"
|
|
@@ -106,13 +113,15 @@ usage(int n)
|
|
|
106
113
|
"Otherwise, the output file consists of the stemmed words, one per\n"
|
|
107
114
|
"line.\n"
|
|
108
115
|
"\n"
|
|
109
|
-
"-h displays this help\n"
|
|
110
|
-
progname);
|
|
116
|
+
"-h displays this help\n");
|
|
111
117
|
exit(n);
|
|
112
118
|
}
|
|
113
119
|
|
|
114
120
|
int
|
|
115
121
|
main(int argc, char * argv[])
|
|
122
|
+
#ifdef __cplusplus
|
|
123
|
+
try
|
|
124
|
+
#endif
|
|
116
125
|
{
|
|
117
126
|
const char * in = NULL;
|
|
118
127
|
const char * out = NULL;
|
|
@@ -202,3 +211,9 @@ main(int argc, char * argv[])
|
|
|
202
211
|
|
|
203
212
|
return 0;
|
|
204
213
|
}
|
|
214
|
+
#ifdef __cplusplus
|
|
215
|
+
catch (const std::exception& e) {
|
|
216
|
+
fprintf(stderr, "Exception: %s\n", e.what());
|
|
217
|
+
exit(1);
|
|
218
|
+
}
|
|
219
|
+
#endif
|
|
@@ -11,9 +11,12 @@ $ snowball path/to/algorithm.sbl -go -o algorithm
|
|
|
11
11
|
|
|
12
12
|
### Go specific options
|
|
13
13
|
|
|
14
|
-
`-
|
|
14
|
+
`-Package`/`-P`: the package name used in the generated go file (defaults to `snowball`)
|
|
15
15
|
|
|
16
|
-
`-gor
|
|
16
|
+
`-goruntime`/`-gor`: the import path used for the Go Snowball runtime (defaults to `github.com/snowballstem/snowball/go`)
|
|
17
|
+
|
|
18
|
+
Snowball 3.0.1 and earlier supported `-go`/`-gopackage`, but this was just an
|
|
19
|
+
alias for `-Package`/`-P` since Snowball 2.0.0.
|
|
17
20
|
|
|
18
21
|
## Code Organization
|
|
19
22
|
|
|
@@ -30,12 +33,17 @@ $ snowball path/to/algorithm.sbl -go -o algorithm
|
|
|
30
33
|
Assuming you generated a stemmer, put that code in a package which is imported by this code as `english`.
|
|
31
34
|
|
|
32
35
|
```
|
|
33
|
-
env := snowball.NewEnv("
|
|
36
|
+
env := snowball.NewEnv("")
|
|
37
|
+
env.SetCurrent("beautiful")
|
|
34
38
|
english.Stem(env)
|
|
35
39
|
fmt.Printf("stemmed word is: %s", env.Current())
|
|
36
40
|
```
|
|
37
41
|
|
|
38
|
-
|
|
42
|
+
If you are stemming many words you should reuse `env` as shown above. If you
|
|
43
|
+
are stemming a single word, you can set the current string when you create it
|
|
44
|
+
with `env:= snowball.NewEnv("beautiful")`, but doing this when stemming many
|
|
45
|
+
words is not recommended as the overhead is measurable (stemwords for the arabic
|
|
46
|
+
stemmer on the sample vocabulary is about 12% faster if you reuse `env`).
|
|
39
47
|
|
|
40
48
|
## Testing
|
|
41
49
|
|
data/vendor/snowball/go/env.go
CHANGED
|
@@ -92,10 +92,10 @@ func (env *Env) EqSB(s string) bool {
|
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
func (env *Env) SliceFrom(s string)
|
|
95
|
+
func (env *Env) SliceFrom(s string) {
|
|
96
96
|
bra, ket := env.Bra, env.Ket
|
|
97
97
|
env.ReplaceS(bra, ket, s)
|
|
98
|
-
|
|
98
|
+
env.Ket = bra + len(s)
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
func (env *Env) NextChar() {
|
|
@@ -112,7 +112,7 @@ func (env *Env) PrevChar() {
|
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
-
func (env *Env) Hop(delta
|
|
115
|
+
func (env *Env) Hop(delta int) bool {
|
|
116
116
|
res := env.Cursor
|
|
117
117
|
for delta > 0 {
|
|
118
118
|
delta--
|
|
@@ -128,11 +128,11 @@ func (env *Env) Hop(delta int32) bool {
|
|
|
128
128
|
return true
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
-
func (env *Env) HopChecked(delta
|
|
131
|
+
func (env *Env) HopChecked(delta int) bool {
|
|
132
132
|
return delta >= 0 && env.Hop(delta)
|
|
133
133
|
}
|
|
134
134
|
|
|
135
|
-
func (env *Env) HopBack(delta
|
|
135
|
+
func (env *Env) HopBack(delta int) bool {
|
|
136
136
|
res := env.Cursor
|
|
137
137
|
for delta > 0 {
|
|
138
138
|
delta--
|
|
@@ -148,7 +148,7 @@ func (env *Env) HopBack(delta int32) bool {
|
|
|
148
148
|
return true
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
-
func (env *Env) HopBackChecked(delta
|
|
151
|
+
func (env *Env) HopBackChecked(delta int) bool {
|
|
152
152
|
return delta >= 0 && env.HopBack(delta)
|
|
153
153
|
}
|
|
154
154
|
|
|
@@ -310,8 +310,8 @@ func (env *Env) GoOutGroupingB(chars []byte, min, max int32) bool {
|
|
|
310
310
|
return false
|
|
311
311
|
}
|
|
312
312
|
|
|
313
|
-
func (env *Env) SliceDel()
|
|
314
|
-
|
|
313
|
+
func (env *Env) SliceDel() {
|
|
314
|
+
env.SliceFrom("")
|
|
315
315
|
}
|
|
316
316
|
|
|
317
317
|
func (env *Env) Insert(bra, ket int, s string) {
|
|
@@ -380,9 +380,8 @@ func (env *Env) FindAmong(amongs []*Among, ctx interface{}) int32 {
|
|
|
380
380
|
if commonI >= len(w.Str) {
|
|
381
381
|
env.Cursor = c + len(w.Str)
|
|
382
382
|
if w.F != nil {
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
if res {
|
|
383
|
+
if w.F(env, ctx) {
|
|
384
|
+
env.Cursor = c + len(w.Str)
|
|
386
385
|
return w.B
|
|
387
386
|
}
|
|
388
387
|
} else {
|
|
@@ -449,9 +448,8 @@ func (env *Env) FindAmongB(amongs []*Among, ctx interface{}) int32 {
|
|
|
449
448
|
if commonI >= len(w.Str) {
|
|
450
449
|
env.Cursor = c - len(w.Str)
|
|
451
450
|
if w.F != nil {
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
if res {
|
|
451
|
+
if w.F(env, ctx) {
|
|
452
|
+
env.Cursor = c - len(w.Str)
|
|
455
453
|
return w.B
|
|
456
454
|
}
|
|
457
455
|
} else {
|
|
@@ -51,9 +51,10 @@ func main() {
|
|
|
51
51
|
|
|
52
52
|
var err error
|
|
53
53
|
scanner := bufio.NewScanner(reader)
|
|
54
|
+
env := snowballRuntime.NewEnv("")
|
|
54
55
|
for scanner.Scan() {
|
|
55
56
|
word := scanner.Text()
|
|
56
|
-
env
|
|
57
|
+
env.SetCurrent(word)
|
|
57
58
|
stemmer(env)
|
|
58
59
|
fmt.Fprintf(writer, "%s\n", env.Current())
|
|
59
60
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
package org.tartarus.snowball;
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Internal class used by Snowball stemmers
|
|
5
|
+
*/
|
|
6
|
+
public class CharArraySequence implements CharSequence {
|
|
7
|
+
public CharArraySequence(char[] a, int len) {
|
|
8
|
+
this.a = a;
|
|
9
|
+
this.len = len;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
final public char charAt(int index) {
|
|
13
|
+
if (index < 0 || index >= len) {
|
|
14
|
+
throw new StringIndexOutOfBoundsException(index);
|
|
15
|
+
}
|
|
16
|
+
return a[index];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
final public int length() {
|
|
20
|
+
return len;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
final public CharSequence subSequence(int start, int end) {
|
|
24
|
+
// Not needed for how we used CharSequence.
|
|
25
|
+
throw new UnsupportedOperationException();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
final public String toString() {
|
|
29
|
+
if (a == null) return "";
|
|
30
|
+
return new String(a, 0, len);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
final private char[] a;
|
|
34
|
+
|
|
35
|
+
final private int len;
|
|
36
|
+
}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
|
|
2
2
|
package org.tartarus.snowball;
|
|
3
3
|
import java.lang.reflect.UndeclaredThrowableException;
|
|
4
|
-
import java.io.Serializable;
|
|
5
4
|
import java.util.Arrays;
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
7
|
* Base class for a snowball stemmer
|
|
9
8
|
*/
|
|
10
|
-
public class SnowballProgram
|
|
9
|
+
public class SnowballProgram {
|
|
11
10
|
protected SnowballProgram()
|
|
12
11
|
{
|
|
13
12
|
cursor = 0;
|
|
@@ -17,8 +16,6 @@ public class SnowballProgram implements Serializable {
|
|
|
17
16
|
ket = limit;
|
|
18
17
|
}
|
|
19
18
|
|
|
20
|
-
static final long serialVersionUID = 2016072500L;
|
|
21
|
-
|
|
22
19
|
/**
|
|
23
20
|
* Set the current string.
|
|
24
21
|
*/
|
|
@@ -77,7 +74,7 @@ public class SnowballProgram implements Serializable {
|
|
|
77
74
|
}
|
|
78
75
|
|
|
79
76
|
// current string
|
|
80
|
-
|
|
77
|
+
protected char[] current;
|
|
81
78
|
|
|
82
79
|
protected int cursor;
|
|
83
80
|
protected int length;
|
|
@@ -290,16 +287,16 @@ public class SnowballProgram implements Serializable {
|
|
|
290
287
|
if (common_i >= w.s.length) {
|
|
291
288
|
cursor = c + w.s.length;
|
|
292
289
|
if (w.method == null) return w.result;
|
|
293
|
-
boolean res = false;
|
|
294
290
|
try {
|
|
295
|
-
|
|
291
|
+
if ((boolean) w.method.invokeExact(this)) {
|
|
292
|
+
cursor = c + w.s.length;
|
|
293
|
+
return w.result;
|
|
294
|
+
}
|
|
296
295
|
} catch (Error | RuntimeException e) {
|
|
297
296
|
throw e;
|
|
298
297
|
} catch (Throwable e) {
|
|
299
298
|
throw new UndeclaredThrowableException(e);
|
|
300
299
|
}
|
|
301
|
-
cursor = c + w.s.length;
|
|
302
|
-
if (res) return w.result;
|
|
303
300
|
}
|
|
304
301
|
i = w.substring_i;
|
|
305
302
|
if (i < 0) return 0;
|
|
@@ -354,17 +351,16 @@ public class SnowballProgram implements Serializable {
|
|
|
354
351
|
if (common_i >= w.s.length) {
|
|
355
352
|
cursor = c - w.s.length;
|
|
356
353
|
if (w.method == null) return w.result;
|
|
357
|
-
|
|
358
|
-
boolean res = false;
|
|
359
354
|
try {
|
|
360
|
-
|
|
355
|
+
if ((boolean) w.method.invokeExact(this)) {
|
|
356
|
+
cursor = c - w.s.length;
|
|
357
|
+
return w.result;
|
|
358
|
+
}
|
|
361
359
|
} catch (Error | RuntimeException e) {
|
|
362
360
|
throw e;
|
|
363
361
|
} catch (Throwable e) {
|
|
364
362
|
throw new UndeclaredThrowableException(e);
|
|
365
363
|
}
|
|
366
|
-
cursor = c - w.s.length;
|
|
367
|
-
if (res) return w.result;
|
|
368
364
|
}
|
|
369
365
|
i = w.substring_i;
|
|
370
366
|
if (i < 0) return 0;
|
|
@@ -413,6 +409,7 @@ public class SnowballProgram implements Serializable {
|
|
|
413
409
|
{
|
|
414
410
|
slice_check();
|
|
415
411
|
replace_s(bra, ket, s);
|
|
412
|
+
ket = bra + s.length();
|
|
416
413
|
}
|
|
417
414
|
|
|
418
415
|
protected void slice_del()
|
|
@@ -427,35 +424,21 @@ public class SnowballProgram implements Serializable {
|
|
|
427
424
|
if (c_bra <= ket) ket += adjustment;
|
|
428
425
|
}
|
|
429
426
|
|
|
430
|
-
/* Copy the slice into the supplied StringBuilder */
|
|
431
|
-
protected void slice_to(StringBuilder s)
|
|
432
|
-
{
|
|
433
|
-
slice_check();
|
|
434
|
-
int len = ket - bra;
|
|
435
|
-
s.setLength(0);
|
|
436
|
-
s.append(current, bra, len);
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
protected void assign_to(StringBuilder s)
|
|
440
|
-
{
|
|
441
|
-
s.setLength(0);
|
|
442
|
-
s.append(current, 0, limit);
|
|
443
|
-
}
|
|
444
|
-
|
|
445
427
|
/*
|
|
446
428
|
extern void debug(struct SN_env * z, int number, int line_count)
|
|
447
|
-
{
|
|
429
|
+
{
|
|
430
|
+
int i;
|
|
448
431
|
int limit = SIZE(z->p);
|
|
449
432
|
//if (number >= 0) printf("%3d (line %4d): '", number, line_count);
|
|
450
433
|
if (number >= 0) printf("%3d (line %4d): [%d]'", number, line_count,limit);
|
|
451
|
-
for (i = 0; i <= limit; i++)
|
|
452
|
-
|
|
434
|
+
for (i = 0; i <= limit; i++) {
|
|
435
|
+
if (z->lb == i) printf("{");
|
|
453
436
|
if (z->bra == i) printf("[");
|
|
454
437
|
if (z->c == i) printf("|");
|
|
455
438
|
if (z->ket == i) printf("]");
|
|
456
439
|
if (z->l == i) printf("}");
|
|
457
|
-
if (i < limit)
|
|
458
|
-
|
|
440
|
+
if (i < limit) {
|
|
441
|
+
int ch = z->p[i];
|
|
459
442
|
if (ch == 0) ch = '#';
|
|
460
443
|
printf("%c", ch);
|
|
461
444
|
}
|