Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/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
You can’t perform that action at this time.