updated file IO with database config
Browse files- 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 |
-
|
169 |
-
|
170 |
-
|
171 |
yield key, data
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
|
|
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}")
|