whatlanguage 2.0.0 → 2.0.1

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: '0939c1109ab44fd32e9e611c20696ee315a980877c0f04d5990fe42f51c17201'
4
- data.tar.gz: e5002ebde89b8c6acfa313355d2aa588b31cbb7db27870690bbeae761ecaeb2c
3
+ metadata.gz: 53fea55810c7a8eb102970d6d8c3fe039b031680ff0f23eb6a1c7fec6ad1a602
4
+ data.tar.gz: f960efb55e0d04b5e457ef53f6c382434a334eea9d44fab2065e7ce9d4376747
5
5
  SHA512:
6
- metadata.gz: 2a06fa18163cee6de9278291856c1b04c633880be1a2816476ce4b47b03c374242c9eb0ea012e1fb04322de753d45492a9ca96856ec70582ea1287fb19034c2e
7
- data.tar.gz: e57243d9fccc9b5c43e5da591db26085d2eedd7776a4bc3e6dfd9b8ddcfcc59112de6309f63a41f0b2f38bc171bce2d80e638b2c3a8645230657aeb643f852ef
6
+ metadata.gz: 99e1be592f692ba51e3a973a489703f955238da71985feb91b424e9203b8ae29d1ff635d5479ee6cea0226a06cd74c10c4f859a722c76914f277df3d41c3c779
7
+ data.tar.gz: e13bf56aa67c969d86213e9f1bd34bb2f0aa4ab0ab5db4c1b735ef84c9c3d2ad8e7891f0104a0881833fb5f54c42235132cf48f7a75af38f1cf5f71280529a31
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.0.1 / 2026-07-11
4
+
5
+ - Added a `whatlanguage` command-line executable that reads from files given as
6
+ arguments (or stdin) and prints the ISO 639 code of the detected language, or
7
+ `und` if undetermined. (#50, suggested by Keith Bennett)
8
+
3
9
  ## 2.0.0 / 2026-06-10
4
10
 
5
11
  - Rewrote the detection engine from scratch. Bloom-filter dictionary lookups are
data/README.md CHANGED
@@ -13,8 +13,11 @@ WhatLanguage.language("Que linguagem é essa? É uma pergunta sobre a língua po
13
13
  - No runtime dependencies.
14
14
  - Supports 20+ writing systems.
15
15
  - Ships a compact ~220 KB trigram model.
16
- - Requires Ruby 3.0+
17
- - Best on sentence-length text or longer.
16
+ - Requires Ruby 3.0+ (JRuby and TruffleRuby also good)
17
+ - **Best on sentence-length text or longer.** Short texts can have ambiguous results.
18
+
19
+ > [!IMPORTANT]
20
+ > v2.0 has many breaking changes as the entire library has been reimplemented, though the core `WhatLanguage.language` API remains similar. Versions 1.0.6 and earlier (so the 2007-2025 run of the library) used a Bloom-filter technique and had 5MB of binary files to handle ~20 languages. Version 2.0 is more accurate, faster, and supports more languages from a single 220KB JSON file :-)
18
21
 
19
22
  ## How it works
20
23
 
@@ -22,8 +25,6 @@ Detection is in two stages. First, the dominant Unicode script is detected; scri
22
25
 
23
26
  The trigram profiles are vendored from [whatlang](https://github.com/greyblake/whatlang-rs), a port of [Franc](https://github.com/wooorm/franc), whose models are built from the public-domain UDHR corpus (see Credits). The model is a ~220 KB JSON file.
24
27
 
25
- > [!IMPORTANT]
26
- > v2.0 has many breaking changes as the entire library has been rewritten, though the core `WhatLanguage.language` API remains similar. Versions 1.0.6 and earlier (so the 2007-2025 run of the library) used a Bloom-filter technique and had 5MB of binary files to handle ~20 languages. Version 2.0 is more accurate, faster, and supports more languages from a single 220KB JSON file :-)
27
28
 
28
29
  ## Usage
29
30
 
@@ -58,9 +59,20 @@ Short Latin-script fragments are ignored by default because there is not enough
58
59
  wl = WhatLanguage.new(min_chars: 0)
59
60
  ```
60
61
 
62
+ ## Command line
63
+
64
+ Installing the gem also installs a `whatlanguage` executable that reads from files given as arguments (or stdin) and prints the ISO 639 code of the detected language, or `und` if undetermined:
65
+
66
+ ```bash
67
+ $ whatlanguage README.md
68
+ en
69
+ $ echo "Wie geht es dir heute?" | whatlanguage
70
+ de
71
+ ```
72
+
61
73
  ## Known limitations
62
74
 
63
- - Short fragments are unreliable. For languages resolved by statistical comparison, fewer than 10 significant characters returns `nil` by default.
75
+ - Short fragments are unreliable. For languages resolved by statistical comparison, fewer than 10 significant characters returns `nil` by default. **This is the biggest thing I want to fix.** I think there should be a mechanism for "weighting" languages so that less likely languages don't frequently appear for small English samples, say.
64
76
  - Scores are relative ranking values, not probabilities. Use `#ranked` or `#detect.ranked` when close runners-up matter.
65
77
  - Closely related written languages can be hard to separate, especially Norwegian Bokmål/Danish, Hebrew/Yiddish, and similar language pairs.
66
78
  - Kanji-only Japanese text can classify as Chinese because Han characters alone do not identify the language.
@@ -68,6 +80,6 @@ wl = WhatLanguage.new(min_chars: 0)
68
80
 
69
81
  ## Credits
70
82
 
71
- Contributions from Konrad Reiche, Salimane Adjao Moustapha, Andrew Cone, Lasse Skindstad Ebert, Henrik Nyh, Daniel Sandbecker, Michael Hartl, Pedro Lambert, Tobias Preuss, Pepijn Looije, and others appreciated.
83
+ Contributions from Konrad Reiche, Salimane Adjao Moustapha, Andrew Cone, Lasse Skindstad Ebert, Henrik Nyh, Daniel Sandbecker, Michael Hartl, Pedro Lambert, Tobias Preuss, Pepijn Looije, Keith Bennett, and others appreciated.
72
84
 
73
85
  The trigram language profiles in `lib/whatlanguage/trigrams.json` are taken from [whatlang](https://github.com/greyblake/whatlang-rs) (MIT, © Sergey Potapov), itself a derivative of [Franc](https://github.com/wooorm/franc) (MIT, © Titus Wormer). Those profiles are derived from the public-domain Universal Declaration of Human Rights translations.
data/exe/whatlanguage ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'whatlanguage'
5
+
6
+ # Reads from files given as arguments, or stdin otherwise. Prints the ISO 639
7
+ # code of the detected language, or "und" (undetermined) if detection fails.
8
+ puts WhatLanguage.language_iso(ARGF.read) || 'und'
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class WhatLanguage
4
- VERSION = '2.0.0'
4
+ VERSION = '2.0.1'
5
5
  end
data/whatlanguage.gemspec CHANGED
@@ -16,6 +16,7 @@ Gem::Specification.new do |gem|
16
16
  gem.required_ruby_version = '>= 3.0'
17
17
 
18
18
  gem.files = Dir['lib/**/*'] + [
19
+ 'exe/whatlanguage',
19
20
  'README.md',
20
21
  'CHANGELOG.md',
21
22
  'LICENSE.txt',
@@ -23,6 +24,8 @@ Gem::Specification.new do |gem|
23
24
  'Rakefile',
24
25
  'whatlanguage.gemspec'
25
26
  ]
27
+ gem.bindir = 'exe'
28
+ gem.executables = ['whatlanguage']
26
29
  gem.require_paths = ['lib']
27
30
 
28
31
  gem.add_development_dependency 'minitest', '~> 5.0'
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: whatlanguage
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Cooper
8
- bindir: bin
8
+ bindir: exe
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
@@ -40,7 +40,8 @@ dependencies:
40
40
  description: WhatLanguage rapidly detects the language of a sample of text
41
41
  email:
42
42
  - git@peterc.org
43
- executables: []
43
+ executables:
44
+ - whatlanguage
44
45
  extensions: []
45
46
  extra_rdoc_files: []
46
47
  files:
@@ -49,6 +50,7 @@ files:
49
50
  - LICENSE.txt
50
51
  - README.md
51
52
  - Rakefile
53
+ - exe/whatlanguage
52
54
  - lib/whatlanguage.rb
53
55
  - lib/whatlanguage/languages.rb
54
56
  - lib/whatlanguage/trigrams.json