Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Accept-Encoding header to a request for edict #101

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
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