diff options
author | resec <resec0109@gmail.com> | 2017-07-20 05:13:15 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-20 05:13:15 +0300 |
commit | bd5f5ba69024a3171b00156a6c9b75da3b87e28b (patch) | |
tree | 5f28afaa12c4c7d87ffe791b2df5260b96455c98 /src | |
parent | f3255348797ded71d2a4e38de6a2d903c6c7883b (diff) |
Impl std::istream variant to Load and LoadOrDie
Implemented for SentencePieceProcessor:
bool SentencePieceProcessor::Load(std::istream &istream)
void SentencePieceProcessor::LoadOrDie(std::istream &istream)
Diffstat (limited to 'src')
-rw-r--r-- | src/sentencepiece_processor.cc | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/sentencepiece_processor.cc b/src/sentencepiece_processor.cc index 817219f..7abb848 100644 --- a/src/sentencepiece_processor.cc +++ b/src/sentencepiece_processor.cc @@ -42,9 +42,13 @@ bool SentencePieceProcessor::Load(const std::string &filename) { return false; } + return Load(ifs); +} + +bool SentencePieceProcessor::Load(std::istream &istream) { model_proto_ = port::MakeUnique<ModelProto>(); - if (!model_proto_->ParseFromIstream(&ifs)) { - LOG(WARNING) << "Model file is broken: " << filename; + if (!model_proto_->ParseFromIstream(&istream)) { + LOG(WARNING) << "Model file is broken"; return false; } @@ -59,6 +63,10 @@ void SentencePieceProcessor::LoadOrDie(const std::string &filename) { CHECK(Load(filename)) << "failed to load model: " << filename; } +void SentencePieceProcessor::LoadOrDie(std::istream &istream) { + CHECK(Load(istream)) << "failed to load model"; +} + void SentencePieceProcessor::SetEncodeExtraOptions( const std::string &extra_options) { encode_extra_options_ = ParseExtraOptions(extra_options); |