sungguk's picture
Release visual answerability benchmark v1.0.0
e1ced61 verified
Raw History Blame Contribute Delete
2.42 kB
"""``table_dsl_v1`` operator signature table — grammar only (``docs/02`` §7,
``docs/07`` §4 P2).
This third DSL covers lookups/aggregations over a table's rows and columns. P2
ships the **signature table + canonicalization profile** so the type checker and
canonicalizer cover the full ``dsl`` enum and so ChartQA's underlying table
(hashed in ``provenance.table_sha256``) has a target grammar. No per-source
compiler is implemented here: tables are not compiled deterministically in P2.
ChartQA is a C2/P4 model-compiled source — its program is proposed/verified by
the dual model families, not built in code. The compiler is therefore P4.
"""
from __future__ import annotations
from .typecheck import OpSignature
# DSL marker (the ``dsl`` enum value); kept for parity with the other DSL modules.
DSL = "table_dsl_v1"
# --- operator signature table ---------------------------------------------
#
# ``COL(label)`` selects a column (scalar); ``ROW(...)`` selects a row. ``LOOKUP``
# reads one cell. ``SUM``/``AVG`` are variadic-commutative aggregations over a
# column (set) of values; ``COUNT``/``EXIST`` are set selectors over a column.
SIGNATURES: dict[str, OpSignature] = {
"COL": OpSignature(arg_types=("string",), return_type="column", selector_kind="scalar"),
"ROW": OpSignature(arg_types=("string",), return_type="row", selector_kind="scalar"),
"LOOKUP": OpSignature(arg_types=("row", "column"), return_type="value", selector_kind="none"),
"SUM": OpSignature(
arg_types=("value",),
return_type="value",
commutative=True,
variadic=True,
selector_kind="none",
),
"AVG": OpSignature(
arg_types=("value",),
return_type="value",
commutative=True,
variadic=True,
selector_kind="none",
),
"COUNT": OpSignature(arg_types=("column",), return_type="integer", selector_kind="set"),
"EXIST": OpSignature(arg_types=("column",), return_type="boolean", selector_kind="set"),
}
# Canonicalization profile (§7.2 steps 3–5). ``SUM``/``AVG`` are commutative;
# table aliases/casts are not introduced in P2 (the compiler is P4).
COMMUTATIVE_OPS: frozenset[str] = frozenset({"SUM", "AVG"})
ALIASES: dict[str, str] = {"GET_CELL": "LOOKUP", "TOTAL": "SUM"}
IDENTITY_CASTS: frozenset[str] = frozenset()
__all__ = [
"ALIASES",
"COMMUTATIVE_OPS",
"DSL",
"IDENTITY_CASTS",
"SIGNATURES",
]