提取章节内容
(text: str)
| 515 | |
| 516 | |
| 517 | def extract_sections(text: str) -> Dict[str, str]: |
| 518 | """提取章节内容""" |
| 519 | sections = {} |
| 520 | |
| 521 | for section_name, pattern in SECTION_PATTERNS.items(): |
| 522 | match = re.search(pattern, text, re.IGNORECASE) |
| 523 | if match: |
| 524 | start = match.end() |
| 525 | next_section = None |
| 526 | for other_name, other_pattern in SECTION_PATTERNS.items(): |
| 527 | if other_name != section_name: |
| 528 | other_match = re.search(other_pattern, text[start:], re.IGNORECASE) |
| 529 | if other_match: |
| 530 | if next_section is None or other_match.start() < next_section: |
| 531 | next_section = other_match.start() |
| 532 | |
| 533 | if next_section: |
| 534 | sections[section_name] = text[start:start + next_section].strip() |
| 535 | else: |
| 536 | sections[section_name] = text[start:].strip() |
| 537 | |
| 538 | return sections |
| 539 | |
| 540 | |
| 541 | def score_direction_confidence(match_count: int, keyword_count: int) -> float: |