Class: Langue::Japanese::Parser

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/langue/japanese/parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

#null_logger

Constructor Details

#initialize(options = {}) ⇒ Parser

Returns a new instance of Parser.



12
13
14
15
16
# File 'lib/langue/japanese/parser.rb', line 12

def initialize(options = {})
  @mecab_options = options[:mecab_options] || {}
  @logger = options[:logger] || null_logger
  @taggers = {}
end

Instance Attribute Details

#mecab_optionsObject

Returns the value of attribute mecab_options.



18
19
20
# File 'lib/langue/japanese/parser.rb', line 18

def mecab_options
  @mecab_options
end

Instance Method Details

#parse(text) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/langue/japanese/parser.rb', line 20

def parse(text)
  morphemes = Morphemes.new
  node = tagger.parseToNode(text)

  while node
    surface = node.surface.force_encoding('utf-8')

    unless surface.empty?
      feature = node.feature.force_encoding('utf-8')
      morphemes << create_morpheme(surface, feature)
    end

    node = node.next
  end

  morphemes
end