diff --git a/lib/logaling/external_glossaries/edict.rb b/lib/logaling/external_glossaries/edict.rb index a269679..2f4b336 100644 --- a/lib/logaling/external_glossaries/edict.rb +++ b/lib/logaling/external_glossaries/edict.rb @@ -14,8 +14,6 @@ # along with this program. If not, see . require 'open-uri' -require 'zlib' -require 'stringio' module Logaling class Edict < ExternalGlossary @@ -29,20 +27,13 @@ class Edict < ExternalGlossary def convert_to_csv(csv) puts "downloading edict file..." url = 'http://ftp.monash.edu.au/pub/nihongo/edict.gz' - Zlib::GzipReader.open(open(url)) do |gz| - puts "importing edict file..." - - lines = StringIO.new(gz.read).each_line - - lines.next # skip header - - preprocessed_lines = lines.map do |line| - line.encode("UTF-8", "EUC-JP").chomp - end - - preprocessed_lines.each do |line| - source, target = line.split('/', 2) - source = source.strip + open(url) do |edict| + edict.gets # skip header + edict.each_line do |raw_line| + line = raw_line.encode("UTF-8", "EUC-JP").chomp + target, source = line.split('/', 2) + source.strip! + target.strip! csv << [source, target] end end