File size: 1,949 Bytes
0a6fd56
8c534a8
0a6fd56
8c534a8
0a6fd56
eff511c
 
0a6fd56
 
 
 
 
 
eff511c
0a6fd56
 
 
 
eff511c
0a6fd56
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
eff511c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from __future__ import annotations

from typing import Any

from normative_runtime import route_normative_question


def route_question(
    question: str,
    documents: list[dict[str, Any]] | dict[str, dict[str, Any]] | None = None,
    cross_document_edges: list[dict[str, Any]] | None = None,
) -> dict[str, Any]:
    """Route through the semantic addresses compiled from the active corpus.

    ``documents`` and ``cross_document_edges`` remain in the public signature
    for compatibility with retrieval callers.  The authoritative data is the
    immutable package loaded by ``init_normative_runtime``; no law-specific
    Python lexicon or article switch is maintained here.
    """
    route = route_normative_question(question)
    if route.get("document_scores") or not documents:
        return route

    docs = list(documents.values()) if isinstance(documents, dict) else list(documents or [])
    document_ids = [str(item.get("document_id", "")) for item in docs if item.get("document_id")]
    return {
        "candidate_document_ids": document_ids,
        "document_scores": {document_id: 0.0 for document_id in document_ids},
        "top_document_id": "",
        "top_score": 0.0,
        "runner_up_score": 0.0,
        "scope_confident": False,
        "cross_document": False,
        "candidate_edge_ids": [],
        "candidate_edges": [],
        "target_articles_by_document": {},
        "reasons": {document_id: [] for document_id in document_ids},
    }


def score_document_domain(question: str, document: dict[str, Any]) -> float:
    route = route_question(question, [document], [])
    return float(route.get("document_scores", {}).get(document.get("document_id", ""), 0.0))


def _target_articles(question: str) -> dict[str, list[str]]:
    """Compatibility facade for diagnostics; targets are corpus-derived."""
    return dict(route_normative_question(question).get("target_articles_by_document", {}) or {})