class MecabNode

This class define Node struct Nameko::Mecab#parse method return it.

Public Instance Methods

feature() click to toggle source
# File lib/nameko/node.rb, line 27
def feature
  feature = self[:feature].force_encoding(Encoding.default_external).match(/
    ^
    (?:
      (?<pos>[^,]+),
      \*?(?<pos1>[^,]*),
      \*?(?<pos2>[^,]*),
      \*?(?<pos3>[^,]*),
      \*?(?<conjugation_form>[^,]*),
      \*?(?<conjugation>[^,]*),
      (?<base>[^,]*)
      (?:
        ,(?<yomi>[^,]*)
        ,(?<pronunciation>[^,]*)
      )?
    )?
    /x) do |md|
    md.named_captures.map{ |k, v| [k.to_sym, v] }.to_h
  end

  fill_up(feature)
end
next() click to toggle source
# File lib/nameko/node.rb, line 50
def next
  MecabNode.new self[:next]
end
surface() click to toggle source
# File lib/nameko/node.rb, line 54
def surface
  self[:surface][0...self[:length]].force_encoding(Encoding.default_external)
end

Private Instance Methods

fill_up(analysis) click to toggle source
# File lib/nameko/node.rb, line 60
def fill_up(analysis)
  if !analysis[:yomi] && surface.match(/\p{katakana}+/)
    analysis[:yomi] = surface
    analysis[:pronunciation] = surface
  end
  analysis
end
method_missing(key) click to toggle source
# File lib/nameko/node.rb, line 78
def method_missing(key)
  self[key]
end
to_ary() click to toggle source
# File lib/nameko/node.rb, line 72
def to_ary
  [self[:surface]]
end
to_s() click to toggle source
# File lib/nameko/node.rb, line 68
def to_s
  self[:surface]
end