Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 7 additions & 16 deletions lib/logaling/external_glossaries/edict.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

require 'open-uri'
require 'zlib'
require 'stringio'

module Logaling
class Edict < ExternalGlossary
Expand All @@ -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
Expand Down