Class: Opener::ConstituentParser
- Inherits:
-
Object
- Object
- Opener::ConstituentParser
- Defined in:
- lib/opener/constituent_parser.rb,
lib/opener/constituent_parser/cli.rb,
lib/opener/constituent_parser/server.rb,
lib/opener/constituent_parser/version.rb
Overview
Constituent parser for various languages such as English and German.
Defined Under Namespace
Constant Summary collapse
- DEFAULT_OPTIONS =
Hash containing the default options to use.
{ :args => [], }.freeze
- VERSION =
'2.0.1'
Instance Attribute Summary collapse
- #options ⇒ Hash readonly
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ ConstituentParser
constructor
A new instance of ConstituentParser.
-
#run(input) ⇒ String
Processes the input KAF document and returns a new KAF document as a String.
Constructor Details
#initialize(options = {}) ⇒ ConstituentParser
Returns a new instance of ConstituentParser.
34 35 36 |
# File 'lib/opener/constituent_parser.rb', line 34 def initialize( = {}) @options = DEFAULT_OPTIONS.merge() end |
Instance Attribute Details
#options ⇒ Hash (readonly)
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 |
# File 'lib/opener/constituent_parser.rb', line 18 class ConstituentParser attr_reader :options ## # Hash containing the default options to use. # # @return [Hash] # DEFAULT_OPTIONS = { :args => [], }.freeze ## # @param [Hash] options # @see Opener::ConstituentParsers::Base#initialize # def initialize( = {}) @options = DEFAULT_OPTIONS.merge() end ## # Processes the input KAF document and returns a new KAF document as a # String. # # @param [String] input # @return [String] # def run(input) args = [:args].dup language = language(input) if language_constant_defined?(language) kernel = language_constant(language).new(:args => args) else kernel = ConstituentParsers::Base.new( :args => args, :language => language ) 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 ConstituentParsers.const_defined?(language.upcase) end ## # @return [Class] # def language_constant(language) return ConstituentParsers.const_get(language.upcase) end ## # @return the language from the KAF # def language(input) document = Nokogiri::XML(input) language = document.at('KAF').attr('xml:lang') return language end end |
Instance Method Details
#run(input) ⇒ String
Processes the input KAF document and returns a new KAF document as a String.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/opener/constituent_parser.rb', line 45 def run(input) args = [:args].dup language = language(input) if language_constant_defined?(language) kernel = language_constant(language).new(:args => args) else kernel = ConstituentParsers::Base.new( :args => args, :language => language ) end return kernel.run(input) end |