File size: 1,907 Bytes
b0fd935
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
"""
Minimal usage example for hv-split.

    python example.py

Splits eight queries with different ambiguity sources, shows the bundle
structure, and demonstrates answer_each with a mock callback.
"""

from hv_split import HVInterpret


QUERIES = [
    ("lexical", "I need to access the bank"),
    ("referential",
     "She told her that the manager had changed it, and it broke"),
    ("scope", "All that glitters is not gold"),
    ("presuppositional", "Why did the CEO resign last week?"),
    ("framing",
     "in the language of category theory, what is an identity?"),
    ("temporal", "recently, has the function changed?"),
    ("multi-source",
     "why did the current bank say recently that the function she used "
     "in the language of category theory had changed?"),
    ("clean", "compute 2 + 2"),
]


def main() -> None:
    m = HVInterpret()

    print("=" * 78)
    print("Bundle summary")
    print("=" * 78)
    print(f"  {'name':<16} {'ambig':>7}  {'conf':>6}  {'n':>3}  sources")
    print("  " + "-" * 70)
    for name, q in QUERIES:
        b = m.split(q)
        srcs = ", ".join(b.sources) or "(none)"
        print(
            f"  {name:<16} {b.ambiguity_score:>7.3f}  "
            f"{b.confidence:>6.3f}  {b.n_interpretations:>3}  {srcs}"
        )

    print()
    print("=" * 78)
    print("Full bundle: multi-source query")
    print("=" * 78)
    b = m.split(QUERIES[6][1])
    print(m.render(b))

    print("=" * 78)
    print("answer_each with a mock callback")
    print("=" * 78)
    for interp, answer in m.answer_each(
        QUERIES[0][1],
        lambda q, i: f"[would answer as: {i.reading}]",
    ):
        print(f"  prior {interp.prior:.3f}  ->  {answer}")

    print()
    print("=" * 78)
    print("JSON output (presuppositional query)")
    print("=" * 78)
    print(m.render(m.split(QUERIES[3][1]), mode="json"))


if __name__ == "__main__":
    main()