Class: Opener::Ner
- Inherits:
-
Object
- Object
- Opener::Ner
- Defined in:
- lib/opener/ner.rb,
lib/opener/ner/cli.rb,
lib/opener/ner/server.rb,
lib/opener/ner/version.rb
Overview
Primary NER class that takes care of delegating NER actions to the language specific kernels.
Defined Under Namespace
Constant Summary collapse
- DEFAULT_LANGUAGE =
The default language to use when no custom one is specified.
'en'.freeze
- DEFAULT_OPTIONS =
Hash containing the default options to use.
{ :args => [], :language => DEFAULT_LANGUAGE }.freeze
- VERSION =
'3.0.0'
Instance Attribute Summary collapse
- #options ⇒ Hash readonly
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Ner
constructor
A new instance of Ner.
-
#run(input) ⇒ Array
Processes the input and returns an array containing the output of STDOUT, STDERR and an object containing process information.
Constructor Details
#initialize(options = {}) ⇒ Ner
Returns a new instance of Ner.
44 45 46 |
# File 'lib/opener/ner.rb', line 44 def initialize( = {}) @options = DEFAULT_OPTIONS.merge() end |
Instance Attribute Details
#options ⇒ Hash (readonly)
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/opener/ner.rb', line 16 class Ner attr_reader :options ## # The default language to use when no custom one is specified. # # @return [String] # DEFAULT_LANGUAGE = 'en'.freeze ## # Hash containing the default options to use. # # @return [Hash] # DEFAULT_OPTIONS = { :args => [], :language => DEFAULT_LANGUAGE }.freeze ## # @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. # def initialize( = {}) @options = DEFAULT_OPTIONS.merge() end ## # Processes the input and returns an array containing the output of STDOUT, # STDERR and an object containing process information. # # @param [String] input # @return [Array] # def run(input) language = language_from_kaf(input) || DEFAULT_LANGUAGE args = [:args].dup if language_constant_defined?(language) kernel = language_constant(language).new() else kernel = Ners::Base.new() end return kernel.run(input) end protected ## # Returns `true` if the current language has a dedicated kernel class. # # @return [TrueClass|FalseClass] # def language_constant_defined?(language) return language && Ners.const_defined?(language.upcase) end ## # @return [Class] # def language_constant(language) return Ners.const_get(language.upcase) end ## # @param [String] input # @return [String] # def language_from_kaf(input) reader = Nokogiri::XML::Reader(input) return reader.read.lang end end |
Instance Method Details
#run(input) ⇒ Array
Processes the input and returns an array containing the output of STDOUT, STDERR and an object containing process information.
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/opener/ner.rb', line 55 def run(input) language = language_from_kaf(input) || DEFAULT_LANGUAGE args = [:args].dup if language_constant_defined?(language) kernel = language_constant(language).new() else kernel = Ners::Base.new() end return kernel.run(input) end |