Class: HiwaiKaeuta::Mecab::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/hiwai_kaeuta/mecab/node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node) ⇒ Node

Returns a new instance of Node.



9
10
11
12
13
# File 'lib/hiwai_kaeuta/mecab/node.rb', line 9

def initialize(node)
  @features = node.feature.split(',').map { |x| correct_encoding(x) }
  @surface = correct_encoding(node.surface)
  @pos = @features[0]
end

Instance Attribute Details

#featuresObject (readonly)

Returns the value of attribute features.



6
7
8
# File 'lib/hiwai_kaeuta/mecab/node.rb', line 6

def features
  @features
end

#indexObject

Returns the value of attribute index.



7
8
9
# File 'lib/hiwai_kaeuta/mecab/node.rb', line 7

def index
  @index
end

#locationObject

Returns the value of attribute location.



7
8
9
# File 'lib/hiwai_kaeuta/mecab/node.rb', line 7

def location
  @location
end

#posObject (readonly)

Returns the value of attribute pos.



6
7
8
# File 'lib/hiwai_kaeuta/mecab/node.rb', line 6

def pos
  @pos
end

#surfaceObject (readonly)

Returns the value of attribute surface.



6
7
8
# File 'lib/hiwai_kaeuta/mecab/node.rb', line 6

def surface
  @surface
end

Instance Method Details

#is_bos_or_eos?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/hiwai_kaeuta/mecab/node.rb', line 15

def is_bos_or_eos?
  @pos == 'BOS/EOS'
end

#is_noun?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/hiwai_kaeuta/mecab/node.rb', line 19

def is_noun?
  @pos == '名詞'
end

#readingObject



23
24
25
26
27
28
29
30
# File 'lib/hiwai_kaeuta/mecab/node.rb', line 23

def reading
  x = @features[7]
  if x == '*' || x.nil?
    @surface
  else
    x
  end
end