dict: 连接号处理 (#1194)

This commit is contained in:
Lithium-7
2025-03-08 02:02:59 +08:00
committed by GitHub
parent 22699f5ade
commit de5e5d267d
5 changed files with 29 additions and 21 deletions

View File

@@ -31,18 +31,12 @@ var (
// 初始化特殊词汇列表、需要注音列表、错别字列表、拼音列表
func initCheck() {
// 特殊词汇列表,不进行任何检查
specialWords.Add("狄尔斯–阿尔德反应")
specialWords.Add("特里斯坦–达库尼亚")
specialWords.Add("特里斯坦–达库尼亚群岛")
specialWords.Add("茱莉亚·路易斯-德瑞弗斯")
specialWords.Add("梅赛德斯-奔驰")
specialWords.Add("科科斯(基林)群岛")
specialWords.Add("刚果(金)")
specialWords.Add("刚果(布)")
specialWords.Add("赛博朋克:边缘行者")
specialWords.Add("赛博朋克:边缘跑手")
specialWords.Add("赛博朋克:命运之轮")
specialWords.Add("哈勃–勒梅特定律")
// 需要注音的列表
file1, err := os.Open(需要注音TXT)
@@ -241,9 +235,9 @@ func checkLine(dictPath string, _type int, line string, lineNumber int) {
return
}
// text 不应该有非汉字内容,除了间隔号 ·
// text 不应该有非汉字内容,除了间隔号 · (Middle Dot: U+00B7)和连接号 - (Hyphen-Minus: U+002D)
for _, c := range text {
if string(c) != "·" && !unicode.Is(unicode.Han, c) {
if !unicode.Is(unicode.Han, c) && !strings.ContainsRune("·-", c) {
fmt.Println("❌ text 含有非汉字内容:", line)
break
}
@@ -263,8 +257,9 @@ func checkLine(dictPath string, _type int, line string, lineNumber int) {
if code != "" {
codeCount := len(strings.Split(code, " "))
textCount := utf8.RuneCountInString(text)
if strings.Contains(text, "·") {
if strings.ContainsAny(text, -") {
textCount -= strings.Count(text, "·")
textCount -= strings.Count(text, "-")
}
if strings.HasPrefix(text, "# ") {
textCount -= 2
@@ -292,10 +287,10 @@ func checkLine(dictPath string, _type int, line string, lineNumber int) {
// 检查拼写错误如「赞zan」写成了zna顺便检查是否存在字表中没有注音的字
if dictPath != HanziPath && (_type == 2 || _type == 3) && !hanPinyinFilter.Contains(text) {
// 把汉字和拼音弄成一一对应关系,「拼音:pin yin」→「拼:pin」「音:yin」
textWithoutDian := strings.ReplaceAll(text, "·", "") // 去掉间隔号
textWithoutSpecialChars := strings.NewReplacer("·", "", "-", "").Replace(text) // 去掉间隔号和连接号
pinyins := strings.Split(code, " ")
i := 0
for _, zi := range textWithoutDian {
for _, zi := range textWithoutSpecialChars {
if !contains(hanPinyin[string(zi)], pinyins[i]) {
fmt.Printf("❌ 注音错误 or 字表未包含的汉字及注音: %s - %s.+%s\n", line, string(zi), pinyins[i])
}