ag2435 commited on
Commit
ab9a953
·
1 Parent(s): 999c568

updated file IO with database config

Browse files
Files changed (1) hide show
  1. phantom-wiki-v050.py +12 -12
phantom-wiki-v050.py CHANGED
@@ -165,16 +165,16 @@ class PhantomWiki(datasets.GeneratorBasedBuilder):
165
  def _generate_examples(self, filepath, split):
166
  # TODO: This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
167
  # The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
168
- with open(filepath, encoding="utf-8") as f:
169
- for key, data in enumerate(json.load(f)):
170
- if self.config.name == "text-corpus":
171
  yield key, data
172
- elif self.config.name == "question-answer":
173
- yield key, data
174
- elif self.config.name == "database":
175
- # NOTE: Our schema expects a dictionary with a single key "content"
176
- yield key, {
177
- "content": data,
178
- }
179
- else:
180
- raise ValueError(f"Unknown configuration name {self.config.name}")
 
165
  def _generate_examples(self, filepath, split):
166
  # TODO: This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
167
  # The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
168
+ if self.config.name in ["text-corpus", "question-answer"]:
169
+ with open(filepath, encoding="utf-8") as f:
170
+ for key, data in enumerate(json.load(f)):
171
  yield key, data
172
+ elif self.config.name == "database":
173
+ with open(filepath, encoding="utf-8") as f:
174
+ data = f.read()
175
+ # NOTE: Our schema expects a dictionary with a single key "content"
176
+ yield key, {
177
+ "content": data,
178
+ }
179
+ else:
180
+ raise ValueError(f"Unknown configuration name {self.config.name}")