| 123456789101112131415161718 |
- from __future__ import annotations
- import re
- _RELATIONSHIP_MARKERS = ("上游", "下游", "依赖", "关联", "经过", "血缘")
- _GLOBAL_MARKERS = ("整体", "主要主题", "跨域", "总结")
- _EXACT_PATTERN = re.compile(r"[\"'“”‘’`]|\b[a-zA-Z][a-zA-Z0-9_.$-]{2,}\b")
- def route_query(query: str) -> str:
- normalized = query.strip()
- if any(marker in normalized for marker in _RELATIONSHIP_MARKERS):
- return "relationship"
- if any(marker in normalized for marker in _GLOBAL_MARKERS):
- return "global"
- if _EXACT_PATTERN.search(normalized):
- return "exact"
- return "semantic"
|