Extract 从消息中提取偏好
(message string)
| 88 | |
| 89 | // Extract 从消息中提取偏好 |
| 90 | func (e *Extractor) Extract(message string) []*ExtractedPreference { |
| 91 | var preferences []*ExtractedPreference |
| 92 | |
| 93 | for category, keywords := range e.keywords { |
| 94 | for _, keyword := range keywords { |
| 95 | if strings.Contains(message, keyword) { |
| 96 | // 提取包含关键词的句子 |
| 97 | content := e.extractSentence(message, keyword) |
| 98 | if content == "" { |
| 99 | continue |
| 100 | } |
| 101 | |
| 102 | pref := &ExtractedPreference{ |
| 103 | Category: category, |
| 104 | Content: content, |
| 105 | Keywords: []string{keyword}, |
| 106 | Confidence: e.calculateConfidence(message, keyword, category), |
| 107 | Timestamp: time.Now(), |
| 108 | } |
| 109 | |
| 110 | if pref.Confidence >= e.config.MinConfidence { |
| 111 | preferences = append(preferences, pref) |
| 112 | } |
| 113 | |
| 114 | break // 每个类别只提取一次 |
| 115 | } |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | return preferences |
| 120 | } |
| 121 | |
| 122 | // HasPreferenceKeyword 检查消息是否包含偏好关键词 |
| 123 | func (e *Extractor) HasPreferenceKeyword(message string) bool { |
nothing calls this directly
no test coverage detected