cloverhxy commited on
Commit
56ce827
1 Parent(s): 314b63a

Create Company.py

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