https://github.com/vhyza/language_detection
Ruby bindings for Chromium Compact Language Detector
https://github.com/vhyza/language_detection
language-detection ruby-bindings
Last synced: 11 months ago
JSON representation
Ruby bindings for Chromium Compact Language Detector
- Host: GitHub
- URL: https://github.com/vhyza/language_detection
- Owner: vhyza
- License: mit
- Created: 2012-09-27T19:58:58.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2023-03-15T16:19:17.000Z (about 3 years ago)
- Last Synced: 2025-05-06T05:56:11.838Z (11 months ago)
- Topics: language-detection, ruby-bindings
- Language: C++
- Homepage: https://github.com/vhyza/language_detection
- Size: 2.92 MB
- Stars: 20
- Watchers: 3
- Forks: 7
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# LanguageDetection
Ruby bindings for Chromium Compact Language Detector ([source](http://src.chromium.org/viewvc/chrome/trunk/src/third_party/cld/)). This gem is using source codes from [chromium-compact-language-detector](http://code.google.com/p/chromium-compact-language-detector/) port.
## Installation
Add this line to your application's Gemfile:
gem 'language_detection'
And then execute:
$ bundle
Or install it yourself as:
$ gem install language_detection
## Usage
```ruby
>> require 'language_detection'
=> true
>> language = LanguageDetection.perform("This is some example text for language detection")
=> #]>
>> language.name
=> "english"
>> language.code
=> "en"
>> language.reliable
=> true
>> language.details # contains up to 3 languages sorted by score
=> [#]
>> language.details.first.percent
=> 100
>> language.details.first.score
=> 49.43273905996759
```
the other way is to include `LanguageDetection` module in your class
```ruby
class Article
include LanguageDetection
attr_accessor :title, :content
def initialize(params = {})
@title = params[:title]
@content = params[:content]
end
def to_s
"#{title}\n#{content}"
end
end
```
which provides `Article#language` method using `Article#to_s` method as parameter
```ruby
>> article = Article.new :title => "Web development that doesn't hurt", :content => "Tens of thousands of Rails applications are already live..."
>> article.language
=> #]>
```
or you can add `String#language` method by `require 'language_detection/string'`
```ruby
>> require 'language_detection'
=> true
>> require 'language_detection/string'
=> true
>> "Web development that doesn't hurt".language
=> #]>
```
## Contributing
1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request