class Opener::LanguageIdentifier

Language identifier class that can detect various languages such as Dutch, German and Swedish.

@!attribute [r] options

@return [Hash]

Constants

DEFAULT_OPTIONS

Hash containing the default options to use.

@return [Hash]

VERSION

Attributes

options[R]

Public Class Methods

new(options = {}) click to toggle source

@param [Hash] options

@option options [Array] :args Arbitrary arguments to pass to the

underlying kernel.

@option options [TrueClass|FalseClass] :kaf When set to `true` the

results will be displayed as KAF.
# File lib/opener/language_identifier.rb, line 48
def initialize(options = {})
  @options  = DEFAULT_OPTIONS.merge(options)
  @detector = Detector.new ENV['BACKEND'], ENV['FALLBACK']
end

Public Instance Methods

identify(input, params = {})
Alias for: run
run(input, params = {}) click to toggle source

Processes the input and returns an Array containing the output of STDOUT, STDERR and an object containing process information.

@param [String] input The text of which to detect the language. @return [Array]

# File lib/opener/language_identifier.rb, line 60
def run input, params = {}
  output = @detector.detect input
  output = build_kaf input, output if options[:kaf]

  return output
end
Also aliased as: identify

Protected Instance Methods

build_kaf(input, language) click to toggle source

Builds a KAF document containing the input and the correct XML language tag based on the output of the kernel.

@param [String] input The input text. @param [String] language The detected language @return [String]

# File lib/opener/language_identifier.rb, line 79
def build_kaf(input, language)
  builder = KafBuilder.new(input, language)
  builder.build

  return builder.to_s
end