MCPcopy Create free account
hub / github.com/astercloud/aster / Extract

Method Extract

pkg/memory/dialog/extractor.go:90–120  ·  view source on GitHub ↗

Extract 从消息中提取偏好

(message string)

Source from the content-addressed store, hash-verified

88
89// Extract 从消息中提取偏好
90func (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 检查消息是否包含偏好关键词
123func (e *Extractor) HasPreferenceKeyword(message string) bool {

Callers

nothing calls this directly

Calls 2

extractSentenceMethod · 0.95
calculateConfidenceMethod · 0.95

Tested by

no test coverage detected