whatlang 0.1.6 → 0.1.8
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/.gitignore +2 -5
- data/.gitlab-ci.yml +6 -6
- data/CHANGELOG.md +12 -0
- data/Gemfile +2 -0
- data/README.md +1 -1
- data/Rakefile +9 -11
- data/ext/whatlang-rb/Cargo.lock +360 -0
- data/ext/whatlang-rb/Cargo.toml +12 -0
- data/ext/whatlang-rb/src/lib.rs +122 -0
- data/lib/whatlang.rb +1 -57
- data/test/test_package.rb +38 -0
- data/test/test_whatlang.rb +1 -0
- data/whatlang.gemspec +3 -6
- metadata +8 -39
- data/Cargo.lock +0 -144
- data/Cargo.toml +0 -14
- data/ext/Rakefile +0 -23
- data/src/lib.rs +0 -95
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 69c49c403761528be76daea679fbf38b5c7fbf2f508a819d9bef3e5b6bf14b48
|
|
4
|
+
data.tar.gz: 748275ab31ce880de74a32c92ebd680f3b05af4303cf29e3985cfb774076d0e9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8c7acef11c2721c3ea347f4c64d199114c22ebd3258cef88acbb8cd81633d9ec1a0843f8fa3543c667b1c416ffa22631a71fe0e0ddbb5b7803a7bc0d581f729d
|
|
7
|
+
data.tar.gz: 381ad3386f4bae91ed497e1a49f5bf60df9346457f775f0fe7f6df335cb05d2b5ca5123a30f4e2fcae518c81d2a0e9da12aa1c69841b3a192b3349909d96e618
|
data/.gitignore
CHANGED
data/.gitlab-ci.yml
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
default:
|
|
2
|
-
image: ruby:3.
|
|
2
|
+
image: ruby:3.4.7
|
|
3
3
|
|
|
4
4
|
before_script:
|
|
5
5
|
- apt-get update && apt-get install -y clang
|
|
6
|
-
- gem update --system '3.4.22'
|
|
7
|
-
- gem install bundler -v 2.4.22
|
|
8
|
-
- gem install tomlrb
|
|
9
|
-
- bundle install
|
|
10
6
|
- curl https://sh.rustup.rs -sSf | sh -s -- -y
|
|
7
|
+
- . "$HOME/.cargo/env"
|
|
8
|
+
- gem update --system
|
|
9
|
+
- gem install bundler
|
|
10
|
+
- bundle install
|
|
11
11
|
|
|
12
12
|
test:
|
|
13
13
|
variables:
|
|
14
14
|
RB_SYS_FORCE_INSTALL_RUST_TOOLCHAIN: 'true'
|
|
15
15
|
script:
|
|
16
|
-
- source "$HOME/.cargo/env" &&
|
|
16
|
+
- source "$HOME/.cargo/env" && rake test
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
0.1.8
|
|
2
|
+
=====
|
|
3
|
+
|
|
4
|
+
* Switch Rust glue library from [Rutie][] to [Magnus][]
|
|
5
|
+
|
|
6
|
+
0.1.7
|
|
7
|
+
=====
|
|
8
|
+
|
|
9
|
+
* Stick Rust version to 1.77.2. See https://github.com/danielpclark/rutie/issues/185 for details
|
|
10
|
+
|
|
1
11
|
0.1.6
|
|
2
12
|
=====
|
|
3
13
|
|
|
@@ -36,3 +46,5 @@
|
|
|
36
46
|
* Initial release
|
|
37
47
|
|
|
38
48
|
[@bendangelo]: https://gitlab.com/bendangelo
|
|
49
|
+
[Rutie]: https://github.com/danielpclark/rutie
|
|
50
|
+
[Magnus]: https://docs.rs/magnus/latest/magnus/
|
data/Gemfile
CHANGED
data/README.md
CHANGED
|
@@ -8,7 +8,7 @@ Features
|
|
|
8
8
|
|
|
9
9
|
Features are derived from original [Whatlang][] library, which includes:
|
|
10
10
|
|
|
11
|
-
* Supports [
|
|
11
|
+
* Supports [70 languages](https://github.com/greyblake/whatlang-rs/blob/master/SUPPORTED_LANGUAGES.md)
|
|
12
12
|
* Lightweight, fast and simple
|
|
13
13
|
* Recognizes not only a language, but also a script (Latin, Cyrillic, etc)
|
|
14
14
|
* Provides reliability information
|
data/Rakefile
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "rake/clean"
|
|
4
|
+
require "rubygems/ext"
|
|
4
5
|
require "rubygems/tasks"
|
|
5
6
|
require "rake/testtask"
|
|
6
7
|
require "yard"
|
|
@@ -10,16 +11,13 @@ task default: :test
|
|
|
10
11
|
Gem::Tasks.new
|
|
11
12
|
YARD::Rake::YardocTask.new
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
file path
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
file RUST_TARGET => RUST_SRC + ["Cargo.toml", "Cargo.lock"] do
|
|
21
|
-
sh "cargo build --release"
|
|
14
|
+
EXTENSION = "lib/whatlang-rb/whatlang_rb.#{RbConfig::CONFIG["DLEXT"]}"
|
|
15
|
+
file EXTENSION do
|
|
16
|
+
results = Rake.verbose == true ? $stdout : []
|
|
17
|
+
Gem::Ext::CargoBuilder.new.build "ext/whatlang-rb/Cargo.toml", ".", results, [], "lib", File.expand_path("ext/whatlang-rb")
|
|
22
18
|
end
|
|
23
|
-
CLEAN.include
|
|
19
|
+
CLEAN.include "whatlang-rb"
|
|
20
|
+
CLOBBER.include EXTENSION
|
|
24
21
|
|
|
25
|
-
Rake::TestTask.new
|
|
22
|
+
Rake::TestTask.new
|
|
23
|
+
task test: EXTENSION
|
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
# This file is automatically @generated by Cargo.
|
|
2
|
+
# It is not intended for manual editing.
|
|
3
|
+
version = 4
|
|
4
|
+
|
|
5
|
+
[[package]]
|
|
6
|
+
name = "ahash"
|
|
7
|
+
version = "0.8.12"
|
|
8
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
9
|
+
checksum = "5a15f179cd60c4584b8a8c596927aadc462e27f2ca70c04e0071964a73ba7a75"
|
|
10
|
+
dependencies = [
|
|
11
|
+
"cfg-if",
|
|
12
|
+
"once_cell",
|
|
13
|
+
"version_check",
|
|
14
|
+
"zerocopy",
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
[[package]]
|
|
18
|
+
name = "aho-corasick"
|
|
19
|
+
version = "1.1.3"
|
|
20
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
21
|
+
checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916"
|
|
22
|
+
dependencies = [
|
|
23
|
+
"memchr",
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
[[package]]
|
|
27
|
+
name = "allocator-api2"
|
|
28
|
+
version = "0.2.21"
|
|
29
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
30
|
+
checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923"
|
|
31
|
+
|
|
32
|
+
[[package]]
|
|
33
|
+
name = "bindgen"
|
|
34
|
+
version = "0.69.5"
|
|
35
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
36
|
+
checksum = "271383c67ccabffb7381723dea0672a673f292304fcb45c01cc648c7a8d58088"
|
|
37
|
+
dependencies = [
|
|
38
|
+
"bitflags",
|
|
39
|
+
"cexpr",
|
|
40
|
+
"clang-sys",
|
|
41
|
+
"itertools",
|
|
42
|
+
"lazy_static",
|
|
43
|
+
"lazycell",
|
|
44
|
+
"proc-macro2",
|
|
45
|
+
"quote",
|
|
46
|
+
"regex",
|
|
47
|
+
"rustc-hash",
|
|
48
|
+
"shlex",
|
|
49
|
+
"syn",
|
|
50
|
+
]
|
|
51
|
+
|
|
52
|
+
[[package]]
|
|
53
|
+
name = "bitflags"
|
|
54
|
+
version = "2.10.0"
|
|
55
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
56
|
+
checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3"
|
|
57
|
+
|
|
58
|
+
[[package]]
|
|
59
|
+
name = "cexpr"
|
|
60
|
+
version = "0.6.0"
|
|
61
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
62
|
+
checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766"
|
|
63
|
+
dependencies = [
|
|
64
|
+
"nom",
|
|
65
|
+
]
|
|
66
|
+
|
|
67
|
+
[[package]]
|
|
68
|
+
name = "cfg-if"
|
|
69
|
+
version = "1.0.4"
|
|
70
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
71
|
+
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
|
|
72
|
+
|
|
73
|
+
[[package]]
|
|
74
|
+
name = "clang-sys"
|
|
75
|
+
version = "1.8.1"
|
|
76
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
77
|
+
checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4"
|
|
78
|
+
dependencies = [
|
|
79
|
+
"glob",
|
|
80
|
+
"libc",
|
|
81
|
+
"libloading",
|
|
82
|
+
]
|
|
83
|
+
|
|
84
|
+
[[package]]
|
|
85
|
+
name = "either"
|
|
86
|
+
version = "1.15.0"
|
|
87
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
88
|
+
checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719"
|
|
89
|
+
|
|
90
|
+
[[package]]
|
|
91
|
+
name = "glob"
|
|
92
|
+
version = "0.3.3"
|
|
93
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
94
|
+
checksum = "0cc23270f6e1808e30a928bdc84dea0b9b4136a8bc82338574f23baf47bbd280"
|
|
95
|
+
|
|
96
|
+
[[package]]
|
|
97
|
+
name = "hashbrown"
|
|
98
|
+
version = "0.14.5"
|
|
99
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
100
|
+
checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
|
|
101
|
+
dependencies = [
|
|
102
|
+
"ahash",
|
|
103
|
+
"allocator-api2",
|
|
104
|
+
]
|
|
105
|
+
|
|
106
|
+
[[package]]
|
|
107
|
+
name = "itertools"
|
|
108
|
+
version = "0.12.1"
|
|
109
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
110
|
+
checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569"
|
|
111
|
+
dependencies = [
|
|
112
|
+
"either",
|
|
113
|
+
]
|
|
114
|
+
|
|
115
|
+
[[package]]
|
|
116
|
+
name = "lazy_static"
|
|
117
|
+
version = "1.5.0"
|
|
118
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
119
|
+
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
|
|
120
|
+
|
|
121
|
+
[[package]]
|
|
122
|
+
name = "lazycell"
|
|
123
|
+
version = "1.3.0"
|
|
124
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
125
|
+
checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
|
|
126
|
+
|
|
127
|
+
[[package]]
|
|
128
|
+
name = "libc"
|
|
129
|
+
version = "0.2.177"
|
|
130
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
131
|
+
checksum = "2874a2af47a2325c2001a6e6fad9b16a53b802102b528163885171cf92b15976"
|
|
132
|
+
|
|
133
|
+
[[package]]
|
|
134
|
+
name = "libloading"
|
|
135
|
+
version = "0.8.9"
|
|
136
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
137
|
+
checksum = "d7c4b02199fee7c5d21a5ae7d8cfa79a6ef5bb2fc834d6e9058e89c825efdc55"
|
|
138
|
+
dependencies = [
|
|
139
|
+
"cfg-if",
|
|
140
|
+
"windows-link",
|
|
141
|
+
]
|
|
142
|
+
|
|
143
|
+
[[package]]
|
|
144
|
+
name = "magnus"
|
|
145
|
+
version = "0.8.2"
|
|
146
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
147
|
+
checksum = "3b36a5b126bbe97eb0d02d07acfeb327036c6319fd816139a49824a83b7f9012"
|
|
148
|
+
dependencies = [
|
|
149
|
+
"magnus-macros",
|
|
150
|
+
"rb-sys",
|
|
151
|
+
"rb-sys-env",
|
|
152
|
+
"seq-macro",
|
|
153
|
+
]
|
|
154
|
+
|
|
155
|
+
[[package]]
|
|
156
|
+
name = "magnus-macros"
|
|
157
|
+
version = "0.8.0"
|
|
158
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
159
|
+
checksum = "47607461fd8e1513cb4f2076c197d8092d921a1ea75bd08af97398f593751892"
|
|
160
|
+
dependencies = [
|
|
161
|
+
"proc-macro2",
|
|
162
|
+
"quote",
|
|
163
|
+
"syn",
|
|
164
|
+
]
|
|
165
|
+
|
|
166
|
+
[[package]]
|
|
167
|
+
name = "memchr"
|
|
168
|
+
version = "2.7.6"
|
|
169
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
170
|
+
checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273"
|
|
171
|
+
|
|
172
|
+
[[package]]
|
|
173
|
+
name = "minimal-lexical"
|
|
174
|
+
version = "0.2.1"
|
|
175
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
176
|
+
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
|
|
177
|
+
|
|
178
|
+
[[package]]
|
|
179
|
+
name = "nom"
|
|
180
|
+
version = "7.1.3"
|
|
181
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
182
|
+
checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
|
|
183
|
+
dependencies = [
|
|
184
|
+
"memchr",
|
|
185
|
+
"minimal-lexical",
|
|
186
|
+
]
|
|
187
|
+
|
|
188
|
+
[[package]]
|
|
189
|
+
name = "once_cell"
|
|
190
|
+
version = "1.21.3"
|
|
191
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
192
|
+
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
|
|
193
|
+
|
|
194
|
+
[[package]]
|
|
195
|
+
name = "proc-macro2"
|
|
196
|
+
version = "1.0.101"
|
|
197
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
198
|
+
checksum = "89ae43fd86e4158d6db51ad8e2b80f313af9cc74f5c0e03ccb87de09998732de"
|
|
199
|
+
dependencies = [
|
|
200
|
+
"unicode-ident",
|
|
201
|
+
]
|
|
202
|
+
|
|
203
|
+
[[package]]
|
|
204
|
+
name = "quote"
|
|
205
|
+
version = "1.0.41"
|
|
206
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
207
|
+
checksum = "ce25767e7b499d1b604768e7cde645d14cc8584231ea6b295e9c9eb22c02e1d1"
|
|
208
|
+
dependencies = [
|
|
209
|
+
"proc-macro2",
|
|
210
|
+
]
|
|
211
|
+
|
|
212
|
+
[[package]]
|
|
213
|
+
name = "rb-sys"
|
|
214
|
+
version = "0.9.117"
|
|
215
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
216
|
+
checksum = "f900d1ce4629a2ebffaf5de74bd8f9c1188d4c5ed406df02f97e22f77a006f44"
|
|
217
|
+
dependencies = [
|
|
218
|
+
"rb-sys-build",
|
|
219
|
+
]
|
|
220
|
+
|
|
221
|
+
[[package]]
|
|
222
|
+
name = "rb-sys-build"
|
|
223
|
+
version = "0.9.117"
|
|
224
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
225
|
+
checksum = "ef1e9c857028f631056bcd6d88cec390c751e343ce2223ddb26d23eb4a151d59"
|
|
226
|
+
dependencies = [
|
|
227
|
+
"bindgen",
|
|
228
|
+
"lazy_static",
|
|
229
|
+
"proc-macro2",
|
|
230
|
+
"quote",
|
|
231
|
+
"regex",
|
|
232
|
+
"shell-words",
|
|
233
|
+
"syn",
|
|
234
|
+
]
|
|
235
|
+
|
|
236
|
+
[[package]]
|
|
237
|
+
name = "rb-sys-env"
|
|
238
|
+
version = "0.2.2"
|
|
239
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
240
|
+
checksum = "08f8d2924cf136a1315e2b4c7460a39f62ef11ee5d522df9b2750fab55b868b6"
|
|
241
|
+
|
|
242
|
+
[[package]]
|
|
243
|
+
name = "regex"
|
|
244
|
+
version = "1.12.2"
|
|
245
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
246
|
+
checksum = "843bc0191f75f3e22651ae5f1e72939ab2f72a4bc30fa80a066bd66edefc24d4"
|
|
247
|
+
dependencies = [
|
|
248
|
+
"aho-corasick",
|
|
249
|
+
"memchr",
|
|
250
|
+
"regex-automata",
|
|
251
|
+
"regex-syntax",
|
|
252
|
+
]
|
|
253
|
+
|
|
254
|
+
[[package]]
|
|
255
|
+
name = "regex-automata"
|
|
256
|
+
version = "0.4.13"
|
|
257
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
258
|
+
checksum = "5276caf25ac86c8d810222b3dbb938e512c55c6831a10f3e6ed1c93b84041f1c"
|
|
259
|
+
dependencies = [
|
|
260
|
+
"aho-corasick",
|
|
261
|
+
"memchr",
|
|
262
|
+
"regex-syntax",
|
|
263
|
+
]
|
|
264
|
+
|
|
265
|
+
[[package]]
|
|
266
|
+
name = "regex-syntax"
|
|
267
|
+
version = "0.8.8"
|
|
268
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
269
|
+
checksum = "7a2d987857b319362043e95f5353c0535c1f58eec5336fdfcf626430af7def58"
|
|
270
|
+
|
|
271
|
+
[[package]]
|
|
272
|
+
name = "rustc-hash"
|
|
273
|
+
version = "1.1.0"
|
|
274
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
275
|
+
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
|
|
276
|
+
|
|
277
|
+
[[package]]
|
|
278
|
+
name = "seq-macro"
|
|
279
|
+
version = "0.3.6"
|
|
280
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
281
|
+
checksum = "1bc711410fbe7399f390ca1c3b60ad0f53f80e95c5eb935e52268a0e2cd49acc"
|
|
282
|
+
|
|
283
|
+
[[package]]
|
|
284
|
+
name = "shell-words"
|
|
285
|
+
version = "1.1.0"
|
|
286
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
287
|
+
checksum = "24188a676b6ae68c3b2cb3a01be17fbf7240ce009799bb56d5b1409051e78fde"
|
|
288
|
+
|
|
289
|
+
[[package]]
|
|
290
|
+
name = "shlex"
|
|
291
|
+
version = "1.3.0"
|
|
292
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
293
|
+
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
|
|
294
|
+
|
|
295
|
+
[[package]]
|
|
296
|
+
name = "syn"
|
|
297
|
+
version = "2.0.107"
|
|
298
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
299
|
+
checksum = "2a26dbd934e5451d21ef060c018dae56fc073894c5a7896f882928a76e6d081b"
|
|
300
|
+
dependencies = [
|
|
301
|
+
"proc-macro2",
|
|
302
|
+
"quote",
|
|
303
|
+
"unicode-ident",
|
|
304
|
+
]
|
|
305
|
+
|
|
306
|
+
[[package]]
|
|
307
|
+
name = "unicode-ident"
|
|
308
|
+
version = "1.0.20"
|
|
309
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
310
|
+
checksum = "462eeb75aeb73aea900253ce739c8e18a67423fadf006037cd3ff27e82748a06"
|
|
311
|
+
|
|
312
|
+
[[package]]
|
|
313
|
+
name = "version_check"
|
|
314
|
+
version = "0.9.5"
|
|
315
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
316
|
+
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
|
|
317
|
+
|
|
318
|
+
[[package]]
|
|
319
|
+
name = "whatlang"
|
|
320
|
+
version = "0.16.4"
|
|
321
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
322
|
+
checksum = "471d1c1645d361eb782a1650b1786a8fb58dd625e681a04c09f5ff7c8764a7b0"
|
|
323
|
+
dependencies = [
|
|
324
|
+
"hashbrown",
|
|
325
|
+
"once_cell",
|
|
326
|
+
]
|
|
327
|
+
|
|
328
|
+
[[package]]
|
|
329
|
+
name = "whatlang-rb"
|
|
330
|
+
version = "0.1.7"
|
|
331
|
+
dependencies = [
|
|
332
|
+
"magnus",
|
|
333
|
+
"whatlang",
|
|
334
|
+
]
|
|
335
|
+
|
|
336
|
+
[[package]]
|
|
337
|
+
name = "windows-link"
|
|
338
|
+
version = "0.2.1"
|
|
339
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
340
|
+
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
|
|
341
|
+
|
|
342
|
+
[[package]]
|
|
343
|
+
name = "zerocopy"
|
|
344
|
+
version = "0.8.27"
|
|
345
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
346
|
+
checksum = "0894878a5fa3edfd6da3f88c4805f4c8558e2b996227a3d864f47fe11e38282c"
|
|
347
|
+
dependencies = [
|
|
348
|
+
"zerocopy-derive",
|
|
349
|
+
]
|
|
350
|
+
|
|
351
|
+
[[package]]
|
|
352
|
+
name = "zerocopy-derive"
|
|
353
|
+
version = "0.8.27"
|
|
354
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
355
|
+
checksum = "88d2b8d9c68ad2b9e4340d7832716a4d21a22a1154777ad56ea55c51a9cf3831"
|
|
356
|
+
dependencies = [
|
|
357
|
+
"proc-macro2",
|
|
358
|
+
"quote",
|
|
359
|
+
"syn",
|
|
360
|
+
]
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
use magnus::{
|
|
2
|
+
Error, Ruby, Value, function, method,
|
|
3
|
+
prelude::*,
|
|
4
|
+
scan_args::{get_kwargs, scan_args},
|
|
5
|
+
};
|
|
6
|
+
use whatlang as wl;
|
|
7
|
+
|
|
8
|
+
#[magnus::wrap(class = "Whatlang::Lang")]
|
|
9
|
+
struct Lang(wl::Lang);
|
|
10
|
+
|
|
11
|
+
impl Lang {
|
|
12
|
+
fn code(&self) -> &str {
|
|
13
|
+
self.0.code()
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
fn name(&self) -> &str {
|
|
17
|
+
self.0.name()
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
fn eng_name(&self) -> &str {
|
|
21
|
+
self.0.eng_name()
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
#[magnus::wrap(class = "Whatlang::Info")]
|
|
26
|
+
struct Info(wl::Info);
|
|
27
|
+
|
|
28
|
+
impl Info {
|
|
29
|
+
fn lang(&self) -> Lang {
|
|
30
|
+
Lang(self.0.lang())
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
fn script(&self) -> String {
|
|
34
|
+
self.0.script().to_string()
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
fn confidence(&self) -> f64 {
|
|
38
|
+
self.0.confidence()
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
fn is_reliable(&self) -> bool {
|
|
42
|
+
self.0.is_reliable()
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
fn detect(ruby: &Ruby, args: &[Value]) -> Result<Option<Info>, Error> {
|
|
47
|
+
type LangList = Option<Vec<String>>;
|
|
48
|
+
|
|
49
|
+
let args = scan_args::<(Value,), (), (), (), _, ()>(args)?;
|
|
50
|
+
let kw_args = get_kwargs::<_, (), (LangList, LangList), ()>(
|
|
51
|
+
args.keywords,
|
|
52
|
+
&[],
|
|
53
|
+
&["allowlist", "denylist"],
|
|
54
|
+
)?;
|
|
55
|
+
let (allowlist, denylist) = kw_args.optional;
|
|
56
|
+
if allowlist.is_some() && denylist.is_some() {
|
|
57
|
+
return Err(Error::new(
|
|
58
|
+
ruby.exception_arg_error(),
|
|
59
|
+
"Couldn't specify `allowlist' and `denylist' at a time. Choose one.",
|
|
60
|
+
));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
let text = args.required.0.to_r_string()?.to_string()?;
|
|
64
|
+
Ok(if let Some(allowlist) = allowlist {
|
|
65
|
+
detect_with_allowlist(text, allowlist)
|
|
66
|
+
} else if let Some(denylist) = denylist {
|
|
67
|
+
detect_with_denylist(text, denylist)
|
|
68
|
+
} else {
|
|
69
|
+
detect_without_options(text)
|
|
70
|
+
})
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
fn detect_without_options(text: String) -> Option<Info> {
|
|
74
|
+
wl::detect(&text).map(Info)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
fn detect_with_allowlist(text: String, allowlist: Vec<String>) -> Option<Info> {
|
|
78
|
+
wl::Detector::with_allowlist(allowlist.iter().filter_map(wl::Lang::from_code).collect())
|
|
79
|
+
.detect(&text)
|
|
80
|
+
.map(Info)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
fn detect_with_denylist(text: String, denylist: Vec<String>) -> Option<Info> {
|
|
84
|
+
wl::Detector::with_denylist(denylist.iter().filter_map(wl::Lang::from_code).collect())
|
|
85
|
+
.detect(&text)
|
|
86
|
+
.map(Info)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
fn detect_lang(text: String) -> Option<Lang> {
|
|
90
|
+
wl::detect_lang(&text).map(Lang)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
fn detect_script(text: String) -> Option<String> {
|
|
94
|
+
wl::detect_script(&text).map(|script| script.to_string())
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
#[magnus::init]
|
|
98
|
+
fn init(ruby: &Ruby) -> Result<(), Error> {
|
|
99
|
+
let module = ruby.define_module("Whatlang")?;
|
|
100
|
+
module.define_singleton_method(
|
|
101
|
+
"detect_without_options",
|
|
102
|
+
function!(detect_without_options, 1),
|
|
103
|
+
)?;
|
|
104
|
+
module.define_singleton_method("detect", function!(detect, -1))?;
|
|
105
|
+
module.define_singleton_method("detect_with_allowlist", function!(detect_with_allowlist, 2))?;
|
|
106
|
+
module.define_singleton_method("detect_with_denylist", function!(detect_with_denylist, 2))?;
|
|
107
|
+
module.define_singleton_method("detect_lang", function!(detect_lang, 1))?;
|
|
108
|
+
module.define_singleton_method("detect_script", function!(detect_script, 1))?;
|
|
109
|
+
|
|
110
|
+
let lang = module.define_class("Lang", ruby.class_object())?;
|
|
111
|
+
lang.define_method("code", method!(Lang::code, 0))?;
|
|
112
|
+
lang.define_method("name", method!(Lang::name, 0))?;
|
|
113
|
+
lang.define_method("eng_name", method!(Lang::eng_name, 0))?;
|
|
114
|
+
|
|
115
|
+
let info = module.define_class("Info", ruby.class_object())?;
|
|
116
|
+
info.define_method("lang", method!(Info::lang, 0))?;
|
|
117
|
+
info.define_method("script", method!(Info::script, 0))?;
|
|
118
|
+
info.define_method("confidence", method!(Info::confidence, 0))?;
|
|
119
|
+
info.define_method("reliable?", method!(Info::is_reliable, 0))?;
|
|
120
|
+
|
|
121
|
+
Ok(())
|
|
122
|
+
}
|
data/lib/whatlang.rb
CHANGED
|
@@ -1,57 +1 @@
|
|
|
1
|
-
require "
|
|
2
|
-
|
|
3
|
-
Rutie.new(:whatlang_rb).init "Init_whatlang", __dir__
|
|
4
|
-
|
|
5
|
-
module Whatlang
|
|
6
|
-
class << self
|
|
7
|
-
def detect(text, allowlist: nil, denylist: nil)
|
|
8
|
-
if denylist && allowlist
|
|
9
|
-
raise ArgumentError, "Couldn't specify `allowlist' and `denylist' at a time. Choose one."
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
text = text.to_s
|
|
13
|
-
|
|
14
|
-
case
|
|
15
|
-
when allowlist
|
|
16
|
-
detect_with_allowlist(text, allowlist)
|
|
17
|
-
when denylist
|
|
18
|
-
detect_with_denylist(text, denylist)
|
|
19
|
-
else
|
|
20
|
-
detect_without_options(text)
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
class Info
|
|
26
|
-
attr_reader :lang, :script, :confidence
|
|
27
|
-
|
|
28
|
-
def initialize(lang, script, is_reliable, confidence)
|
|
29
|
-
@lang = lang
|
|
30
|
-
@script = script
|
|
31
|
-
@is_reliable = is_reliable
|
|
32
|
-
@confidence = confidence
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def reliable?
|
|
36
|
-
@is_reliable
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
class Lang
|
|
41
|
-
attr_reader :code, :name, :eng_name
|
|
42
|
-
|
|
43
|
-
def initialize(code, name, eng_name)
|
|
44
|
-
@code = code
|
|
45
|
-
@name = name
|
|
46
|
-
@eng_name = eng_name
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
private
|
|
51
|
-
|
|
52
|
-
# Class returnned by detect when no lang detected.
|
|
53
|
-
#
|
|
54
|
-
# Needed because Rutie cause segmentation fault when it returns NilClass.
|
|
55
|
-
# Should be removed after https://github.com/danielpclark/rutie/pull/180 is solved.
|
|
56
|
-
NO_INFO = nil
|
|
57
|
-
end
|
|
1
|
+
require "whatlang-rb/whatlang_rb"
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
require "test/unit"
|
|
2
|
+
require 'tempfile'
|
|
3
|
+
require 'tmpdir'
|
|
4
|
+
require 'shellwords'
|
|
5
|
+
|
|
6
|
+
class TestPackage < Test::Unit::TestCase
|
|
7
|
+
def test_build
|
|
8
|
+
Tempfile.create do |file|
|
|
9
|
+
assert system("gem", "build", "whatlang.gemspec", "--output", file.to_path.shellescape, exception: true)
|
|
10
|
+
assert file.size > 0
|
|
11
|
+
assert_path_exist file.to_path
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
class TestInstall < self
|
|
16
|
+
def setup
|
|
17
|
+
system "rake", "build", exception: true
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def test_install
|
|
21
|
+
gemspec = Gem::Specification.load("whatlang.gemspec")
|
|
22
|
+
Dir.mktmpdir do |dir|
|
|
23
|
+
dir = File.realpath(dir)
|
|
24
|
+
system "gem", "install", "--install-dir", dir.shellescape, "--no-document", "pkg/#{gemspec.file_name.shellescape}", exception: true
|
|
25
|
+
assert_installed dir, gemspec.version
|
|
26
|
+
|
|
27
|
+
libdir = File.join(dir, "gems", "#{gemspec.name}-#{gemspec.version}", "lib")
|
|
28
|
+
assert_match(/ita/, `ruby -I #{libdir.shellescape} -r whatlang -e 'print Whatlang.detect("Jen la trinkejo fermitis, ni iras tra mallumo kaj pluvo.", allowlist: ["eng", "ita"]).lang.code'`)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
private
|
|
33
|
+
|
|
34
|
+
def assert_installed(dir, version)
|
|
35
|
+
assert_path_exist File.join(dir, "gems/whatlang-#{version}/lib/whatlang-rb", "whatlang_rb.#{RbConfig::CONFIG["DLEXT"]}")
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
data/test/test_whatlang.rb
CHANGED
|
@@ -26,6 +26,7 @@ class TestWhatlang < Test::Unit::TestCase
|
|
|
26
26
|
text = "Jen la trinkejo fermitis, ni iras tra mallumo kaj pluvo."
|
|
27
27
|
list = ["eng", "ita"]
|
|
28
28
|
assert_equal "ita", Whatlang.detect_with_allowlist(text, list).lang.code
|
|
29
|
+
assert_equal "ita", Whatlang.detect_with_allowlist(text, list + ["unknown"]).lang.code
|
|
29
30
|
end
|
|
30
31
|
|
|
31
32
|
def test_detect_with_denylist
|
data/whatlang.gemspec
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
require "
|
|
1
|
+
require "json"
|
|
2
2
|
|
|
3
3
|
Gem::Specification.new do |spec|
|
|
4
4
|
spec.name = "whatlang"
|
|
5
|
-
spec.version =
|
|
5
|
+
spec.version = JSON.parse(`cargo metadata --no-deps --format-version=1 --manifest-path=ext/whatlang-rb/Cargo.toml`)["packages"][0]["version"]
|
|
6
6
|
spec.license = "Ruby"
|
|
7
7
|
spec.authors = ["Kitaiti Makoto"]
|
|
8
8
|
spec.email = ["KitaitiMakoto@gmail.com"]
|
|
@@ -18,11 +18,8 @@ Gem::Specification.new do |spec|
|
|
|
18
18
|
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
|
19
19
|
`git ls-files -z`.split("\x0")
|
|
20
20
|
end
|
|
21
|
-
spec.extensions = ["ext/
|
|
21
|
+
spec.extensions = ["ext/whatlang-rb/Cargo.toml"]
|
|
22
22
|
|
|
23
|
-
spec.add_runtime_dependency "rutie"
|
|
24
|
-
|
|
25
|
-
spec.add_development_dependency "tomlrb"
|
|
26
23
|
spec.add_development_dependency "test-unit"
|
|
27
24
|
spec.add_development_dependency "rake"
|
|
28
25
|
spec.add_development_dependency "yard"
|
metadata
CHANGED
|
@@ -1,43 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: whatlang
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.8
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Kitaiti Makoto
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
|
-
- !ruby/object:Gem::Dependency
|
|
14
|
-
name: rutie
|
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
|
16
|
-
requirements:
|
|
17
|
-
- - ">="
|
|
18
|
-
- !ruby/object:Gem::Version
|
|
19
|
-
version: '0'
|
|
20
|
-
type: :runtime
|
|
21
|
-
prerelease: false
|
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
-
requirements:
|
|
24
|
-
- - ">="
|
|
25
|
-
- !ruby/object:Gem::Version
|
|
26
|
-
version: '0'
|
|
27
|
-
- !ruby/object:Gem::Dependency
|
|
28
|
-
name: tomlrb
|
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
|
30
|
-
requirements:
|
|
31
|
-
- - ">="
|
|
32
|
-
- !ruby/object:Gem::Version
|
|
33
|
-
version: '0'
|
|
34
|
-
type: :development
|
|
35
|
-
prerelease: false
|
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
-
requirements:
|
|
38
|
-
- - ">="
|
|
39
|
-
- !ruby/object:Gem::Version
|
|
40
|
-
version: '0'
|
|
41
12
|
- !ruby/object:Gem::Dependency
|
|
42
13
|
name: test-unit
|
|
43
14
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -99,7 +70,7 @@ email:
|
|
|
99
70
|
- KitaitiMakoto@gmail.com
|
|
100
71
|
executables: []
|
|
101
72
|
extensions:
|
|
102
|
-
- ext/
|
|
73
|
+
- ext/whatlang-rb/Cargo.toml
|
|
103
74
|
extra_rdoc_files: []
|
|
104
75
|
files:
|
|
105
76
|
- ".gitignore"
|
|
@@ -108,15 +79,15 @@ files:
|
|
|
108
79
|
- BSDL
|
|
109
80
|
- CHANGELOG.md
|
|
110
81
|
- COPYING
|
|
111
|
-
- Cargo.lock
|
|
112
|
-
- Cargo.toml
|
|
113
82
|
- Gemfile
|
|
114
83
|
- README.md
|
|
115
84
|
- Rakefile
|
|
116
|
-
- ext/
|
|
85
|
+
- ext/whatlang-rb/Cargo.lock
|
|
86
|
+
- ext/whatlang-rb/Cargo.toml
|
|
87
|
+
- ext/whatlang-rb/src/lib.rs
|
|
117
88
|
- lib/whatlang.rb
|
|
118
|
-
- src/lib.rs
|
|
119
89
|
- test/helper.rb
|
|
90
|
+
- test/test_package.rb
|
|
120
91
|
- test/test_whatlang.rb
|
|
121
92
|
- whatlang.gemspec
|
|
122
93
|
homepage: https://gitlab.com/KitaitiMakoto/whatlang-rb
|
|
@@ -126,7 +97,6 @@ metadata:
|
|
|
126
97
|
homepage_uri: https://gitlab.com/KitaitiMakoto/whatlang-rb
|
|
127
98
|
source_code_uri: https://gitlab.com/KitaitiMakoto/whatlang-rb
|
|
128
99
|
changelog_uri: https://gitlab.com/KitaitiMakoto/whatlang-rb/-/blob/master/CHANGELOG.md
|
|
129
|
-
post_install_message:
|
|
130
100
|
rdoc_options: []
|
|
131
101
|
require_paths:
|
|
132
102
|
- lib
|
|
@@ -141,8 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
141
111
|
- !ruby/object:Gem::Version
|
|
142
112
|
version: '0'
|
|
143
113
|
requirements: []
|
|
144
|
-
rubygems_version: 3.
|
|
145
|
-
signing_key:
|
|
114
|
+
rubygems_version: 3.7.2
|
|
146
115
|
specification_version: 4
|
|
147
116
|
summary: Fast natural language detection library.
|
|
148
117
|
test_files: []
|
data/Cargo.lock
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
# This file is automatically @generated by Cargo.
|
|
2
|
-
# It is not intended for manual editing.
|
|
3
|
-
version = 3
|
|
4
|
-
|
|
5
|
-
[[package]]
|
|
6
|
-
name = "ahash"
|
|
7
|
-
version = "0.8.7"
|
|
8
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
9
|
-
checksum = "77c3a9648d43b9cd48db467b3f87fdd6e146bcc88ab0180006cef2179fe11d01"
|
|
10
|
-
dependencies = [
|
|
11
|
-
"cfg-if",
|
|
12
|
-
"once_cell",
|
|
13
|
-
"version_check",
|
|
14
|
-
"zerocopy",
|
|
15
|
-
]
|
|
16
|
-
|
|
17
|
-
[[package]]
|
|
18
|
-
name = "allocator-api2"
|
|
19
|
-
version = "0.2.16"
|
|
20
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
21
|
-
checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5"
|
|
22
|
-
|
|
23
|
-
[[package]]
|
|
24
|
-
name = "cfg-if"
|
|
25
|
-
version = "1.0.0"
|
|
26
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
27
|
-
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
|
28
|
-
|
|
29
|
-
[[package]]
|
|
30
|
-
name = "hashbrown"
|
|
31
|
-
version = "0.14.3"
|
|
32
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
33
|
-
checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604"
|
|
34
|
-
dependencies = [
|
|
35
|
-
"ahash",
|
|
36
|
-
"allocator-api2",
|
|
37
|
-
]
|
|
38
|
-
|
|
39
|
-
[[package]]
|
|
40
|
-
name = "lazy_static"
|
|
41
|
-
version = "1.4.0"
|
|
42
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
43
|
-
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
|
44
|
-
|
|
45
|
-
[[package]]
|
|
46
|
-
name = "libc"
|
|
47
|
-
version = "0.2.152"
|
|
48
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
49
|
-
checksum = "13e3bf6590cbc649f4d1a3eefc9d5d6eb746f5200ffb04e5e142700b8faa56e7"
|
|
50
|
-
|
|
51
|
-
[[package]]
|
|
52
|
-
name = "once_cell"
|
|
53
|
-
version = "1.19.0"
|
|
54
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
55
|
-
checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
|
|
56
|
-
|
|
57
|
-
[[package]]
|
|
58
|
-
name = "proc-macro2"
|
|
59
|
-
version = "1.0.76"
|
|
60
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
61
|
-
checksum = "95fc56cda0b5c3325f5fbbd7ff9fda9e02bb00bb3dac51252d2f1bfa1cb8cc8c"
|
|
62
|
-
dependencies = [
|
|
63
|
-
"unicode-ident",
|
|
64
|
-
]
|
|
65
|
-
|
|
66
|
-
[[package]]
|
|
67
|
-
name = "quote"
|
|
68
|
-
version = "1.0.35"
|
|
69
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
70
|
-
checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef"
|
|
71
|
-
dependencies = [
|
|
72
|
-
"proc-macro2",
|
|
73
|
-
]
|
|
74
|
-
|
|
75
|
-
[[package]]
|
|
76
|
-
name = "rutie"
|
|
77
|
-
version = "0.9.0"
|
|
78
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
79
|
-
checksum = "e5e8e4f6480c30609e3480adfab87b8d4792525225a1caf98b371fbc9a7b698a"
|
|
80
|
-
dependencies = [
|
|
81
|
-
"lazy_static",
|
|
82
|
-
"libc",
|
|
83
|
-
]
|
|
84
|
-
|
|
85
|
-
[[package]]
|
|
86
|
-
name = "syn"
|
|
87
|
-
version = "2.0.48"
|
|
88
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
89
|
-
checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f"
|
|
90
|
-
dependencies = [
|
|
91
|
-
"proc-macro2",
|
|
92
|
-
"quote",
|
|
93
|
-
"unicode-ident",
|
|
94
|
-
]
|
|
95
|
-
|
|
96
|
-
[[package]]
|
|
97
|
-
name = "unicode-ident"
|
|
98
|
-
version = "1.0.12"
|
|
99
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
100
|
-
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
|
|
101
|
-
|
|
102
|
-
[[package]]
|
|
103
|
-
name = "version_check"
|
|
104
|
-
version = "0.9.4"
|
|
105
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
106
|
-
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
|
|
107
|
-
|
|
108
|
-
[[package]]
|
|
109
|
-
name = "whatlang"
|
|
110
|
-
version = "0.16.4"
|
|
111
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
112
|
-
checksum = "471d1c1645d361eb782a1650b1786a8fb58dd625e681a04c09f5ff7c8764a7b0"
|
|
113
|
-
dependencies = [
|
|
114
|
-
"hashbrown",
|
|
115
|
-
"once_cell",
|
|
116
|
-
]
|
|
117
|
-
|
|
118
|
-
[[package]]
|
|
119
|
-
name = "whatlang-rb"
|
|
120
|
-
version = "0.1.6"
|
|
121
|
-
dependencies = [
|
|
122
|
-
"rutie",
|
|
123
|
-
"whatlang",
|
|
124
|
-
]
|
|
125
|
-
|
|
126
|
-
[[package]]
|
|
127
|
-
name = "zerocopy"
|
|
128
|
-
version = "0.7.32"
|
|
129
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
130
|
-
checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be"
|
|
131
|
-
dependencies = [
|
|
132
|
-
"zerocopy-derive",
|
|
133
|
-
]
|
|
134
|
-
|
|
135
|
-
[[package]]
|
|
136
|
-
name = "zerocopy-derive"
|
|
137
|
-
version = "0.7.32"
|
|
138
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
139
|
-
checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6"
|
|
140
|
-
dependencies = [
|
|
141
|
-
"proc-macro2",
|
|
142
|
-
"quote",
|
|
143
|
-
"syn",
|
|
144
|
-
]
|
data/Cargo.toml
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
[package]
|
|
2
|
-
name = "whatlang-rb"
|
|
3
|
-
version = "0.1.6"
|
|
4
|
-
authors = ["Kitaiti Makoto <KitaitiMakoto@gmail.com>"]
|
|
5
|
-
edition = "2018"
|
|
6
|
-
|
|
7
|
-
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
|
8
|
-
|
|
9
|
-
[dependencies]
|
|
10
|
-
rutie = { version = "0.9.0", features = ["no-link"] }
|
|
11
|
-
whatlang = "0.16.4"
|
|
12
|
-
|
|
13
|
-
[lib]
|
|
14
|
-
crate-type = ["cdylib"]
|
data/ext/Rakefile
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
task :default do
|
|
2
|
-
cargo_exists = `cargo` rescue nil
|
|
3
|
-
if cargo_exists
|
|
4
|
-
sh "cargo build --release"
|
|
5
|
-
else
|
|
6
|
-
fail <<EOS
|
|
7
|
-
Rust environment is required to install this gem.
|
|
8
|
-
|
|
9
|
-
For Unix like system, run
|
|
10
|
-
|
|
11
|
-
% curl https://sh.rustup.rs -sSf | sh
|
|
12
|
-
|
|
13
|
-
For Windows, download installer from
|
|
14
|
-
|
|
15
|
-
https://static.rust-lang.org/rustup/dist/i686-pc-windows-gnu/rustup-init.exe
|
|
16
|
-
|
|
17
|
-
See the Rust official page below for details
|
|
18
|
-
|
|
19
|
-
https://www.rust-lang.org/tools/install
|
|
20
|
-
|
|
21
|
-
EOS
|
|
22
|
-
end
|
|
23
|
-
end
|
data/src/lib.rs
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
use rutie::{
|
|
2
|
-
methods, module, AnyException, AnyObject, Array, Boolean, Float, Module, Object,
|
|
3
|
-
RString, VM,
|
|
4
|
-
};
|
|
5
|
-
use whatlang::{detect, detect_lang, detect_script, Detector, Info, Lang};
|
|
6
|
-
|
|
7
|
-
module!(Whatlang);
|
|
8
|
-
|
|
9
|
-
methods!(
|
|
10
|
-
Whatlang,
|
|
11
|
-
_rtself,
|
|
12
|
-
|
|
13
|
-
fn wl_detect_without_options(text: RString) -> AnyObject {
|
|
14
|
-
detect(rstring(text).to_str()).map_or(no_info(), rinfo)
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
fn wl_detect_with_allowlist(text: RString, list: Array) -> AnyObject {
|
|
18
|
-
let detector = Detector::with_allowlist(rarray_to_lang_list(list));
|
|
19
|
-
detector.detect(rstring(text).to_str()).map_or(no_info(), rinfo)
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
fn wl_detect_with_denylist(text: RString, list: Array) -> AnyObject {
|
|
23
|
-
let detector = Detector::with_denylist(rarray_to_lang_list(list));
|
|
24
|
-
detector.detect(rstring(text).to_str()).map_or(no_info(), rinfo)
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
fn wl_detect_lang(text: RString) -> AnyObject {
|
|
28
|
-
detect_lang(rstring(text).to_str()).map_or(no_info(), rlang)
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
fn wl_detect_script(text: RString) -> AnyObject {
|
|
32
|
-
detect_script(rstring(text).to_str()).map_or(no_info(), |script| {
|
|
33
|
-
RString::new_utf8(script.name()).into()
|
|
34
|
-
})
|
|
35
|
-
}
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
fn rstring(rstring: Result<RString, AnyException>) -> RString {
|
|
39
|
-
rstring.map_err(VM::raise_ex).unwrap()
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
fn rarray_to_lang_list(rarray: Result<Array, AnyException>) -> Vec<Lang> {
|
|
43
|
-
rarray
|
|
44
|
-
.map_err(VM::raise_ex)
|
|
45
|
-
.unwrap()
|
|
46
|
-
.into_iter()
|
|
47
|
-
.filter_map(|rcode| {
|
|
48
|
-
let code = rcode
|
|
49
|
-
.try_convert_to::<RString>()
|
|
50
|
-
.map_err(VM::raise_ex)
|
|
51
|
-
.unwrap();
|
|
52
|
-
Lang::from_code(code.to_str())
|
|
53
|
-
})
|
|
54
|
-
.collect()
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
fn rinfo(info: Info) -> AnyObject {
|
|
58
|
-
Module::from_existing("Whatlang")
|
|
59
|
-
.get_nested_class("Info")
|
|
60
|
-
.new_instance(&[
|
|
61
|
-
rlang(info.lang()),
|
|
62
|
-
RString::new_utf8(info.script().name()).into(),
|
|
63
|
-
Boolean::new(info.is_reliable()).into(),
|
|
64
|
-
Float::new(info.confidence()).into(),
|
|
65
|
-
])
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
fn rlang(lang: Lang) -> AnyObject {
|
|
69
|
-
Module::from_existing("Whatlang")
|
|
70
|
-
.get_nested_class("Lang")
|
|
71
|
-
.new_instance(&[
|
|
72
|
-
RString::new_utf8(lang.code()).into(),
|
|
73
|
-
RString::new_utf8(lang.name()).into(),
|
|
74
|
-
RString::new_utf8(lang.eng_name()).into(),
|
|
75
|
-
])
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// Needed because Rutie cause segmentation fault when it returns NilClass.
|
|
79
|
-
// Should be removed after https://github.com/danielpclark/rutie/pull/180 is solved.
|
|
80
|
-
fn no_info() -> AnyObject {
|
|
81
|
-
Module::from_existing("Whatlang")
|
|
82
|
-
.const_get("NO_INFO")
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
#[allow(non_snake_case)]
|
|
86
|
-
#[no_mangle]
|
|
87
|
-
pub extern "C" fn Init_whatlang() {
|
|
88
|
-
Module::new("Whatlang").define(|itself| {
|
|
89
|
-
itself.def_self("detect_without_options", wl_detect_without_options);
|
|
90
|
-
itself.def_self("detect_with_allowlist", wl_detect_with_allowlist);
|
|
91
|
-
itself.def_self("detect_with_denylist", wl_detect_with_denylist);
|
|
92
|
-
itself.def_self("detect_lang", wl_detect_lang);
|
|
93
|
-
itself.def_self("detect_script", wl_detect_script);
|
|
94
|
-
});
|
|
95
|
-
}
|