class Opener::POSTagger
Primary POS tagger class that delegates work the various POS tagging kernels.
@!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.
# File lib/opener/pos_tagger.rb, line 39 def initialize(options = {}) @options = DEFAULT_OPTIONS.merge(options) end
Public Instance Methods
language_from_kaf(input)
click to toggle source
Extracts the language from a KAF document, returns `nil` if no language was found.
@param [String] input @return [String]
# File lib/opener/pos_tagger.rb, line 71 def language_from_kaf(input) document = Nokogiri::XML(input) language = document.xpath('KAF/@xml:lang')[0] return language ? language.to_s : nil end
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 input to process. @return [Array]
# File lib/opener/pos_tagger.rb, line 50 def run input, params = {} language = language_from_kaf(input) if !language or !valid_language?(language) raise Core::UnsupportedLanguageError, language end kernel = language_constant(language).new(:args => options[:args]) return kernel.run(input) end
Also aliased as: tag
Private Instance Methods
language_constant(language)
click to toggle source
@param [String] language @return [Class]
# File lib/opener/pos_tagger.rb, line 84 def language_constant(language) return language && POSTaggers.const_get(language.upcase) end
valid_language?(language)
click to toggle source
@return [TrueClass|FalseClass]
# File lib/opener/pos_tagger.rb, line 91 def valid_language?(language) return Opener::POSTaggers.const_defined?(language.upcase) end