Skip to content

Instantly share code, notes, and snippets.

@takeshy
Created October 6, 2018 08:44
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save takeshy/abb42f8e4ae14a82b1418dbd03c01f06 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'nkf'
raw = File.read("#{ENV['HOME']}/Downloads/EIJIRO-1445.TXT")
data = NKF.nkf("-w -d", raw)
results = {}
first_flg = false
data.each_line do |raw_line|
next if !first_flg && !raw_line.match(/a\s+{不-1}/)
first_flg = true
line = raw_line.sub(/^[^-0-9a-zA-Z_]+/,"")
next unless line.match(/^[A-Za-z]/)
next if line.match(/〈英〉/)
if line.match(/^[^:]+{/)
match = line.match(/(^[^:]+)\s+({.*)$/)
else
match = line.match(/(^[^:]+)\s+:\s+(.*)$/)
end
next unless match
spell = match[1].sub(/\s+$/,"")
next unless spell.match(/^[A-Za-z]+$/)
signification = match[2]
next if signification.match(/=/)
results[spell] ||= []
results[spell].push(signification)
end
File.open("#{ENV['HOME']}/gene.txt","w") do|f|
results.each do |k,v|
f.puts(k)
f.puts(v.join("\n"))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment