Skip to content

Instantly share code, notes, and snippets.

@rummelonp
Created May 24, 2016 14:06
Show Gist options
  • Save rummelonp/9c03b9562d68f9eb2630752861f26e5d to your computer and use it in GitHub Desktop.
Save rummelonp/9c03b9562d68f9eb2630752861f26e5d to your computer and use it in GitHub Desktop.
module Natto
Node = Struct.new(:surface, :part, :part_sub1, :part_sub2, :part_sub3, :conjugation1, :conjugation2, :original, :read, :pron)
class MeCab
def parse_to_node(text)
nodes = parse(text).split("\n").map(&:strip)
nodes = nodes.map do |node|
next if node == 'EOS'
surface, feature = *node.split("\t")
Node.new(surface, *feature.split(','))
end
nodes.compact
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment