Skip to content

Instantly share code, notes, and snippets.

@unobliged
Created May 23, 2012 18:14
Show Gist options
  • Save unobliged/2776784 to your computer and use it in GitHub Desktop.
Save unobliged/2776784 to your computer and use it in GitHub Desktop.
plymlet old dictionary script
if __FILE__ == $0
# TODO Generated stub
end
$KCODE = "U"
filename = 'njs test.U8.TXT'
dictionary = 'cedict_ts.u8'
vocab_list = []
lines = IO.readlines(filename)
lines.each {|line| vocab_list << line.split}
vocab_list.flatten!
vocab_list.collect! {|b| b.chomp(",")}
vocab_list.collect! {|b| b.chomp("?")}
vocab_list.uniq!
matches = []
dict = File.readlines(dictionary)
better_matches = []
search_match = []
vocab_list.each do |word|
puts('-+-+-+-',word)
matches = dict.grep(/#{word}/)
matches.each {|match| better_matches << match if match.split.include?(word)}
better_matches.each do |better_match|
search_match = better_match.split
puts better_match if search_match[0].include?(word) or search_match[1].include?(word)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment