cloverhxy commited on
Commit
8f51065
·
1 Parent(s): 5d0552f

Update Abt-Buy.py

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