countDistinctVerbs counts unique action verbs in lower (already lower-cased), up to cap. Word boundaries are enforced via Fields, which keeps the scorer simple and Unicode-safe.
(lower string, limit int)
| 125 | // lower-cased), up to cap. Word boundaries are enforced via Fields, |
| 126 | // which keeps the scorer simple and Unicode-safe. |
| 127 | func countDistinctVerbs(lower string, limit int) int { |
| 128 | seen := make(map[string]struct{}) |
| 129 | for _, raw := range strings.Fields(lower) { |
| 130 | w := strings.Trim(raw, ".,;:!?()[]{}\"'`") |
| 131 | if _, ok := actionVerbs[w]; ok { |
| 132 | seen[w] = struct{}{} |
| 133 | if len(seen) >= limit { |
| 134 | return limit |
| 135 | } |
| 136 | } |
| 137 | } |
| 138 | return len(seen) |
| 139 | } |
| 140 | |
| 141 | // countDistinctMatches dedupes a slice and returns count up to limit. |
| 142 | func countDistinctMatches(matches []string, limit int) int { |