|
|
@ -1,7 +1,6 @@ |
|
|
|
package simplify |
|
|
|
package simplify |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
"slices" |
|
|
|
|
|
|
|
"strings" |
|
|
|
"strings" |
|
|
|
"unicode" |
|
|
|
"unicode" |
|
|
|
) |
|
|
|
) |
|
|
@ -70,7 +69,7 @@ func (w *Words) Simplify() []string { |
|
|
|
filteredWhole := make([]string, 0) |
|
|
|
filteredWhole := make([]string, 0) |
|
|
|
for keyword, times := range repetition { |
|
|
|
for keyword, times := range repetition { |
|
|
|
if times == 1 { |
|
|
|
if times == 1 { |
|
|
|
if slices.Contains(w.input, keyword) { |
|
|
|
if w.contains(w.input, keyword) { |
|
|
|
filteredInput = append(filteredInput, keyword) |
|
|
|
filteredInput = append(filteredInput, keyword) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
filteredWhole = append(filteredWhole, keyword) |
|
|
|
filteredWhole = append(filteredWhole, keyword) |
|
|
@ -84,6 +83,15 @@ func (w *Words) Simplify() []string { |
|
|
|
return result |
|
|
|
return result |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (w *Words) contains(arr []string, str string) bool { |
|
|
|
|
|
|
|
for _, v := range arr { |
|
|
|
|
|
|
|
if v == str { |
|
|
|
|
|
|
|
return true |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return false |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// isChineseOrSpace 判断给定的rune字符是否为中文或空格
|
|
|
|
// isChineseOrSpace 判断给定的rune字符是否为中文或空格
|
|
|
|
func (w *Words) isChineseOrSpace(r rune) bool { |
|
|
|
func (w *Words) isChineseOrSpace(r rune) bool { |
|
|
|
return r == ' ' || unicode.Is(unicode.Scripts["Han"], r) |
|
|
|
return r == ' ' || unicode.Is(unicode.Scripts["Han"], r) |
|
|
|