whatlang 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/CHANGELOG.md +5 -0
- data/Cargo.lock +64 -0
- data/Cargo.toml +3 -3
- data/README.md +3 -3
- data/Rakefile +2 -0
- data/lib/whatlang.rb +7 -7
- data/src/lib.rs +14 -15
- data/test/whatlang_test.rb +7 -7
- data/whatlang.gemspec +1 -8
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36245d42bea26a35cafc65448b915efab2f3a372c58d4230b5de21d9fc7219fa
|
4
|
+
data.tar.gz: 42a935dca11dfd87741c16bbcefd5ef0d1c475cf20c7e109accb7e4d21c2da43
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ac72ff2a73db480bc82406ba057f696850505532f714e813e7b4d70b5ae1432cab89a1527e6a6e7a518843199e0cda96265c71342a9b48972412a0d058751f5d
|
7
|
+
data.tar.gz: a7a320d6b29572cdadabc27400f6cfd376158cc6322a17952535fbfc0a99cd0bbb9ff7251f7966caef9ab3b11c589b37d20f5d0b5c77fe2e30c163c718d5c7c4
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
data/Cargo.lock
ADDED
@@ -0,0 +1,64 @@
|
|
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.3.8"
|
8
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
9
|
+
checksum = "e8fd72866655d1904d6b0997d0b07ba561047d070fbe29de039031c641b61217"
|
10
|
+
|
11
|
+
[[package]]
|
12
|
+
name = "autocfg"
|
13
|
+
version = "1.0.1"
|
14
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
15
|
+
checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
|
16
|
+
|
17
|
+
[[package]]
|
18
|
+
name = "hashbrown"
|
19
|
+
version = "0.7.2"
|
20
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
21
|
+
checksum = "96282e96bfcd3da0d3aa9938bedf1e50df3269b6db08b4876d2da0bb1a0841cf"
|
22
|
+
dependencies = [
|
23
|
+
"ahash",
|
24
|
+
"autocfg",
|
25
|
+
]
|
26
|
+
|
27
|
+
[[package]]
|
28
|
+
name = "lazy_static"
|
29
|
+
version = "1.4.0"
|
30
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
31
|
+
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
32
|
+
|
33
|
+
[[package]]
|
34
|
+
name = "libc"
|
35
|
+
version = "0.2.99"
|
36
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
37
|
+
checksum = "a7f823d141fe0a24df1e23b4af4e3c7ba9e5966ec514ea068c93024aa7deb765"
|
38
|
+
|
39
|
+
[[package]]
|
40
|
+
name = "rutie"
|
41
|
+
version = "0.8.2"
|
42
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
43
|
+
checksum = "678217ed742ca819057a79c0146703d1278afbb38896eb0283c410a6cab7c28c"
|
44
|
+
dependencies = [
|
45
|
+
"lazy_static",
|
46
|
+
"libc",
|
47
|
+
]
|
48
|
+
|
49
|
+
[[package]]
|
50
|
+
name = "whatlang"
|
51
|
+
version = "0.12.0"
|
52
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
53
|
+
checksum = "7a346d2eb29c03618693ed24a29d1acd0c3f2cb08ae58b9669d7461e033cf703"
|
54
|
+
dependencies = [
|
55
|
+
"hashbrown",
|
56
|
+
]
|
57
|
+
|
58
|
+
[[package]]
|
59
|
+
name = "whatlang-rb"
|
60
|
+
version = "0.1.0"
|
61
|
+
dependencies = [
|
62
|
+
"rutie",
|
63
|
+
"whatlang",
|
64
|
+
]
|
data/Cargo.toml
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
[package]
|
2
2
|
name = "whatlang-rb"
|
3
|
-
version = "0.1.
|
3
|
+
version = "0.1.1"
|
4
4
|
authors = ["Kitaiti Makoto <KitaitiMakoto@gmail.com>"]
|
5
5
|
edition = "2018"
|
6
6
|
|
7
7
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
8
8
|
|
9
9
|
[dependencies]
|
10
|
-
rutie = { version = "0.8.
|
11
|
-
whatlang = "0.
|
10
|
+
rutie = { version = "0.8.2", features = ["no-link"] }
|
11
|
+
whatlang = "0.12.0"
|
12
12
|
|
13
13
|
[lib]
|
14
14
|
crate-type = ["cdylib"]
|
data/README.md
CHANGED
@@ -61,10 +61,10 @@ Usage
|
|
61
61
|
|
62
62
|
text = "Jen la trinkejo fermitis, ni iras tra mallumo kaj pluvo."
|
63
63
|
list = ["eng", "ita"]
|
64
|
-
Whatlang.detect(text,
|
65
|
-
Whatlang.detect(text,
|
64
|
+
Whatlang.detect(text, allowlist: list).lang.code # => "ita"
|
65
|
+
Whatlang.detect(text, denylist: list).lang.code # => "epo"
|
66
66
|
|
67
|
-
If you're
|
67
|
+
If you're interested in only language information, use `detect_lang` function:
|
68
68
|
|
69
69
|
lang = Whatlang.detect_lang(text)
|
70
70
|
lang.code # => "bul"
|
data/Rakefile
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "rake/clean"
|
3
4
|
require "rubygems/tasks"
|
4
5
|
require "rake/testtask"
|
5
6
|
require "yard"
|
@@ -25,4 +26,5 @@ end
|
|
25
26
|
file RUST_TARGET => RUST_SRC do
|
26
27
|
sh "cargo build --release"
|
27
28
|
end
|
29
|
+
CLEAN.include RUST_TARGET
|
28
30
|
task test: RUST_TARGET
|
data/lib/whatlang.rb
CHANGED
@@ -4,16 +4,16 @@ Rutie.new(:whatlang_rb).init "Init_whatlang", __dir__
|
|
4
4
|
|
5
5
|
module Whatlang
|
6
6
|
class << self
|
7
|
-
def detect(text,
|
8
|
-
if
|
9
|
-
raise ArgumentError, "Couldn't specify `
|
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
10
|
end
|
11
11
|
|
12
12
|
case
|
13
|
-
when
|
14
|
-
|
15
|
-
when
|
16
|
-
|
13
|
+
when allowlist
|
14
|
+
detect_with_allowlist(text, allowlist)
|
15
|
+
when denylist
|
16
|
+
detect_with_denylist(text, denylist)
|
17
17
|
else
|
18
18
|
detect_without_options(text)
|
19
19
|
end
|
data/src/lib.rs
CHANGED
@@ -2,7 +2,7 @@ use rutie::{
|
|
2
2
|
methods, module, AnyException, AnyObject, Array, Boolean, Float, Module, NilClass, Object,
|
3
3
|
RString, VM,
|
4
4
|
};
|
5
|
-
use whatlang::{detect, detect_lang, detect_script,
|
5
|
+
use whatlang::{detect, detect_lang, detect_script, Detector, Info, Lang};
|
6
6
|
|
7
7
|
module!(Whatlang);
|
8
8
|
|
@@ -14,14 +14,14 @@ methods!(
|
|
14
14
|
detect(rstring(text).to_str()).map_or(NilClass::new().into(), rinfo)
|
15
15
|
}
|
16
16
|
|
17
|
-
fn
|
18
|
-
let
|
19
|
-
|
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(NilClass::new().into(), rinfo)
|
20
20
|
}
|
21
21
|
|
22
|
-
fn
|
23
|
-
let
|
24
|
-
|
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(NilClass::new().into(), rinfo)
|
25
25
|
}
|
26
26
|
|
27
27
|
fn wl_detect_lang(text: RString) -> AnyObject {
|
@@ -40,19 +40,18 @@ fn rstring(rstring: Result<RString, AnyException>) -> RString {
|
|
40
40
|
}
|
41
41
|
|
42
42
|
fn rarray_to_lang_list(rarray: Result<Array, AnyException>) -> Vec<Lang> {
|
43
|
-
|
44
|
-
|
43
|
+
rarray
|
44
|
+
.map_err(VM::raise_ex)
|
45
|
+
.unwrap()
|
45
46
|
.into_iter()
|
46
|
-
.
|
47
|
+
.filter_map(|rcode| {
|
47
48
|
let code = rcode
|
48
49
|
.try_convert_to::<RString>()
|
49
50
|
.map_err(VM::raise_ex)
|
50
51
|
.unwrap();
|
51
52
|
Lang::from_code(code.to_str())
|
52
53
|
})
|
53
|
-
.
|
54
|
-
.map(|lang_res| lang_res.unwrap())
|
55
|
-
.collect::<Vec<Lang>>()
|
54
|
+
.collect()
|
56
55
|
}
|
57
56
|
|
58
57
|
fn rinfo(info: Info) -> AnyObject {
|
@@ -81,8 +80,8 @@ fn rlang(lang: Lang) -> AnyObject {
|
|
81
80
|
pub extern "C" fn Init_whatlang() {
|
82
81
|
Module::new("Whatlang").define(|itself| {
|
83
82
|
itself.def_self("detect_without_options", wl_detect_without_options);
|
84
|
-
itself.def_self("
|
85
|
-
itself.def_self("
|
83
|
+
itself.def_self("detect_with_allowlist", wl_detect_with_allowlist);
|
84
|
+
itself.def_self("detect_with_denylist", wl_detect_with_denylist);
|
86
85
|
itself.def_self("detect_lang", wl_detect_lang);
|
87
86
|
itself.def_self("detect_script", wl_detect_script);
|
88
87
|
});
|
data/test/whatlang_test.rb
CHANGED
@@ -8,10 +8,10 @@ class WhatlangTest < Test::Unit::TestCase
|
|
8
8
|
list = ["eng", "ita"]
|
9
9
|
|
10
10
|
assert_equal "epo", Whatlang.detect(text).lang.code
|
11
|
-
assert_equal "ita", Whatlang.detect(text,
|
12
|
-
assert_equal "epo", Whatlang.detect(text,
|
11
|
+
assert_equal "ita", Whatlang.detect(text, allowlist: list).lang.code
|
12
|
+
assert_equal "epo", Whatlang.detect(text, denylist: list).lang.code
|
13
13
|
assert_raise ArgumentError do
|
14
|
-
Whatlang.detect(text,
|
14
|
+
Whatlang.detect(text, allowlist: list, denylist: list)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
@@ -22,16 +22,16 @@ class WhatlangTest < Test::Unit::TestCase
|
|
22
22
|
assert_equal "Latin", info.script
|
23
23
|
end
|
24
24
|
|
25
|
-
def
|
25
|
+
def test_detect_with_allowlist
|
26
26
|
text = "Jen la trinkejo fermitis, ni iras tra mallumo kaj pluvo."
|
27
27
|
list = ["eng", "ita"]
|
28
|
-
assert_equal "ita", Whatlang.
|
28
|
+
assert_equal "ita", Whatlang.detect_with_allowlist(text, list).lang.code
|
29
29
|
end
|
30
30
|
|
31
|
-
def
|
31
|
+
def test_detect_with_denylist
|
32
32
|
text = "Jen la trinkejo fermitis, ni iras tra mallumo kaj pluvo."
|
33
33
|
list = ["eng", "ita"]
|
34
|
-
assert_equal "epo", Whatlang.
|
34
|
+
assert_equal "epo", Whatlang.detect_with_denylist(text, list).lang.code
|
35
35
|
end
|
36
36
|
|
37
37
|
def test_detect_lang
|
data/whatlang.gemspec
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
require "tomlrb"
|
4
2
|
|
5
3
|
Gem::Specification.new do |spec|
|
@@ -9,10 +7,9 @@ Gem::Specification.new do |spec|
|
|
9
7
|
spec.authors = ["Kitaiti Makoto"]
|
10
8
|
spec.email = ["KitaitiMakoto@gmail.com"]
|
11
9
|
|
12
|
-
spec.summary = "Natural language detection."
|
10
|
+
spec.summary = "Natural language detection library."
|
13
11
|
spec.description = "Ruby bindings for Whatlang, a natural language detection for Rust."
|
14
12
|
spec.homepage = "https://gitlab.com/KitaitiMakoto/whatlang-rb"
|
15
|
-
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
16
13
|
|
17
14
|
spec.metadata["homepage_uri"] = spec.homepage
|
18
15
|
spec.metadata["source_code_uri"] = "https://gitlab.com/KitaitiMakoto/whatlang-rb"
|
@@ -21,7 +18,6 @@ Gem::Specification.new do |spec|
|
|
21
18
|
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
22
19
|
`git ls-files -z`.split("\x0")
|
23
20
|
end
|
24
|
-
spec.require_paths = ["lib"]
|
25
21
|
spec.extensions = ["ext/Rakefile"]
|
26
22
|
|
27
23
|
spec.add_runtime_dependency "rutie"
|
@@ -31,7 +27,4 @@ Gem::Specification.new do |spec|
|
|
31
27
|
spec.add_development_dependency "rake"
|
32
28
|
spec.add_development_dependency "yard"
|
33
29
|
spec.add_development_dependency "rubygems-tasks"
|
34
|
-
|
35
|
-
# For more information and examples about making a new gem, checkout our
|
36
|
-
# guide at: https://bundler.io/guides/creating_gem.html
|
37
30
|
end
|
metadata
CHANGED
@@ -1,14 +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.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kitaiti Makoto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-08-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rutie
|
@@ -105,6 +105,7 @@ files:
|
|
105
105
|
- ".gitignore"
|
106
106
|
- ".yardopts"
|
107
107
|
- CHANGELOG.md
|
108
|
+
- Cargo.lock
|
108
109
|
- Cargo.toml
|
109
110
|
- Gemfile
|
110
111
|
- README.md
|
@@ -131,15 +132,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
131
132
|
requirements:
|
132
133
|
- - ">="
|
133
134
|
- !ruby/object:Gem::Version
|
134
|
-
version:
|
135
|
+
version: '0'
|
135
136
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
137
|
requirements:
|
137
138
|
- - ">="
|
138
139
|
- !ruby/object:Gem::Version
|
139
140
|
version: '0'
|
140
141
|
requirements: []
|
141
|
-
rubygems_version: 3.2.
|
142
|
+
rubygems_version: 3.2.22
|
142
143
|
signing_key:
|
143
144
|
specification_version: 4
|
144
|
-
summary: Natural language detection.
|
145
|
+
summary: Natural language detection library.
|
145
146
|
test_files: []
|