scoreSections 评分段落
(sections []string, preserveSections []string)
| 268 | |
| 269 | // scoreSections 评分段落 |
| 270 | func (c *EnhancedPromptCompressor) scoreSections(sections []string, preserveSections []string) []ScoredSection { |
| 271 | result := make([]ScoredSection, 0, len(sections)) |
| 272 | |
| 273 | for i, section := range sections { |
| 274 | title := c.extractSectionTitle(section) |
| 275 | mustKeep := c.shouldPreserve(title, preserveSections) |
| 276 | score := c.calculateSectionScore(section, i, len(sections), mustKeep) |
| 277 | |
| 278 | result = append(result, ScoredSection{ |
| 279 | Content: section, |
| 280 | Title: title, |
| 281 | Score: score, |
| 282 | MustKeep: mustKeep, |
| 283 | }) |
| 284 | } |
| 285 | |
| 286 | // 按评分排序(高分在前) |
| 287 | for i := range len(result) - 1 { |
| 288 | for j := i + 1; j < len(result); j++ { |
| 289 | if result[j].Score > result[i].Score { |
| 290 | result[i], result[j] = result[j], result[i] |
| 291 | } |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | return result |
| 296 | } |
| 297 | |
| 298 | // calculateSectionScore 计算段落重要性评分 |
| 299 | func (c *EnhancedPromptCompressor) calculateSectionScore(section string, index, total int, mustKeep bool) float64 { |