ScHh0625 commited on
Commit
52954cd
·
1 Parent(s): d5927ad

Update rel-text.py

Browse files
Files changed (1) hide show
  1. rel-text.py +20 -16
rel-text.py CHANGED
@@ -36,7 +36,7 @@ class relText(datasets.GeneratorBasedBuilder):
36
  "venue": datasets.Value("string"),
37
  "year": datasets.Value("string"),
38
  },
39
- data_url="https://huggingface.co/datasets/matchbench/rel-text/resolve/main/right.txt",
40
  ),
41
  ]
42
 
@@ -52,7 +52,7 @@ class relText(datasets.GeneratorBasedBuilder):
52
  name=split,
53
  gen_kwargs={
54
  "path_file": dl_manager.download_and_extract(
55
- os.path.join(self.config.data_url, f"{split}.txt")),
56
  "split": split,
57
  }
58
  )
@@ -66,15 +66,16 @@ class relText(datasets.GeneratorBasedBuilder):
66
  "path_file": dl_manager.download_and_extract(self.config.data_url), "split": "target", })]
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
- if split in ['target']:
 
78
  yield i, {
79
  "id": row["id"],
80
  "title": row["title"],
@@ -82,13 +83,16 @@ class relText(datasets.GeneratorBasedBuilder):
82
  "venue": row["venue"],
83
  "year": row["year"],
84
  }
85
- if split in ['source']:
86
- yield i, {
87
- "column": row["column"],
88
- }
89
-
90
-
91
-
92
-
93
-
94
-
 
 
 
 
36
  "venue": datasets.Value("string"),
37
  "year": datasets.Value("string"),
38
  },
39
+ data_url="https://huggingface.co/datasets/matchbench/rel-text/resolve/main/right.csv",
40
  ),
41
  ]
42
 
 
52
  name=split,
53
  gen_kwargs={
54
  "path_file": dl_manager.download_and_extract(
55
+ os.path.join(self.config.data_url, f"{split}.csv")),
56
  "split": split,
57
  }
58
  )
 
66
  "path_file": dl_manager.download_and_extract(self.config.data_url), "split": "target", })]
67
 
68
  def _generate_examples(self, path_file, split):
69
+ file = pd.read_table(path_file),
70
+ if split not in ['source', 'target']:
71
+ for i, row in file.itertuples():
72
  yield i, {
73
  "ltable_id": row["ltable_id"],
74
  "rtable_id": row["rtable_id"],
75
  "label": row["label"],
76
  }
77
+ if split in ['target']:
78
+ for i, row in file.itertuples():
79
  yield i, {
80
  "id": row["id"],
81
  "title": row["title"],
 
83
  "venue": row["venue"],
84
  "year": row["year"],
85
  }
86
+ if split in ['source']:
87
+ with open(path_file, "r") as f:
88
+ md = {}
89
+ for _, line in enumerate(f):
90
+ t = line.strip().split(',')
91
+ if t[0] not in md:
92
+ md[t[0]] = {t[1]}
93
+ else:
94
+ md[t[0]].add(t[1])
95
+ id = -1
96
+ for k in md.items():
97
+ id = id + 1
98
+ yield id, {"column": k}