| 29 | static const int kWholeLine = -2; |
| 30 | |
| 31 | Status GetNumLinesInTextFile(Env* env, const string& vocab_file, |
| 32 | int64* num_lines) { |
| 33 | std::unique_ptr<RandomAccessFile> file; |
| 34 | TF_RETURN_IF_ERROR(env->NewRandomAccessFile(vocab_file, &file)); |
| 35 | |
| 36 | io::InputBuffer input_buffer(file.get(), kInputBufferSize); |
| 37 | string line; |
| 38 | Status s = input_buffer.ReadLine(&line); |
| 39 | int64 next_id = 0; |
| 40 | while (s.ok()) { |
| 41 | next_id++; |
| 42 | s = input_buffer.ReadLine(&line); |
| 43 | } |
| 44 | if (!errors::IsOutOfRange(s)) { |
| 45 | return s; |
| 46 | } |
| 47 | *num_lines = next_id; |
| 48 | return Status::OK(); |
| 49 | } |
| 50 | |
| 51 | // Iterator that reads a text file. Each iteration process one line, it parses |
| 52 | // the line and populates the keys and values tensors used for initialization |
no test coverage detected