(texts ...string)
| 214 | } |
| 215 | |
| 216 | func extractKeywords(texts ...string) []string { |
| 217 | keywordSet := make(map[string]bool) |
| 218 | |
| 219 | for _, text := range texts { |
| 220 | // Split camelCase and PascalCase |
| 221 | words := splitCamelCase(text) |
| 222 | for _, word := range words { |
| 223 | word = strings.ToLower(word) |
| 224 | if len(word) >= 2 && !isStopWord(word) { |
| 225 | keywordSet[word] = true |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | // Also split by spaces and punctuation |
| 230 | for _, word := range strings.FieldsFunc(text, func(r rune) bool { |
| 231 | return !unicode.IsLetter(r) && !unicode.IsDigit(r) |
| 232 | }) { |
| 233 | word = strings.ToLower(word) |
| 234 | if len(word) >= 2 && !isStopWord(word) { |
| 235 | keywordSet[word] = true |
| 236 | } |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | var result []string |
| 241 | for kw := range keywordSet { |
| 242 | result = append(result, kw) |
| 243 | } |
| 244 | return result |
| 245 | } |
| 246 | |
| 247 | func splitCamelCase(s string) []string { |
| 248 | var words []string |
no test coverage detected