Add KANAKANCOST

This commit is contained in:
Nishi 2026-06-21 08:00:28 +09:00
commit a6a7858eaf
20 changed files with 58916 additions and 59081 deletions

5
tools/format.sh Executable file
View file

@ -0,0 +1,5 @@
#!/bin/sh
while [ ! -d .git ]; do
cd ..
done
clang-format --verbose -i `find src lib include "(" -name "*.c" -or -name "*.h" ")" -and -not -name ucstable.h`

71
tools/win32.sh Executable file
View file

@ -0,0 +1,71 @@
#!/bin/sh
cmp="$1"
if [ "x$cmp" = "x" ]; then
echo "Usage: $0 [watcom|msvc]"
exit 1
fi
if [ "$cmp" = "watcom" ]; then
:
elif [ "$cmp" = "msvc" ]; then
:
else
echo "Invalid target"
exit 1
fi
library() {
N=$1
for i in lib/$N/*.c; do
if [ -f $i.obj ]; then
continue
fi
echo $i
if [ "$cmp" = "watcom" ]; then
owcc -Iinclude/sj4common -Iinclude/sj4compat -Iinclude/$N -bnt -c -o $i.obj $i || exit 1
elif [ "$cmp" = "msvc" ]; then
cl.exe /nologo /Iinclude/sj4common /Iinclude/sj4compat /Iinclude/$N /c /Fo$i.obj $i || exit 1
fi
done
if [ "$cmp" = "watcom" ]; then
find lib/$N -name "*.obj" | while read a; do
echo "+$a"
done | xargs wlib -q -b -fo -n $N.lib
elif [ "$cmp" = "msvc" ]; then
lib.exe /nologo /out:$N.lib lib/$N/*.obj
fi
}
executable() {
N=$1
for i in src/$N/*.c; do
if [ -f $i.obj ]; then
continue
fi
echo $i
if [ "$cmp" = "watcom" ]; then
owcc -DUTF8 -DENGLISH -Iinclude/sj4common -Iinclude/sj4core -bnt -c -o $i.obj $i || exit 1
elif [ "$cmp" = "msvc" ]; then
cl.exe /nologo /DUTF8 /DENGLISH /Iinclude/sj4common /Iinclude/sj4core /c /Fo$i.obj $i || exit 1
fi
done
if [ "$cmp" = "watcom" ]; then
owcc -bnt -o $N.exe src/$N/*.obj $2
elif [ "$cmp" = "msvc" ]; then
cl.exe /nologo /Fe$N.exe src/$N/*.obj /link $2
fi
}
library sj4common
library sj4core
library sj4rkcv
executable sj4mkdic
executable sj4test "sj4common.lib sj4core.lib"

166
tools/wnn2sj4.py Executable file
View file

@ -0,0 +1,166 @@
#!/usr/bin/env python3
# THIS IS FOR SYSTEM DICTIONARY GENERATION!!!!!
import sys
import re
from math import *
from collections import defaultdict
HINSHI = {
"名詞": "名1",
"固有名詞": "名1",
"単漢字": "名1",
"人名": "名前",
"地名": "地名",
"人名&地名": "地名",
"数詞": "数詞",
"助数詞": "助数",
"サ行(する)&名詞": "名6",
"形容動詞": "形動1",
"形容動詞&名詞": "形動1",
"形容動詞(たる)": "形動1",
"形容詞": "形1",
"副詞": "副1",
"連体詞": "連体",
"接続詞,感動詞": "接続",
"一段": "一段1",
"一段&名詞": "一段1",
"カ行五段": "カ五1",
"ガ行五段": "ガ五1",
"サ行五段": "サ五1",
"タ行五段": "タ五1",
"ナ行五段": "ナ五",
"バ行五段": "バ五1",
"マ行五段": "マ五1",
"ラ行五段": "ラ五1",
"ワ行五段": "ワ五1",
"サ行(する)": "サ変",
"ザ行(ずる)": "ザ変",
"ラ行(下さい)": "ラ五1",
"カ行(行く)": "カ五1",
"接頭語": "接頭1",
"接頭語(お)": "接頭1",
"接頭語(各)": "接頭1",
"接頭助数詞": "接頭4",
"接頭数詞": "接頭4",
"接頭地名": "接頭3",
"接尾語": "接尾1",
"接尾人名": "接尾1",
"接尾地名": "接尾4",
"接尾助数詞": "助数",
"接尾動詞": "接尾5",
"形容動詞化接尾語": "接尾6",
"サ行(する)&名詞化接尾語": "接尾7",
"形容詞化接尾動詞": "接尾5",
"一動幹": "一段1"
}
SKIP = {
"記号",
"開括弧",
"閉括弧",
"来(こ)",
"来(く)",
"来(き)",
"為(せ)",
"為(し)",
"為(す)"
}
def p_freq(fields):
if len(fields) < 4:
return 0
return int(fields[-1])
if len(sys.argv) != 3:
print("usage: wnn2sj4.py input.u output.dic", file=sys.stderr)
sys.exit(1)
inp = sys.argv[1]
outp = sys.argv[2]
entries = {}
fp = open(inp, "r", encoding="euc_jp")
for lineno, line in enumerate(fp, 1):
line = line.rstrip()
if not(line):
continue
fields = line.split()
if len(fields) < 3:
continue
y = fields[0]
k = fields[1]
h = fields[2]
if h in SKIP:
continue
if re.findall(r'[^あ-んー]', y):
continue
sj = HINSHI[h]
if sj is None:
sys.stderr.write(f"{lineno}: unknown hinshi: {h}\n")
sj = "名1"
freq = p_freq(fields)
key = (y, k, sj)
old = entries.get(key)
if old is None or freq > old:
entries[key] = freq
fp.close()
grouped = defaultdict(list)
maxf = 0
for (y, k, sj), freq in entries.items():
if maxf < freq:
maxf = freq
grouped[y].append((freq, k, sj, freq))
fp = open(outp, "w", encoding="utf-8")
for y in sorted(grouped.keys()):
lst = grouped[y]
lst.sort(key=lambda x: (-x[0], x[1]))
t = "\t" * (4 - (len(y) // 4))
for freq, k, sj, freq in lst:
t2 = "\t" * (4 - (len(k) // 4))
freq = floor(freq / maxf * 0xffff)
fp.write(f"{y}{t}{k}{t2}{sj}:[C{freq}]:\n")
fp.close()