SPB Git

spb/wp44_uqo

Public
2.2 KB · 37 lines python
1import os, sys, tempfile, yaml2sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))3from taxonomy import classify45ONT = {"version": "test", "assignment_rule": {"threshold": 1.0},6       "categories": [7           {"id": "llm", "number": 1, "name": "LLM", "child_of": "foundation_models", "openalex_topics": [{"id": "T10028", "weight": 0.6}],8            "keywords": [{"pattern": r"(?i)\blarge language models?\b", "weight": 1.0, "field": "both"}], "arxiv_categories": [{"id": "cs.CL", "weight": 0.4}]},9           {"id": "foundation_models", "number": 2, "name": "FM", "openalex_topics": [{"id": "T10028", "weight": 0.6}], "keywords": [{"pattern": r"(?i)\bfoundation models?\b", "weight": 1.0}]},10           {"id": "crypto", "number": 27, "name": "Crypto", "openalex_topics": [{"id": "T11000", "weight": 1.0}], "exclusions": [r"(?i)\bcryptocurrency\b"],11            "dblp_streams": [{"key": "conf/crypto", "weight": 1.0}]},12       ]}131415def setup_module(module):16    d = tempfile.mkdtemp(); p = os.path.join(d, "ont.yaml"); yaml.safe_dump(ONT, open(p, "w")); classify._init(p)171819def test_keyword_alone_reaches_threshold_and_child_wins_tie():20    res = classify.score_row("Scaling large language models", "", [], [], [], [])21    ids = {r[0] for r in res}; assert ids == {"llm"}22    res = classify.score_row("Foundation models and large language models", "", [10028], [], [], [])23    scores = {r[0]: r[3] for r in res}; assert scores["llm"] == 1.6 and scores["foundation_models"] == 1.624    parents = set().union(*[set(r[2]) for r in res])25    best = sorted(res, key=lambda r: (-r[3], 1 if r[0] in parents else 0, r[1]))[0]; assert best[0] == "llm"262728def test_signal_types_capped_and_summed():29    res = classify.score_row("x", "y", [10028, 10028, 10028], [], ["cs.CL"], [])30    s = {r[0]: r for r in res}; assert "llm" in s and s["llm"][4] == 0.6 and s["llm"][6] == 0.4 and abs(s["llm"][3] - 1.0) < 1e-6313233def test_exclusion_vetoes():34    assert {r[0] for r in classify.score_row("Lattice signatures", "", [11000], [], [], [])} == {"crypto"}35    assert classify.score_row("Cryptocurrency price prediction", "", [11000], [], [], []) == []36    assert {r[0] for r in classify.score_row("a", "b", [], [], [], ["conf/crypto"])} == {"crypto"}37
Files · 1c3517a85558d25d9bddafb26f9a93cc8ed7fffa
Menu

Theme