File size: 3,710 Bytes
75b8815
 
 
ff8a1cd
75b8815
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ff8a1cd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75b8815
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ff8a1cd
 
 
 
 
 
 
 
75b8815
347c94b
ff8a1cd
 
 
75b8815
ff8a1cd
75b8815
347c94b
ff8a1cd
 
 
 
 
 
 
 
 
 
 
 
a18279e
ff8a1cd
 
 
 
 
 
 
 
 
75b8815
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
import os
import datasets
import pandas as pd
import json


class semiRelConfig(datasets.BuilderConfig):
    def __init__(self, features, data_url, **kwargs):
        super(semiRelConfig, self).__init__(**kwargs)
        self.features = features
        self.data_url = data_url


class semiRel(datasets.GeneratorBasedBuilder):
    BUILDER_CONFIGS = [
        semiRelConfig(
            name="pairs",
            features={
                "ltable_id": datasets.Value("string"),
                "rtable_id": datasets.Value("string"),
                "label": datasets.Value("string"),
            },
            data_url="https://huggingface.co/datasets/matchbench/semi-Rel/resolve/main/",
        ),
        semiRelConfig(
            name="source",
            features={
                 "id": datasets.Value("string"),
                "title": datasets.Value("string"),
                "director": datasets.Value("string"),
                "actors": datasets.Value("string"),
	       "year": datasets.Value("string"),
 	       "rating": datasets.Value("string"),
                 "information": datasets.Value("string"),
            },
            data_url="https://huggingface.co/datasets/matchbench/semi-Rel/resolve/main/left.csv",
        ),

        semiRelConfig(
            name="target",
            features={
                "content": datasets.Value("string"),
            },
            data_url="https://huggingface.co/datasets/matchbench/semi-Rel/resolve/main/right.json",
        ),
    ]

    def _info(self):
        return datasets.DatasetInfo(
            features=datasets.Features(self.config.features)
        )

    def _split_generators(self, dl_manager):
        if self.config.name == "pairs":
            return [
                datasets.SplitGenerator(
                    name=split,
                    gen_kwargs={
                        "path_file": dl_manager.download_and_extract(
                            os.path.join(self.config.data_url, f"{split}.csv")),
                        "split": split,
                    }
                )
                for split in ["train", "valid", "test"]
            ]

        if self.config.name == "source":
            return [datasets.SplitGenerator(name="source", gen_kwargs={
                "path_file": dl_manager.download_and_extract(self.config.data_url), "split": "source", })]

        if self.config.name == "target":
            return [datasets.SplitGenerator(name="target", gen_kwargs={
                "path_file": dl_manager.download_and_extract(self.config.data_url), "split": "target", })]

    def _generate_examples(self, path_file, split):
        if split in ['target']:
            with open(path_file, "r") as f:
                file = json.load(f)
            for i in range(len(file)):
                yield i, {
                    "content": file[i]
                }
        elif split in ['source']:
            file = pd.read_csv(path_file)
            for i, row in file.iterrows():
                    yield i, {
                        "id": row["id"],
                        "title": row["title"],
                        "director": row["director"],
                        "actors": row["actors"],
                        "year": row["year"],
                        "rating": row["rating"],
                        "information": row["information"],

                    }
        else:
            file = pd.read_csv(path_file)
            for i, row in file.iterrows():
                    yield i, {
                        "ltable_id": row["ltable_id"],
                        "rtable_id": row["rtable_id"],
                        "label": row["label"],
                    }