yuansui commited on
Commit
0f862e8
·
1 Parent(s): ec9063e

Update GitTables.py

Browse files
Files changed (1) hide show
  1. GitTables.py +25 -24
GitTables.py CHANGED
@@ -152,27 +152,28 @@ class GitTables(datasets.GeneratorBasedBuilder):
152
  # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
153
  def _generate_examples(self, filepath, split):
154
  # The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
155
- with jsonlines.open(rf"{filepath}", mode="r") as reader:
156
- for key, row in enumerate(reader):
157
- data = json.loads(row)
158
- if self.config.name == "dbpedia":
159
- # Yields examples as (key, example) tuples
160
- yield key, {
161
- "id": data["id"],
162
- "table_id": data["table_id"],
163
- "target_column": data["target_column"],
164
- "column_text": data["column_text"],
165
- "annotation_id": data["annotation_id"],
166
- "annotation_label": data["annotation_label"],
167
- "table_text": data["table_text"]
168
- }
169
- else:
170
- yield key, {
171
- "id": data["id"],
172
- "table_id": data["table_id"],
173
- "target_column": data["target_column"],
174
- "column_text": data["column_text"],
175
- "annotation_id": data["annotation_id"],
176
- "annotation_label": data["annotation_label"],
177
- "table_text": data["table_text"]
178
- }
 
 
152
  # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
153
  def _generate_examples(self, filepath, split):
154
  # The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
155
+ with open(filepath, encoding="utf-8") as f:
156
+ with jsonlines.open(rf"{f}", mode="r") as reader:
157
+ for key, row in enumerate(reader):
158
+ data = json.loads(row)
159
+ if self.config.name == "dbpedia":
160
+ # Yields examples as (key, example) tuples
161
+ yield key, {
162
+ "id": data["id"],
163
+ "table_id": data["table_id"],
164
+ "target_column": data["target_column"],
165
+ "column_text": data["column_text"],
166
+ "annotation_id": data["annotation_id"],
167
+ "annotation_label": data["annotation_label"],
168
+ "table_text": data["table_text"]
169
+ }
170
+ else:
171
+ yield key, {
172
+ "id": data["id"],
173
+ "table_id": data["table_id"],
174
+ "target_column": data["target_column"],
175
+ "column_text": data["column_text"],
176
+ "annotation_id": data["annotation_id"],
177
+ "annotation_label": data["annotation_label"],
178
+ "table_text": data["table_text"]
179
+ }