1 /* Copyright 2020 The TensorFlow Authors. All Rights Reserved. 2 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 ==============================================================================*/ 15 16 #ifndef TENSORFLOW_LITE_SUPPORT_CC_UTILS_COMMON_UTILS_H_ 17 #define TENSORFLOW_LITE_SUPPORT_CC_UTILS_COMMON_UTILS_H_ 18 19 #include <string> 20 #include <vector> 21 22 #include "absl/container/node_hash_map.h" 23 24 namespace tflite { 25 namespace support { 26 namespace utils { 27 28 // Read a vocab file with one vocabulary on each line, create a vector of 29 // strings. 30 std::vector<std::string> LoadVocabFromFile(const std::string& path_to_vocab); 31 32 // read a vocab buffer with one vocab one each line, create a vector of strings 33 std::vector<std::string> LoadVocabFromBuffer(const char* vocab_buffer_data, 34 const size_t vocab_buffer_size); 35 36 // Read a vocab file with one vocabulary and its corresponding index on each 37 // line separated by space, create a map of <vocab, index>. 38 absl::node_hash_map<std::string, int> LoadVocabAndIndexFromFile( 39 const std::string& path_to_vocab); 40 41 // Read a vocab buffer with one vocabulary and its corresponding index on each 42 // line separated by space, create a map of <vocab, index>. 43 absl::node_hash_map<std::string, int> LoadVocabAndIndexFromBuffer( 44 const char* vocab_buffer_data, const size_t vocab_buffer_size); 45 } // namespace utils 46 } // namespace support 47 } // namespace tflite 48 49 #endif // TENSORFLOW_LITE_SUPPORT_CC_UTILS_COMMON_UTILS_H_ 50