File size: 4,811 Bytes
1ccf3da
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
afcfe98
 
 
1ccf3da
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import json
import re
import sys
from collections import defaultdict

CATS = ["subordinate_word_order", "v2_violation", "particle_verbs", "gender_agreement",
        "determiners", "anaphor_agreement", "argument_structure", "binding", "ellipsis",
        "irregular_forms", "island_effects", "nominalization", "npi_licensing",
        "passives", "quantifiers", "relative_clauses"]

# Present-tense verbs that must NOT follow past-time adverbs in v2_violation,
# plus the past-time adverb list -- both come from the canonical generator.
import generate_sv_blimp as g
PRESENT_VERBS = set(g.PRESENT_VERBS)
PAST_ADVS = tuple(g.ADV_PAST)

# Morphologically corrupted tokens from an earlier string-derivation approach;
# they must never appear. Regression guard against reintroducing naive
# inflection by string manipulation (the current generator stores explicit forms).
GARBAGE = ["vitr", "srorr", "lirer", "runr", "svärr", "byggsar", "skrivsar", "mätssar",
           "manen", "ma.", "orde.", "huse.", "glase.", "storta huse"]

def skeleton(s):
    """Replace known slot words with X so we can group identical patterns."""
    words = s.split()
    out = []
    for w in words:
        if re.fullmatch(r"[A-Z][a-zäöåÄÖÅé]+", w) and w in KNOWN_AGENTS:
            out.append("AG")
        elif w in KNOWN_OBJECTS:
            out.append("OB")
        else:
            out.append(w)
    return " ".join(out)

KNOWN_AGENTS = set()
KNOWN_OBJECTS = set()

def load_pools():
    KNOWN_AGENTS.update(g.ALL_AGENTS)
    KNOWN_OBJECTS.update(g.ALL_OBJECTS)

def main():
    load_pools()
    total_errors = 0
    all_skeletons = defaultdict(set)

    for cat in CATS:
        path = f"sv_blimp_{cat}.jsonl"
        lines = open(path, encoding="utf-8").read().splitlines()
        errs = []
        ids = set()
        seen_pairs = set()
        seen_singles = {"sentence_good": set(), "sentence_bad": set()}
        for ln, line in enumerate(lines, 1):
            e = json.loads(line)
            ids.add(e["item_id"])
            pair = (e["sentence_good"], e["sentence_bad"])
            if pair in seen_pairs:
                errs.append(f"L{ln}: duplicate (good, bad) pair: {pair}")
            seen_pairs.add(pair)
            if e["sentence_good"] == e["sentence_bad"]:
                errs.append(f"L{ln}: good == bad: {e['sentence_good']}")
            for key in ("sentence_good", "sentence_bad"):
                s = e[key]
                if not s[0].isupper():
                    errs.append(f"L{ln} {key}: lowercase start: {s}")
                if not s.endswith((".", "?")):
                    errs.append(f"L{ln} {key}: no terminal punctuation: {s}")
                for tok in GARBAGE:
                    if re.search(rf"\b{re.escape(tok)}\b", s):
                        errs.append(f"L{ln} {key}: garbage token '{tok}': {s}")
            # Uniqueness of each sentence on its own (in addition to the pair).
            for key in ("sentence_good", "sentence_bad"):
                s = e[key]
                if s in seen_singles[key]:
                    errs.append(f"L{ln} {key}: duplicate sentence: {s}")
                seen_singles[key].add(s)
            # v2 tense check: a past-time adverb must be followed by a preterite,
            # i.e. no present-tense verb form may appear AFTER the adverb.
            # (The adverb prefix is stripped first: "I går" contains the token
            # "går", which is itself a present-tense verb form.)
            if cat == "v2_violation":
                for key in ("sentence_good", "sentence_bad"):
                    s = e[key]
                    adv = next((a for a in PAST_ADVS if s.startswith(a)), None)
                    if adv is not None:
                        rest = s[len(adv):].split()
                        if any(w in PRESENT_VERBS for w in rest):
                            errs.append(f"L{ln} {key}: present tense after past adverb: {s}")
            all_skeletons[cat].add(skeleton(e["sentence_good"]))
            all_skeletons[cat].add(skeleton(e["sentence_bad"]))
        if len(lines) != 1000:
            errs.append(f"expected 1000 lines, got {len(lines)}")
        if ids != set(range(1, 1001)):
            errs.append("item_id set is not 1..1000")
        status = "OK" if not errs else f"{len(errs)} ERRORS"
        print(f"[{status}] {cat}")
        for e in errs[:10]:
            print("   ", e)
        total_errors += len(errs)

    print("\n=== UNIQUE SKELETONS PER CATEGORY (for manual review) ===")
    for cat in CATS:
        print(f"\n--- {cat} ({len(all_skeletons[cat])} unique skeletons) ---")
        for sk in sorted(all_skeletons[cat]):
            print("  ", sk)

    print(f"\nTotal errors: {total_errors}")
    sys.exit(1 if total_errors else 0)

if __name__ == "__main__":
    main()