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

Method scoreSections

pkg/compression/service.go:368–394  ·  view source on GitHub ↗

scoreSections 评分段落

(sections []string, preserveSections []string)

Source from the content-addressed store, hash-verified

366
367// scoreSections 评分段落
368func (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 计算段落重要性评分
397func (s *DefaultCompressionService) calculateSectionScore(section string, index, total int, mustKeep bool) float64 {

Callers 2

TestSectionScoringFunction · 0.95

Calls 3

extractSectionTitleMethod · 0.95
shouldPreserveMethod · 0.95
calculateSectionScoreMethod · 0.95

Tested by 1

TestSectionScoringFunction · 0.76