-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmk-char-map
More file actions
executable file
·42 lines (36 loc) · 933 Bytes
/
mk-char-map
File metadata and controls
executable file
·42 lines (36 loc) · 933 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/env ruby
# Use the main dict first
# since I may change the breakdown of some chars
main_dict_path = "./092wubi.dict.yaml"
ext_char_dict_path = "./092wubi_U.dict.yaml"
map = {}
# @type [Array<String>]
lines = [
File.open(main_dict_path).readlines(chomp: true).drop_while { |x| x != '...' }.drop(1),
File.open(ext_char_dict_path).readlines(chomp: true).drop_while { |x| x != '...' }.drop(1)
].flatten
lines.each do |line|
split = line.split("\t")
next unless split.length == 2
word = split[0]
next unless word.length == 1
next unless split[1].length >= 2
code = split[1][0..1]
if map[word] == nil
map[word] = code
else
# 有兼容码的字,不放入
if map[word] != code
map.delete word
end
end
end
('A'..'Z').each do |c|
map[c] = "#{c.downcase}z"
end
('a'..'z').each do |c|
map[c] = "#{c}z"
end
map.sort_by { |x| x[0] }.each do |pair|
puts "#{pair[0]} #{pair[1]}"
end