Created
November 23, 2010 01:58
-
-
Save ultraist/711109 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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