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) {