Created
October 6, 2018 08:44
-
-
Save takeshy/abb42f8e4ae14a82b1418dbd03c01f06 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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