Skip to content

Instantly share code, notes, and snippets.

@naoyashiga
Last active Dec 27, 2016
Embed
What would you like to do?
一句(五七五)を抽出してテキストに書き出す
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