lingua_rs 0.4.1 → 0.4.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bd0dba860ee235a6acfc46afb3ba851ec08303df9499f403e47624c74b9396e7
4
- data.tar.gz: b3d9faca1f0f12fb7abee0643b94f1f494ef02e6b4f2c92846fa88e94d503904
3
+ metadata.gz: 4c9b82b89f03f11a0675e53ffd21161a0b79d3f66e8ef4bdbdb96179439e7dd3
4
+ data.tar.gz: 44e5fba6b4cf30e1f651613e3f3631107d9823c831535622d5884dd5aae464ad
5
5
  SHA512:
6
- metadata.gz: 2cae21715d81d650c71df5d55b18fb7b09eb86bcfe1356e5ace3b526a48e9ff31be39d852ee43abe342dffed711c7ea08ad3a9342702960b04a864a674df6068
7
- data.tar.gz: 221eb0c62f4b7158d5c95b4d7c28490a2bcabc3f4cffe64914bea62c413c0d35fc8ceab1a6b6dc81a4750e75f8d7deac522bab1d0aa97b5c02cfd7d49e9eab40
6
+ metadata.gz: 6d681afb8de476d7f7da3ac14ac000ee51d7ef301f01eb22e033a3b4885f4d0c7e7dac6713fbfe56ee7d4bd5341011d9fe7abf329f5e8eb8b38b5ffb54d870bd
7
+ data.tar.gz: 7d3dc5c3c73bf30d11e8ddca1c92e49869bb87a98fef66865dc7ea35376294c08858633dc981da8f8a33c5a6f29c10b8fc62d79fb51457161e7b6efddd91dc12
data/README.md CHANGED
@@ -1,9 +1,9 @@
1
1
  # LinguaRs
2
2
 
3
3
  [![CI](https://github.com/kochka/lingua_rs/actions/workflows/ci.yml/badge.svg)](https://github.com/kochka/lingua_rs/actions/workflows/ci.yml)
4
- [![Gem Version](https://badge.fury.io/rb/lingua_rs.svg)](https://badge.fury.io/rb/lingua_rs)
5
- [![Downloads](https://img.shields.io/gem/dt/lingua_rs)](https://rubygems.org/gems/lingua_rs)
6
- [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
4
+ [![Gem Version](https://img.shields.io/gem/v/lingua_rs?color=cc342d)](https://rubygems.org/gems/lingua_rs)
5
+ [![Downloads](https://img.shields.io/gem/dt/lingua_rs?color=0969da)](https://rubygems.org/gems/lingua_rs)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-6e7781.svg)](https://opensource.org/licenses/MIT)
7
7
 
8
8
  A Ruby gem wrapping the [Lingua](https://github.com/pemistahl/lingua-rs) Rust library for language detection.
9
9
 
@@ -213,21 +213,41 @@ end
213
213
 
214
214
  ## Optimization: selecting languages
215
215
 
216
- By default, all 75 languages are compiled into the native extension (~278 MB). If you only need a subset, set the `LINGUA_LANGUAGES` environment variable before installing to reduce binary size and improve detection speed:
216
+ By default, all 75 languages are compiled into the native extension (~278 MB). If you only need a subset, select languages at build time to reduce binary size and improve detection speed.
217
+
218
+ ### Build option
219
+
220
+ Use `--with-lingua-languages` to select languages. With Bundler you can persist the setting so it applies to every future `bundle install`:
217
221
 
218
222
  ```bash
219
- LINGUA_LANGUAGES=core bundle install
223
+ bundle config set build.lingua_rs --with-lingua-languages=core
224
+ bundle install
220
225
  ```
221
226
 
222
227
  This compiles only the selected language models (~29 MB for the `core` bundle). You can use individual language names or predefined bundles, and you can mix both in the same build.
223
228
 
224
- This also works with `gem install`, for example:
229
+ The setting is saved in your local Bundler config (`~/.bundle/config` or `.bundle/config`) and is reused automatically on subsequent installs. To change it later:
225
230
 
226
231
  ```bash
227
- LINGUA_LANGUAGES=french,english,german gem install lingua_rs
232
+ bundle config set build.lingua_rs --with-lingua-languages=europe_common,japanese
233
+ bundle install
228
234
  ```
229
235
 
230
- Available bundles:
236
+ To remove it and go back to all languages:
237
+
238
+ ```bash
239
+ bundle config unset build.lingua_rs
240
+ bundle install
241
+ ```
242
+
243
+ This also works with `gem install`:
244
+
245
+ ```bash
246
+ gem install lingua_rs -- --with-lingua-languages=french,english,german
247
+ ```
248
+
249
+
250
+ ### Available languages and bundles
231
251
 
232
252
  | Bundle | Languages |
233
253
  | --- | --- |
@@ -242,13 +262,17 @@ Available bundles:
242
262
  Examples:
243
263
 
244
264
  ```bash
245
- LINGUA_LANGUAGES=core bundle install
246
- LINGUA_LANGUAGES=europe_common,polish bundle install
247
- LINGUA_LANGUAGES=east_asia,english bundle install
265
+ bundle config set build.lingua_rs --with-lingua-languages=core
266
+ bundle config set build.lingua_rs --with-lingua-languages=europe_common,polish
267
+ bundle config set build.lingua_rs --with-lingua-languages=east_asia,english
248
268
  ```
249
269
 
250
270
  Language and bundle names must match the Cargo features defined by this gem (lowercase, e.g. `french`, `english`, `german`, `core`, `europe_common`).
251
271
 
272
+ Supported languages (from [Lingua Rust's official list](https://github.com/pemistahl/lingua-rs?tab=readme-ov-file#3-which-languages-are-supported)):
273
+
274
+ `afrikaans`, `albanian`, `arabic`, `armenian`, `azerbaijani`, `basque`, `belarusian`, `bengali`, `bokmal`, `bosnian`, `bulgarian`, `catalan`, `chinese`, `croatian`, `czech`, `danish`, `dutch`, `english`, `esperanto`, `estonian`, `finnish`, `french`, `ganda`, `georgian`, `german`, `greek`, `gujarati`, `hebrew`, `hindi`, `hungarian`, `icelandic`, `indonesian`, `irish`, `italian`, `japanese`, `kazakh`, `korean`, `latin`, `latvian`, `lithuanian`, `macedonian`, `malay`, `maori`, `marathi`, `mongolian`, `nynorsk`, `persian`, `polish`, `portuguese`, `punjabi`, `romanian`, `russian`, `serbian`, `shona`, `slovak`, `slovene`, `somali`, `sotho`, `spanish`, `swahili`, `swedish`, `tagalog`, `tamil`, `telugu`, `thai`, `tsonga`, `tswana`, `turkish`, `ukrainian`, `urdu`, `vietnamese`, `welsh`, `xhosa`, `yoruba`, `zulu`
275
+
252
276
  ## Development
253
277
 
254
278
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake compile` to build the native extension and `rake test` to run the tests.
@@ -4,8 +4,11 @@ require 'mkmf'
4
4
  require 'rb_sys/mkmf'
5
5
 
6
6
  # Allow users to select specific languages to reduce binary size.
7
+ # Supports both --with-lingua-languages build option and LINGUA_LANGUAGES env var.
8
+ # Example: bundle config set build.lingua_rs --with-lingua-languages=core
7
9
  # Example: LINGUA_LANGUAGES=french,english,german bundle install
8
- languages = ENV.fetch('LINGUA_LANGUAGES', '').split(',').map { |lang| lang.strip.downcase }
10
+ selection = with_config('lingua-languages', nil) || ENV.fetch('LINGUA_LANGUAGES', '')
11
+ languages = selection.to_s.split(',').map { |lang| lang.strip.downcase }.reject(&:empty?)
9
12
 
10
13
  create_rust_makefile('lingua/lingua') do |r|
11
14
  unless languages.empty?
@@ -122,6 +122,12 @@ pub fn build_detector_from_options(
122
122
  })?;
123
123
  languages.push(lang);
124
124
  }
125
+ if languages.is_empty() {
126
+ return Err(magnus::Error::new(
127
+ ruby.exception_arg_error(),
128
+ "languages must contain at least 1 language",
129
+ ));
130
+ }
125
131
  LanguageDetectorBuilder::from_languages(&languages)
126
132
  } else {
127
133
  LanguageDetectorBuilder::from_all_languages()
@@ -129,6 +135,12 @@ pub fn build_detector_from_options(
129
135
 
130
136
  if let Some(opts) = options {
131
137
  if let Some(dist) = fetch_option::<f64>(ruby, opts, "minimum_relative_distance") {
138
+ if !(0.0..=0.99).contains(&dist) {
139
+ return Err(magnus::Error::new(
140
+ ruby.exception_arg_error(),
141
+ "minimum_relative_distance must be between 0.0 and 0.99",
142
+ ));
143
+ }
132
144
  builder.with_minimum_relative_distance(dist);
133
145
  }
134
146
  if fetch_option::<bool>(ruby, opts, "is_every_language_model_preloaded").unwrap_or(false) {
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Lingua
4
- VERSION = '0.4.1'
4
+ VERSION = '0.4.3'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lingua_rs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sébastien Vrillaud
@@ -37,8 +37,9 @@ dependencies:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
39
  version: 1.3.0
40
- description: Native Ruby bindings for the Lingua Rust library. Detects languages with
41
- confidence scores, ISO 639-1/639-3 support, and configurable accuracy modes.
40
+ description: Native Ruby bindings for the Lingua Rust library, bringing highly accurate
41
+ language detection for short text and mixed-language text to Ruby, with confidence
42
+ scores and ISO 639-1/639-3 language codes.
42
43
  email:
43
44
  - kochka@gmail.com
44
45
  executables: []
@@ -86,5 +87,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
87
  requirements: []
87
88
  rubygems_version: 3.6.9
88
89
  specification_version: 4
89
- summary: Fast language detection for Ruby, powered by Lingua (Rust).
90
+ summary: High-accuracy language detection powered by Lingua (Rust).
90
91
  test_files: []