Last active
December 27, 2016 12:00
-
-
Save naoyashiga/a793b2fd72f3881c9c5b0827b8fdf14a 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 "ikku" | |
reviewer = Ikku::Reviewer.new | |
sourceTextFileName = '../data/wiki.txt' | |
outputTextFileName = 'math.txt' | |
outputTextFile = File.open(outputTextFileName,'w') | |
begin | |
File.open(sourceTextFileName) do |file| | |
file.each_line do |line| | |
ikkus = reviewer.search(line) | |
for ikku in ikkus do | |
for ku in ikku.phrases do | |
for word in ku do | |
outputTextFile.print word | |
end | |
outputTextFile.print " " | |
end | |
outputTextFile.print "\n" | |
end | |
end | |
end | |
# 例外は小さい単位で捕捉する | |
rescue SystemCallError => e | |
puts %Q(class=[#{e.class}] message=[#{e.message}]) | |
rescue IOError => e | |
puts %Q(class=[#{e.class}] message=[#{e.message}]) | |
end | |
outputTextFile.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment