cloverhxy commited on
Commit
79f1ae1
·
1 Parent(s): b8ffda4

Create bikes.py

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