Datasets:
Modalities:
Text
Formats:
json
Size:
< 1K
Tags:
multilingual
mathematical-word-problems
natural-language-to-formal-language
multi-agent-systems
benchmark
conversational-interfaces
Download tests/test_readers.py from tailot/math-stratum: direct link, hf CLI and curl.
- Browser
- Download file 3.81 kB
-
https://huggingface.co/datasets/tailot/math-stratum/resolve/main/tests/test_readers.py
- Command line
-
hf download hf://datasets/tailot/math-stratum/tests/test_readers.py
-
curl -L -o test_readers.py https://huggingface.co/datasets/tailot/math-stratum/resolve/main/tests/test_readers.py
3.81 kB
| """What the two readers do, taken from the questions the corpus already carries.""" | |
| import pytest | |
| from lgstratum import canonical, compare, corpus, read_a, read_b | |
| ITEMS = {item["id"]: item for item in corpus.load()} | |
| AGREED = [item_id for item_id, item in ITEMS.items() if (item.get("expect") or {}).get("state") == "AGREED"] | |
| SINGLE = [item_id for item_id, item in ITEMS.items() if (item.get("expect") or {}).get("state") == "SINGLE"] | |
| NEGATIVE = [item_id for item_id, item in ITEMS.items() | |
| if (item.get("expect") or {}).get("state") == "NOT COVERED"] | |
| PASSTHROUGH = [item_id for item_id, item in ITEMS.items() | |
| if (item.get("expect") or {}).get("state") == "PASSTHROUGH"] | |
| def _item(item_id): | |
| item = ITEMS[item_id] | |
| return str(item["lang"]), str(item["question"]) | |
| def test_the_readers_are_read_from_the_data_not_from_a_fork(): | |
| # Two readers that share nothing but the data files are the whole point: one matches the shapes | |
| # written in the frames, the other follows the joints of the math language. If they became the | |
| # same procedure, the stratum would be reading a question twice with one pair of eyes. | |
| assert read_a.read.__module__ != read_b.read.__module__ | |
| import inspect | |
| assert "gap_markers" not in inspect.getsource(read_a.read) | |
| assert "compile_pattern" not in inspect.getsource(read_b.read) | |
| def test_both_readers_reach_the_same_sentence(item_id): | |
| lang, question = _item(item_id) | |
| a = read_a.read(lang, question) | |
| b = read_b.read(lang, question) | |
| assert a["status"] == "READ", (item_id, a.get("notes")) | |
| assert b["status"] == "READ", (item_id, b.get("notes")) | |
| assert a["kind"] == b["kind"], (item_id, a["kind"], b["kind"]) | |
| assert compare.equivalence(a, b)["same"] is True, (item_id, compare.equivalence(a, b).get("why")) | |
| expected = canonical.tidy(str((ITEMS[item_id].get("expect") or {}).get("sentence", ""))) | |
| if expected: | |
| assert canonical.tidy(canonical.print_math(a["kind"], a["slots"])) == expected, item_id | |
| def test_a_reader_keeps_every_number_the_question_wrote(item_id): | |
| lang, question = _item(item_id) | |
| reading = read_a.read(lang, question) | |
| assert compare.keeps(reading, question)["ok"] is True, (item_id, compare.keeps(reading, question)) | |
| def test_one_reader_may_abstain_where_the_other_reads(item_id): | |
| # The varieties that put the joints after the slot, rather than before it, are read by the strict | |
| # reader and not by the frame reader. That disagreement is reported, never hidden, and it is what | |
| # keeps the assurance of those questions at one. | |
| lang, question = _item(item_id) | |
| a = read_a.read(lang, question) | |
| b = read_b.read(lang, question) | |
| assert a["status"] == "READ", (item_id, a.get("notes")) | |
| assert b["status"] != "READ", (item_id, b.get("notes")) | |
| assert compare.equivalence(a, b)["same"] is False, item_id | |
| def test_a_question_this_variety_does_not_write_is_not_read(item_id): | |
| lang, question = _item(item_id) | |
| for reading in (read_a.read(lang, question), read_b.read(lang, question)): | |
| assert reading["status"] != "READ", (item_id, reading.get("kind"), reading.get("slots")) | |
| assert not reading.get("math"), (item_id, reading.get("math")) | |
| def test_the_math_language_is_handed_on_without_being_read(item_id): | |
| lang, question = _item(item_id) | |
| direct = canonical.direct(question) | |
| assert direct is not None, item_id | |
| assert canonical.tidy(str(direct.get("math", ""))) == canonical.tidy( | |
| str((ITEMS[item_id].get("expect") or {}).get("sentence", ""))), item_id | |