scoreSections 评分段落
(sections []string, preserveSections []string)
| 366 | |
| 367 | // scoreSections 评分段落 |
| 368 | func (s *DefaultCompressionService) scoreSections(sections []string, preserveSections []string) []scoredSection { |
| 369 | result := make([]scoredSection, 0, len(sections)) |
| 370 | |
| 371 | for i, section := range sections { |
| 372 | title := s.extractSectionTitle(section) |
| 373 | mustKeep := s.shouldPreserve(title, preserveSections) |
| 374 | score := s.calculateSectionScore(section, i, len(sections), mustKeep) |
| 375 | |
| 376 | result = append(result, scoredSection{ |
| 377 | content: section, |
| 378 | title: title, |
| 379 | score: score, |
| 380 | mustKeep: mustKeep, |
| 381 | }) |
| 382 | } |
| 383 | |
| 384 | // 按评分排序(高分在前) |
| 385 | for i := range len(result) - 1 { |
| 386 | for j := i + 1; j < len(result); j++ { |
| 387 | if result[j].score > result[i].score { |
| 388 | result[i], result[j] = result[j], result[i] |
| 389 | } |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | return result |
| 394 | } |
| 395 | |
| 396 | // calculateSectionScore 计算段落重要性评分 |
| 397 | func (s *DefaultCompressionService) calculateSectionScore(section string, index, total int, mustKeep bool) float64 { |