Class: Kampyo::Mecab

Inherits:
Text
  • Object
show all
Defined in:
lib/kampyo/mecab.rb

Overview

Text

Instance Method Summary collapse

Methods inherited from Text

#ext_reading, #initialize

Constructor Details

This class inherits a constructor from Kampyo::Text

Instance Method Details

#parser(input) ⇒ Object

rubocop:todo Metrics/MethodLength



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/kampyo/mecab.rb', line 13

def parser(input) # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
  result = []
  parser = MeCab::Tagger.new
  node = parser.parseToNode(input)
  while node
    features = node.feature.split(',')
    if features[0] != 'BOS/EOS'
      result << {
        id: result.size + 1,
        chunk: 0,
        surface: node.surface,
        feature1: features[0],
        feature2: features[1],
        baseform: features[6],
        reading: features[7],
        ext_reading: ext_reading(features[7]),
        cost: node.cost,
        wcost: node.wcost,
        right_context: node.rcAttr,
        left_context: node.lcAttr
      }
    end
    node = node.next
  end

  result
end