that_language 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 55ee472553f58911e2ae6ce8dcc5bb3810a2d5ad
4
- data.tar.gz: 90319b193692262d7cc03da0303361b87fc9b5ef
3
+ metadata.gz: 41ecd55149abde5d1b27e64be73afd2e63d0b821
4
+ data.tar.gz: 82764566978fa2fdee98eaf3f8d7f7b71bdb6742
5
5
  SHA512:
6
- metadata.gz: aa3e9829509503cf095fbcda14533402c02116d2bb0174f6c792475269ce335dd440f1d096fa1060633f9c183d43d712b3ea6979b616ac089829ad965a47c071
7
- data.tar.gz: 5815e76c184809b88d85e965f01108b52affe623fb0fd0afc97ec33d4d29d2b1c214bb19e552fece2c34e3d4c0e21b498fe8834c254d2eac32fd78129297629f
6
+ metadata.gz: f4c718d69f9f1f38da49d24f80d01507064aa32a6571bfbe31ac99f2ac5ce45fdbd2437c2a9599cb1be6d9f36ae4838ec1783491826e1bd4642b714f9c5e83f3
7
+ data.tar.gz: 8d1482da930ffe300f288476b11274f22b001df698f49d7901fdfbb6944b827b75f37a0f3650892ce3433932fb843dd918c5425a3b285cbd7c99a95229624233
data/README.md CHANGED
@@ -1,15 +1,11 @@
1
- # DetectLanguage
2
-
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/detect_language`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
1
+ # ThatLanguage
6
2
 
7
3
  ## Installation
8
4
 
9
5
  Add this line to your application's Gemfile:
10
6
 
11
7
  ```ruby
12
- gem 'detect_language'
8
+ gem 'that_language'
13
9
  ```
14
10
 
15
11
  And then execute:
@@ -18,32 +14,199 @@ And then execute:
18
14
 
19
15
  Or install it yourself as:
20
16
 
21
- $ gem install detect_language
17
+ $ gem install that_language
18
+
19
+ ## Examples
20
+
21
+ ```ruby
22
+ text = "This is just a random english sentence."
23
+
24
+ ## == Language
25
+
26
+ ThatLanguage.language(text)
27
+ # => :English
28
+
29
+
30
+ ## == LanguageCode
31
+
32
+ ThatLanguage.language_code(text)
33
+ # => "en"
34
+
35
+
36
+ ## == Detect
37
+
38
+ detect = ThatLanguage.detect(text)
39
+ # => #<ThatLanguage::Result:...
40
+
41
+ detect.language
42
+ # => :English
43
+
44
+ detect.language_code
45
+ # => "en"
46
+
47
+ detect.confidence
48
+ # => 0.5631093821386951
49
+
50
+ detect.to_h
51
+ # =>
52
+ # {
53
+ # language: :English,
54
+ # language_code: "en",
55
+ # confidence: 0.5631093821386951,
56
+ # value: 3.9417656749708656,
57
+ # hit_ratio: 0.8571428571428571,
58
+ # hit_count: 6,
59
+ # words_count: 7
60
+ # }
61
+
62
+
63
+ ## == Details
64
+
65
+ details = ThatLanguage.details(text)
66
+ # => #<ThatLanguage::ResultSet:...
67
+
68
+ winner = details.winner
69
+ # => #<ThatLanguage::Result:...
70
+
71
+ results = details.results
72
+ # => [#<ThatLanguage::Result, #<ThatLanguage::Result, ...]
73
+
74
+ details.to_h
75
+ # =>
76
+ # {
77
+ # "results" => [
78
+ # {
79
+ # language: :English,
80
+ # language_code: "en",
81
+ # confidence: 0.5631093821386951,
82
+ # value: 3.9417656749708656,
83
+ # hit_ratio: 0.8571428571428571,
84
+ # hit_count: 6,
85
+ # words_count: 7
86
+ # },
87
+ # {
88
+ # language: :Hungarian,
89
+ # language_code: "hu",
90
+ # confidence: 0.21380816083786156,
91
+ # value: 1.496657125865031,
92
+ # hit_ratio: 0.42857142857142855,
93
+ # hit_count: 3,
94
+ # words_count: 7
95
+ # },
96
+ # # ...
97
+ # ]
98
+ # }
99
+ ```
22
100
 
23
101
  ## Supported locales
24
102
 
25
- * ar
26
- * da
27
- * de
28
- * en
29
- * es
30
- * fa
31
- * fr
32
- * it
33
- * nl
34
- * pt
35
- * ru
36
- * sv
103
+ ```ruby
104
+ require 'pp'
105
+
106
+ pp ThatLanguage.available
107
+
108
+ {
109
+ ak: :Akan,
110
+ am: :Amharic,
111
+ ar: :Arabic,
112
+ as: :Assamese,
113
+ az: :Azerbaijani,
114
+ be: :Belarusian,
115
+ bn: :Bengali,
116
+ cs: :Czech,
117
+ da: :Danish,
118
+ de: :German,
119
+ el: :Greek,
120
+ en: :English,
121
+ es: :Spanish,
122
+ fa: :Persian,
123
+ ff: :Fula,
124
+ fi: :Finnish,
125
+ fr: :French,
126
+ gu: :Gujarati,
127
+ ha: :Hausa,
128
+ he: :Hebrew,
129
+ hi: :Hindi,
130
+ ht: :Haitian,
131
+ hu: :Hungarian,
132
+ it: :Italian,
133
+ ja: :Japanese,
134
+ jv: :Javanese,
135
+ kk: :Kazakh,
136
+ km: :Khmer,
137
+ kn: :Kannada,
138
+ ko: :Korean,
139
+ ku: :Kurdish,
140
+ mg: :Malagasy,
141
+ mr: :Marathi,
142
+ ms: :Malay,
143
+ my: :Burmese,
144
+ ne: :Nepali,
145
+ nl: :Dutch,
146
+ nn: :"Norwegian Nynorsk",
147
+ no: :Norwegian,
148
+ ny: :Chichewa,
149
+ om: :Oromo,
150
+ or: :Oriya,
151
+ pa: :Panjabi,
152
+ pl: :Polish,
153
+ ps: :Pashto,
154
+ pt: :Portuguese,
155
+ qu: :Quechua,
156
+ rn: :Kirundi,
157
+ ro: :Romanian,
158
+ ru: :Russian,
159
+ rw: :Kinyarwanda,
160
+ sd: :Sindhi,
161
+ si: :Sinhala,
162
+ sn: :Shona,
163
+ so: :Somali,
164
+ su: :Sundanese,
165
+ sv: :Swedish,
166
+ ta: :Tamil,
167
+ te: :Telugu,
168
+ th: :Thai,
169
+ tk: :Turkmen,
170
+ tl: :Tagalog,
171
+ tr: :Turkish,
172
+ ug: :Uyghur,
173
+ uk: :Ukrainian,
174
+ ur: :Urdu,
175
+ uz: :Uzbek,
176
+ vi: :Vietnamese,
177
+ xh: :Xhosa,
178
+ yo: :Yoruba,
179
+ zh: :Chinese,
180
+ zu: :Zulu
181
+ }
182
+
183
+ ```
184
+
185
+ ## Configure
186
+
187
+ To use a custom directory that contains all the wordlists:
188
+
189
+ ```ruby
190
+ ThatLanguage.configure do |config|
191
+ config.wordlist_path = File.join("wordlists", "100k")
192
+ end
193
+ ```
37
194
 
38
195
  ## Development
39
196
 
40
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
197
+ After checking out the repo, run `bin/setup` to install dependencies.
198
+ Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
41
199
 
42
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
200
+ To install this gem onto your local machine, run `bundle exec rake install`.
201
+ To release a new version, update the version number in `version.rb`,
202
+ and then run `bundle exec rake release`, which will create a git tag for the version,
203
+ push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
43
204
 
44
205
  ## Contributing
45
206
 
46
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/detect_language. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
207
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Deradon/that_language.
208
+ This project is intended to be a safe, welcoming space for collaboration,
209
+ and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
47
210
 
48
211
 
49
212
  ## License
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "bundler/setup"
4
- require "detect_language"
4
+ require "that_language"
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
@@ -15,6 +15,10 @@ module ThatLanguage
15
15
  end
16
16
  alias_method :config, :configuration
17
17
 
18
+ def configure
19
+ yield(config)
20
+ end
21
+
18
22
  def language(text)
19
23
  detect_context.language(text)
20
24
  end
@@ -1,11 +1,13 @@
1
1
  module ThatLanguage
2
2
  class Configuration
3
- attr_reader :wordlist_path
4
-
5
- def initialize
6
- @wordlist_path = File.absolute_path(
3
+ def wordlist_path
4
+ @wordlist_path ||= File.absolute_path(
7
5
  File.join(File.dirname(__FILE__), '../../wordlists/10k/')
8
6
  )
9
7
  end
8
+
9
+ def wordlist_path=(path)
10
+ @wordlist_path = path
11
+ end
10
12
  end
11
13
  end
@@ -43,9 +43,13 @@ module ThatLanguage
43
43
  value > other.value
44
44
  end
45
45
 
46
+ def language
47
+ Iso639[language_code]
48
+ end
49
+
46
50
  def to_h
47
51
  {
48
- language: Iso639[language_code],
52
+ language: language,
49
53
  language_code: language_code,
50
54
  confidence: confidence,
51
55
  value: value,
@@ -1,3 +1,3 @@
1
1
  module ThatLanguage
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -10,8 +10,8 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["me@patrick-helm.de"]
11
11
 
12
12
  spec.summary = %q{Detect language of given text}
13
- spec.description = %q{Detect language of given text}
14
- spec.homepage = "http://gitlab.patrick-helm.de/Ruby/that-language"
13
+ # spec.description = %q{Detect language of given text}
14
+ spec.homepage = "https://github.com/Deradon/that_language"
15
15
  spec.license = "MIT"
16
16
 
17
17
  # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
@@ -28,6 +28,7 @@ Gem::Specification.new do |spec|
28
28
  spec.require_paths = ["lib"]
29
29
 
30
30
  spec.add_development_dependency "bundler", "~> 1.10"
31
+ spec.add_development_dependency "pry"
31
32
  spec.add_development_dependency "rake", "~> 10.0"
32
33
  spec.add_development_dependency "rspec"
33
34
  spec.add_development_dependency "rspec-its"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: that_language
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrick Helm
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
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'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rake
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -66,7 +80,7 @@ dependencies:
66
80
  - - ">="
67
81
  - !ruby/object:Gem::Version
68
82
  version: '0'
69
- description: Detect language of given text
83
+ description:
70
84
  email:
71
85
  - me@patrick-helm.de
72
86
  executables: []
@@ -166,7 +180,7 @@ files:
166
180
  - wordlists/10k/10000-yo.pstore
167
181
  - wordlists/10k/10000-zh.pstore
168
182
  - wordlists/10k/10000-zu.pstore
169
- homepage: http://gitlab.patrick-helm.de/Ruby/that-language
183
+ homepage: https://github.com/Deradon/that_language
170
184
  licenses:
171
185
  - MIT
172
186
  metadata: {}