File size: 2,953 Bytes
ec86707
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import json
import datasets

_CITATION = """\
@misc{TMBench2025,
  title={TMBench Dataset},
  author={Your Name},
  year={2025}
}
"""

_DESCRIPTION = """\
TMBench is a symbolic rewriting benchmark dataset with four variants:
- TMBench: the latin version
- TMBenchGreek: includes Greek characters in symbol sets
- TMBenchNumber: includes numeric characters in symbol sets
- TMBenchSpecial: includes special characters in symbol sets
Each sample includes:
- An initial string
- A set of rewriting rules (symbol → string)
- Step-wise rewriting results
- Number of deleted characters per step
"""

_HOMEPAGE = "https://gitee.pjlab.org.cn/L1/wuhaitao/DeepCADParser"

class TMBenchConfig(datasets.BuilderConfig):
    def __init__(self, **kwargs):
        super(TMBenchConfig, self).__init__(**kwargs)

class TMBench(datasets.GeneratorBasedBuilder):
    BUILDER_CONFIGS = [
        TMBenchConfig(name="latin", version=datasets.Version("1.0.0"), description="TMBench with Latin letters"),
        TMBenchConfig(name="greek", version=datasets.Version("1.0.0"), description="TMBench with Greek letters"),
        TMBenchConfig(name="number", version=datasets.Version("1.0.0"), description="TMBench with numbers"),
        TMBenchConfig(name="special", version=datasets.Version("1.0.0"), description="TMBench with special characters"),
    ]

    def _info(self):
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=datasets.Features({
                "id": datasets.Value("string"),
                "init_str": datasets.Value("string"),
                "rule": datasets.Features({
                    "__all__": datasets.Value("string")
                }),
                "delete_count": datasets.Value("int32"),
                "step_results": datasets.Sequence(datasets.Value("string")),
            }),
            supervised_keys=None,
            homepage=_HOMEPAGE,
            citation=_CITATION,
        )

    def _split_generators(self, dl_manager):
        name_map = {
            "latin": "TMBench.json",
            "greek": "TMBenchGreek.json",
            "number": "TMBenchNumber.json",
            "special": "TMBenchSpecial.json",
        }
        file_path = dl_manager.download_and_extract(name_map[self.config.name])
        return [
            datasets.SplitGenerator(
                name=datasets.Split.TRAIN,
                gen_kwargs={"filepath": file_path}
            )
        ]

    def _generate_examples(self, filepath):
        with open(filepath, encoding="utf-8") as f:
            data = json.load(f)
            for idx, sample in enumerate(data["samples"]):
                yield idx, {
                    "id": sample.get("id", str(idx)),
                    "init_str": sample["init_str"],
                    "rule": sample["rule"],
                    "delete_count": sample["delete_count"],
                    "step_results": sample["step_results"],
                }