项目作者: NARKOZ

项目描述 :
Language detection library for Ruby
高级语言: Ruby
项目地址: git://github.com/NARKOZ/linguo.git
创建时间: 2012-03-14T01:55:37Z
项目社区:https://github.com/NARKOZ/linguo

开源协议:BSD 2-Clause "Simplified" License

下载


Linguo

Linguo detects the language of a given text using Free Language Detection API.

Build Status

Installation

Install it from rubygems:

  1. gem install linguo

If you’re using Rails, add to your Gemfile:

  1. gem 'linguo'
  2. # gem 'linguo', :git => 'git://github.com/NARKOZ/linguo.git'

and run:

  1. bundle

You can run rails g linguo:config to generate an initializer and set up API key at config/initializers/linguo.rb.

Usage examples

You can use demo API key (demo) to test out any examples below.

There are a few ways to set an API key. You can set default API key globally in Linguo::Config.api_key:

  1. Linguo.api_key = "your_api_key"

or set the environment variable 'LINGUO_API_KEY' and Linguo will use it.

You can also pass it directly:

  1. Linguo.detect("your text to detect", "your_api_key")

Identify text language and get confidence scores using the detect method:

  1. Linguo.detect("こんにちは")

Get a list of languages with confidence greater than 0.3:

  1. Linguo.detect("こんにちは").detections.map {|x| x['language'] if x['confidence'] > 0.3}.compact

Linguo adds lang method to String class:

  1. "こんにちは".lang

It will return an array containing detected languages.

For more information, refer to documentation.

License

Released under the BSD 2-clause license. See LICENSE.txt for details.