(question: str, response_language: str = "zh")
| 4424 | |
| 4425 | |
| 4426 | def _question_route(question: str, scope: str, resolved_mentions: List[Dict[str, Any]]) -> Tuple[str, str]: |
| 4427 | normalized_scope = str(scope or "all").strip().lower() |
| 4428 | normalized_question = str(question or "").strip().lower() |
| 4429 | if resolved_mentions or "@" in normalized_question: |
| 4430 | return "wiki", "explicit_mention" |
| 4431 | if normalized_scope in {"recent", "profile"}: |
| 4432 | return "wiki", f"scope_{normalized_scope}" |
| 4433 | if any(term in normalized_question for term in _LOCAL_WIKI_TERMS): |
| 4434 | return "wiki", "local_research_context" |
| 4435 | if normalized_question.startswith(_DIRECT_STARTERS): |
| 4436 | return "direct", "general_question" |
| 4437 | return "direct", "no_local_context_signal" |
| 4438 | |
| 4439 | |
| 4440 | def _is_trend_question(question: str) -> bool: |
| 4441 | normalized = str(question or "").strip().lower() |
| 4442 | if not normalized: |
| 4443 | return False |
| 4444 | return any(term in normalized for term in _TREND_QUESTION_TERMS) |
| 4445 | |
| 4446 | |
| 4447 | def _should_pin_recent_papers(question: str, scope: str) -> bool: |
| 4448 | normalized = str(question or "").strip().lower() |
| 4449 | normalized_scope = str(scope or "").strip().lower() |
| 4450 | if not normalized: |
| 4451 | return False |
| 4452 | if normalized_scope == "recent" or _is_trend_question(normalized): |
| 4453 | return True |
| 4454 | has_paper_signal = any(term in normalized for term in _RECENT_PAPER_QUERY_TERMS) |
| 4455 | has_recent_signal = any(term in normalized for term in _RECENT_CONTEXT_QUERY_TERMS) |
| 4456 | return has_paper_signal and has_recent_signal |
| 4457 | |
| 4458 | |
| 4459 | def _comparison_needs_mentions(question: str, resolved_nodes: List[Dict[str, Any]]) -> bool: |
| 4460 | normalized = str(question or "").strip().lower() |
| 4461 | if len(resolved_nodes or []) >= 2: |
| 4462 | return False |
| 4463 | has_deictic_pair = any(term in normalized for term in ("这两篇", "这两个", "上述两篇", "上面两篇")) |
| 4464 | return has_deictic_pair and any(term in normalized for term in _COMPARE_QUERY_TERMS) |
| 4465 | |
| 4466 | |
| 4467 | def _local_paper_query_tokens(question: str) -> List[str]: |
| 4468 | tokens: List[str] = [] |
| 4469 | for token in re.findall(r"[a-zA-Z][a-zA-Z0-9_+-]{1,}", str(question or "").lower()): |
| 4470 | if token not in _LOCAL_PAPER_STOP_TOKENS and token not in tokens: |
| 4471 | tokens.append(token) |
| 4472 | return tokens[:8] |
| 4473 |
no test coverage detected