diff --git a/libcorpus2/io/reader.cpp b/libcorpus2/io/reader.cpp index 46a158a4eceaf78eee265785497ca1a4c4811b76..7dacd101ae706d63955bddaf14b303d8038b7d4f 100644 --- a/libcorpus2/io/reader.cpp +++ b/libcorpus2/io/reader.cpp @@ -222,6 +222,22 @@ boost::shared_ptr<Chunk> BufferedChunkReader::get_next_chunk() } } +bool BufferedChunkReader::has_more() +{ + ensure_more(); + return !chunk_buf_.empty(); +} + +bool BufferedSentenceReader::has_more() +{ + if (sentence_buf_ != NULL) { + return true; + } + sentence_buf_ = actual_next_sentence(); + return (sentence_buf_ != NULL); +} + + BufferedSentenceReader::BufferedSentenceReader(const Tagset& tagset) : TokenReader(tagset), chunkify_(true) , sentence_buf_(), token_buf_() diff --git a/libcorpus2/io/reader.h b/libcorpus2/io/reader.h index 417497d637d8600f37d9476730e2323bd10802d4..e4e242fe20306cf24bb4c82006aef1788d5a1a38 100644 --- a/libcorpus2/io/reader.h +++ b/libcorpus2/io/reader.h @@ -90,6 +90,13 @@ public: */ virtual boost::shared_ptr<Chunk> get_next_chunk() = 0; + + /** + * Checks if there is anything left to be returned. Non-const because it + * might read ahead and fill the buffer. + */ + virtual bool has_more() = 0; + /** * General option setter. */ @@ -297,6 +304,8 @@ public: boost::shared_ptr<Chunk> get_next_chunk(); + bool has_more(); + void set_option(const std::string& option) { TokenReader::set_option(option); } @@ -332,6 +341,8 @@ public: Sentence::Ptr get_next_sentence(); + bool has_more(); + boost::shared_ptr<Chunk> get_next_chunk(); void set_option(const std::string& option) { diff --git a/swig/libcorpustokenreader.i b/swig/libcorpustokenreader.i index 0a367d531e933538db5866133b8a9ed2a9ab2a6f..c5d64d1ae4f7bc731f9e9872c1d694aaa7cf2268 100644 --- a/swig/libcorpustokenreader.i +++ b/swig/libcorpustokenreader.i @@ -61,6 +61,7 @@ namespace Corpus2 { virtual Token* get_next_token() = 0; virtual Sentence::Ptr get_next_sentence() = 0; virtual boost::shared_ptr<Chunk> get_next_chunk() = 0; + virtual bool has_more() = 0; /* --------------------------------------------------------------------- */ virtual void set_option(const std::string& option);