From bd5f5ba69024a3171b00156a6c9b75da3b87e28b Mon Sep 17 00:00:00 2001 From: resec Date: Thu, 20 Jul 2017 10:13:15 +0800 Subject: Impl std::istream variant to Load and LoadOrDie Implemented for SentencePieceProcessor: bool SentencePieceProcessor::Load(std::istream &istream) void SentencePieceProcessor::LoadOrDie(std::istream &istream) --- src/sentencepiece_processor.cc | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/sentencepiece_processor.cc') 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(); - 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); -- cgit v1.2.3