File size: 4,296 Bytes
592fcef
 
 
 
 
 
 
 
 
 
 
 
 
215abec
 
 
592fcef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
215abec
 
 
592fcef
 
 
215abec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
592fcef
 
 
 
215abec
592fcef
 
 
 
7997120
592fcef
 
 
1aeffad
 
 
7997120
 
 
 
 
 
 
 
 
592fcef
215abec
 
 
 
592fcef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
215abec
 
 
592fcef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import os
import json
from datasets import (
    GeneratorBasedBuilder,
    DatasetInfo,
    Features,
    Value,
    Sequence,
    Split,
    SplitGenerator,
    BuilderConfig,
)

# -------------------------
# Features specification
# -------------------------
SUITE_DATASET_CONDITION_SPEC = {
    "condition_name": Value("string"),
    "content": Value("string"),
    "regions": Sequence({
        "region_number": Value("int32"),
        "content": Value("string"),
    }),
}

SUITE_DATASET_SPEC = Features({
    "suite_name": Value("string"),
    "item_number": Value("int32"),
    "conditions": Sequence(SUITE_DATASET_CONDITION_SPEC),
    "predictions": Sequence(Value("string")),
})

# -------------------------
# Dataset builder
# -------------------------
class SyntacticAgreement(GeneratorBasedBuilder):
    BUILDER_CONFIG_CLASS = BuilderConfig
    BUILDER_CONFIGS = [
        BuilderConfig(
            name="spanish",
            description="Spanish syntax test suites",
        ),
        BuilderConfig(
            name="italian",
            description="Italian syntax test suites",
        ),
        BuilderConfig(
            name="portuguese",
            description="Portuguese syntax test suites",
        ),
        BuilderConfig(
            name="russian",
            description="Russian syntax test suites",
        ),
    ]

    def _info(self):
        return DatasetInfo(
            description="Agreement syntax test suites in multiple languages.",
            features=SUITE_DATASET_SPEC,
            supervised_keys=None,
            homepage="",
            license="",
            citation="https://aclanthology.org/2025.depling-1.4/",
        )

    def _split_generators(self, dl_manager):
        # URL to the zip archive of the selected language
        base_url = "https://huggingface.co/datasets/albalbalba/SyntacticAgreement/resolve/main"
        archive_url = f"{base_url}/{self.config.name}.zip"
        extracted_dir = dl_manager.download_and_extract(archive_url)

        # Handle case where extraction produces a nested folder (italian/italian/*.json)
        possible_nested = os.path.join(extracted_dir, self.config.name)
        if os.path.exists(possible_nested):
            data_dir = possible_nested
        else:
            data_dir = extracted_dir

        return [
            SplitGenerator(
                name=Split.TRAIN,
                gen_kwargs={"data_dir": data_dir},
            ),
        ]

    def _generate_examples(self, data_dir):
        for filename in sorted(os.listdir(data_dir)):
            if not filename.endswith(".json"):
                continue
            filepath = os.path.join(data_dir, filename)
            with open(filepath, encoding="utf-8") as f:
                data = json.load(f)

            suite_name = data["meta"]["name"]
            predictions = [p["formula"] for p in data.get("predictions", [])]

            for item in data.get("items", []):
                item_number = item["item_number"]
                conditions = []
                for condition in item.get("conditions", []):
                    content_all = " ".join(
                        [region["content"] for region in condition["regions"]]
                    ).lstrip(" ")
                    content_all = (
                        content_all.replace("  ", " ")
                        .replace(" .", ".")
                        .replace(" ,", ",")
                        .replace("¿ ", "¿")
                    )
                    conditions.append({
                        "condition_name": condition["condition_name"],
                        "content": content_all,
                        "regions": [
                            {
                                "region_number": region["region_number"],
                                "content": region["content"],
                            }
                            for region in condition["regions"]
                        ],
                    })

                key = f"{suite_name}_{item_number}"
                yield key, {
                    "suite_name": suite_name,
                    "item_number": item_number,
                    "conditions": conditions,
                    "predictions": predictions,
                }