Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Commit

Permalink
Support stdin for prediction jsonl. (#2003)
Browse files Browse the repository at this point in the history
  • Loading branch information
schmmd committed Nov 6, 2018
1 parent bae7758 commit 3ca6942
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions allennlp/commands/predict.py
Expand Up @@ -151,12 +151,20 @@ def _maybe_print_to_console_and_file(self,
self._output_file.write(prediction)

def _get_json_data(self) -> Iterator[JsonDict]:
for line in open(self._input_file):
if not line.isspace():
yield self._predictor.load_line(line)
if self._input_file == "-":
for line in sys.stdin:
if not line.isspace():
yield self._predictor.load_line(line)
else:
with open(self._input_file, "r") as file_input:
for line in file_input:
if not line.isspace():
yield self._predictor.load_line(line)

def _get_instance_data(self) -> Iterator[Instance]:
if self._dataset_reader is None:
if self._input_file == "-":
raise ConfigurationError("stdin is not an option when using a DatasetReader.")
elif self._dataset_reader is None:
raise ConfigurationError("To generate instances directly, pass a DatasetReader.")
else:
yield from self._dataset_reader.read(self._input_file)
Expand Down

0 comments on commit 3ca6942

Please sign in to comment.