forked from OpenNMT/OpenNMT-py
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Start abstracting out dataset readers. * Remove make_examples in favor of Reader.read * Uniform spacing around imports. * _check_deps as a classmethod of the reader. * Move reader.read calls into DatasetBase init. * Add 'empty' data reader __init__ to reader's base; delete from TextDataReader. * Make readers a class attribute of DatasetBase instead of passing as args. * Revert "Make readers a class attribute of DatasetBase instead of passing as args." This reverts commit cc8cc98. * Add from_opt to readers; undo __init__ taking all the args. * Add tests for data readers.
- Loading branch information
Showing
13 changed files
with
394 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# coding: utf-8 | ||
|
||
|
||
# several data readers need optional dependencies. There's no | ||
# appropriate builtin exception | ||
class MissingDependencyException(Exception): | ||
pass | ||
|
||
|
||
class DataReaderBase(object): | ||
"""Read data from file system and yield as dicts.""" | ||
@classmethod | ||
def from_opt(cls, opt): | ||
return cls() | ||
|
||
@classmethod | ||
def _read_file(cls, path): | ||
with open(path, "rb") as f: | ||
for line in f: | ||
yield line | ||
|
||
@staticmethod | ||
def _raise_missing_dep(*missing_deps): | ||
"""Raise missing dep exception with standard error message.""" | ||
raise MissingDependencyException( | ||
"Could not create reader. Be sure to install " | ||
"the following dependencies: " + ", ".join(missing_deps)) | ||
|
||
def read(self, data, side, src_dir): | ||
raise NotImplementedError() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.