This repository was archived by the owner on Sep 12, 2025. It is now read-only.
forked from amazingfate/tes3-chinese-translation
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwords.lua
More file actions
86 lines (77 loc) · 1.52 KB
/
words.lua
File metadata and controls
86 lines (77 loc) · 1.52 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
local function extWords()
local t = {}
local i = 0
for line in io.lines "ecdict.csv" do -- https://github.com/skywind3000/ECDICT
i = i + 1
local words = line:match '^"(.-)",'
if not words then
words = line:match "^(.-),"
end
if not words then
error("1: " .. i)
end
if not words:find "^[%w%-+*/&$%%!?~_\"';:.,()%[%] ]+$" then
error("2: " .. i)
end
for word in words:gmatch "%a+" do
if #word > 1 then
t[word] = true
end
end
end
local tt = {}
for word in pairs(t) do
tt[#tt + 1] = word
end
table.sort(tt)
local f = io.open("words.txt", "wb")
for _, word in ipairs(tt) do
f:write(word, "\n")
end
f:close()
print "done!"
end
local function calcWords()
local words = {}
for word in io.lines "words.txt" do
if word:find "^%a%l+$" then
words[word:lower()] = true
end
end
local files = {
"tes3cn_Morrowind.ext.txt",
"tes3cn_Tribunal.ext.txt",
"tes3cn_Bloodmoon.ext.txt",
}
local t = {}
for _, file in ipairs(files) do
for line in io.lines(file) do
if not line:find "^> " then
for word in line:gmatch "%a%l+" do
word = word:lower()
if not words[word] then
t[word] = (t[word] or 0) + 1
end
end
end
end
end
local tt = {}
for word in pairs(t) do
tt[#tt + 1] = word
end
table.sort(tt, function(a, b)
if t[a] ~= t[b] then
return t[a] > t[b]
end
return a < b
end)
local f = io.open("words1.txt", "wb")
for _, word in ipairs(tt) do
f:write(word, "\t", t[word], "\n")
end
f:close()
print "done!"
end
-- extWords()
calcWords()