b31d8d0096
- Added migration to harden task audit tracking by modifying audit_logs and related tables. - Introduced operator_id to several tables for better tracking of actions. - Updated article_templates with new prompt templates for various article types, enhancing content generation. - Created prompt_rules and schedule_tasks tables to manage content generation rules and scheduling. - Added foreign key constraints to articles for better data integrity.
37 lines
689 B
Go
37 lines
689 B
Go
package contentstats
|
||
|
||
import (
|
||
"regexp"
|
||
"strings"
|
||
"unicode"
|
||
)
|
||
|
||
var latinTokenPattern = regexp.MustCompile(`[A-Za-z0-9]+(?:['’-][A-Za-z0-9]+)?`)
|
||
|
||
func CountWords(input string) int {
|
||
input = strings.TrimSpace(input)
|
||
if input == "" {
|
||
return 0
|
||
}
|
||
|
||
var builder strings.Builder
|
||
hanCount := 0
|
||
|
||
for _, r := range input {
|
||
switch {
|
||
case unicode.Is(unicode.Han, r):
|
||
hanCount++
|
||
builder.WriteRune(' ')
|
||
case unicode.IsLetter(r) || unicode.IsDigit(r):
|
||
builder.WriteRune(r)
|
||
case unicode.IsSpace(r):
|
||
builder.WriteRune(' ')
|
||
default:
|
||
builder.WriteRune(' ')
|
||
}
|
||
}
|
||
|
||
latinCount := len(latinTokenPattern.FindAllString(builder.String(), -1))
|
||
return hanCount + latinCount
|
||
}
|