In Files

Parent

Class Index [+]

Quicksearch

CLD::Detector

Detect the language of a given string of text

Public Class Methods

new() click to toggle source

Initialize and allocate a copy of the native C++ library

    # File lib/CLD.rb, line 45
45:     def initialize
46:       @native = CLDNative.new
47:     end

Public Instance Methods

detect_language(text, options = {}, &block) click to toggle source

Detect the language of text using the provided options (see below). For example:

   detector = CLD::Detector.new
   result = detector.detect_language("I'm a little teapot.")
   puts result.probable_language.code
   #=> 'en'

Or, you can pass a block which will be called with the result object:

   detector = CLD::Detector.new
   detector.detect_language("I'm a little teapot.") do |result|
     puts result.probable_language.code
     #=> 'en'
   end
   

The options can include:

  • :html if the text contains HTML that should be ignored

  • :all_languages test language outside of the core set (quality if not as good)

  • :weak_matches include weak matches in the results

    # File lib/CLD.rb, line 69
69:     def detect_language(text, options = {}, &block)
70:       return nil if text == nil
71:       return nil if text =~ /^\s*$/
72: 
73:       if block_given?
74:         yield @native.detect_language(text, options)
75:       else
76:         @native.detect_language(text, options)
77:       end
78:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.