ScHh0625 commited on
Commit
94e35b9
·
1 Parent(s): d9ac088

Upload relHeter.py

Browse files
Files changed (1) hide show
  1. relHeter.py +98 -0
relHeter.py ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import datasets
3
+ import pandas as pd
4
+
5
+
6
+ class relHeterConfig(datasets.BuilderConfig):
7
+ def __init__(self, features, data_url, **kwargs):
8
+ super(relHeterConfigConfig, self).__init__(**kwargs)
9
+ self.features = features
10
+ self.data_url = data_url
11
+
12
+
13
+ class relHeterConfig(datasets.GeneratorBasedBuilder):
14
+ BUILDER_CONFIGS = [
15
+ relHeterConfig(
16
+ name="pairs",
17
+ features={
18
+ "ltable_id": datasets.Value("string"),
19
+ "rtable_id": datasets.Value("string"),
20
+ "label": datasets.Value("string"),
21
+ },
22
+ data_url="https://huggingface.co/datasets/matchbench/rel-heter/resolve/main/",
23
+ ),
24
+ relHeterConfig(
25
+ name="source",
26
+ features={
27
+ "id": datasets.Value("string"),
28
+ "title": datasets.Value("string"),
29
+ "address": datasets.Value("string"),
30
+ "phone": datasets.Value("string"),
31
+ "category": datasets.Value("string"),
32
+ },
33
+ data_url="https://huggingface.co/datasets/matchbench/rel-heter/resolve/main/tableA.csv",
34
+ ),
35
+ relHeterConfig(
36
+ name="target",
37
+ features={
38
+ "id": datasets.Value("string"),
39
+ "add": datasets.Value("string"),
40
+ "city": datasets.Value("string"),
41
+ "phone": datasets.Value("string"),
42
+ "type": datasets.Value("string"),
43
+ "class": datasets.Value("string"),
44
+ },
45
+ data_url="https://huggingface.co/datasets/matchbench/rel-heter/resolve/main/tableB.csv",
46
+ ),
47
+ ]
48
+
49
+ def _info(self):
50
+ return datasets.DatasetInfo(
51
+ features=datasets.Features(self.config.features)
52
+ )
53
+
54
+ def _split_generators(self, dl_manager):
55
+ if self.config.name == "pairs":
56
+ return [
57
+ datasets.SplitGenerator(
58
+ name=split,
59
+ gen_kwargs={
60
+ "path_file": dl_manager.download_and_extract(
61
+ os.path.join(self.config.data_url, f"{split}.csv")),
62
+ "split": split,
63
+ }
64
+ )
65
+ for split in ["train", "valid", "test"]
66
+ ]
67
+ if self.config.name == "source":
68
+ return [datasets.SplitGenerator(name="source", gen_kwargs={
69
+ "path_file": dl_manager.download_and_extract(self.config.data_url), "split": "source", })]
70
+ if self.config.name == "target":
71
+ return [datasets.SplitGenerator(name="target", gen_kwargs={
72
+ "path_file": dl_manager.download_and_extract(self.config.data_url), "split": "target", })]
73
+
74
+ def _generate_examples(self, path_file, split):
75
+ file = pd.read_csv(path_file)
76
+ for i, row in file.iterrows():
77
+ if split not in ['source', 'target']:
78
+ yield i, {
79
+ "ltable_id": row["ltable_id"],
80
+ "rtable_id": row["rtable_id"],
81
+ "label": row["label"],
82
+ }
83
+ elif split in ['source']:
84
+ yield i, {
85
+ "id": row["id"],
86
+ "title": row["title"],
87
+ "address": row["address"],
88
+ "phone": row["phone"],
89
+ "category": row["category"]},
90
+ else:
91
+ yield i, {
92
+ "id": row["id"],
93
+ "addr": row["addr"],
94
+ "city": row["city"],
95
+ "phone": row["phone"],
96
+ "type": row["type"],
97
+ "class": row["class"],
98
+ }