Skip to content

Instantly share code, notes, and snippets.

@ultraist
Created November 23, 2010 01:58
Show Gist options
  • Save ultraist/711109 to your computer and use it in GitHub Desktop.
Save ultraist/711109 to your computer and use it in GitHub Desktop.
require 'CaboCha'
sentence = "太郎はこの本を二郎を見た女性に渡した。"
c = CaboCha::Parser.new;
tree = c.parse(sentence)
chunks = []
(0 ... tree.chunk_size).each do |i|
chunk = tree.chunk(i)
token = ""
(0 ... chunk.token_size).each do |j|
token << tree.token(chunk.token_pos + j).surface
end
chunks << token
end
(0 ... tree.chunk_size).each do |i|
chunk = tree.chunk(i)
if (chunk.link >= 0)
puts "#{chunks[i]} => #{chunks[chunk.link]}"
end
end
=begin
太郎は => 渡した。
この => 本を
本を => 見た
二郎を => 見た
見た => 女性に
女性に => 渡した。
=end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment