From e589b0c2c0437650d14d1fa1ceb82995532642f1 Mon Sep 17 00:00:00 2001 From: songqingqing <18520276036@163.com> Date: Tue, 11 Feb 2025 09:47:28 +0800 Subject: [PATCH] =?UTF-8?q?Simplify=E5=8C=85=EF=BC=9Afix=20[interferon=20b?= =?UTF-8?q?eta-1a]=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- simplify/words.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/simplify/words.go b/simplify/words.go index 9cc05e8..9b02535 100644 --- a/simplify/words.go +++ b/simplify/words.go @@ -37,17 +37,19 @@ func (w *Words) Simplify() []string { for _, separator := range separators { str = strings.ReplaceAll(str, separator, " ") } - wide := " " + strings.Join(strings.Fields(str), " ") + " " // 空格开头结尾,便于包含判断 + wide := " " + strings.Join(strings.Fields(str), " ") + " " // 去掉连续空格 且 空格开头结尾,便于包含判断 if strings.TrimSpace(wide) == "" { continue } - wides[keyword] = wide + if _, ok := wides[wide]; !ok { // 优先保留 input内容 + wides[wide] = keyword + } } // 计算重复次数 repetition := make(map[string]int) - for _, wide1 := range wides { - for keyword, wide2 := range wides { + for wide1 := range wides { + for wide2, keyword := range wides { // 首尾空格字符串 包含另一个 首尾空格字符串,则认为重复 if strings.Contains(wide2, wide1) {