class Opener::Ner

Primary NER class that takes care of delegating NER actions to the language specific kernels.

@!attribute [r] options

@return [Hash]

Constants

DEFAULT_LANGUAGE

The default language to use when no custom one is specified.

@return [String]

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 Collection of arbitrary arguments to pass

to the underlying kernels.

@option options [String] :language The language to use.

# File lib/opener/ner.rb, line 44
def initialize(options = {})
  @options = DEFAULT_OPTIONS.merge(options)
end

Public Instance Methods

run(input) 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 @return [Array]

# File lib/opener/ner.rb, line 55
def run(input)
  language = language_from_kaf(input) || DEFAULT_LANGUAGE
  args     = options[:args].dup

  if language_constant_defined?(language)
    kernel = language_constant(language).new(options)
  else
    kernel = Ners::Base.new(options)
  end

  return kernel.run(input)
end

Protected Instance Methods

language_constant(language) click to toggle source

@return [Class]

# File lib/opener/ner.rb, line 82
def language_constant(language)
  return Ners.const_get(language.upcase)
end
language_constant_defined?(language) click to toggle source

Returns ‘true` if the current language has a dedicated kernel class.

@return [TrueClass|FalseClass]

# File lib/opener/ner.rb, line 75
def language_constant_defined?(language)
  return language && Ners.const_defined?(language.upcase)
end
language_from_kaf(input) click to toggle source

@param [String] input @return [String]

# File lib/opener/ner.rb, line 90
def language_from_kaf(input)
  reader = Nokogiri::XML::Reader(input)

  return reader.read.lang
end