1*993b0882SAndroid Build Coastguard Worker /* 2*993b0882SAndroid Build Coastguard Worker * Copyright (C) 2018 The Android Open Source Project 3*993b0882SAndroid Build Coastguard Worker * 4*993b0882SAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*993b0882SAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*993b0882SAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*993b0882SAndroid Build Coastguard Worker * 8*993b0882SAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*993b0882SAndroid Build Coastguard Worker * 10*993b0882SAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*993b0882SAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*993b0882SAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*993b0882SAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*993b0882SAndroid Build Coastguard Worker * limitations under the License. 15*993b0882SAndroid Build Coastguard Worker */ 16*993b0882SAndroid Build Coastguard Worker 17*993b0882SAndroid Build Coastguard Worker #ifndef LIBTEXTCLASSIFIER_ANNOTATOR_VOCAB_VOCAB_LEVEL_TABLE_H_ 18*993b0882SAndroid Build Coastguard Worker #define LIBTEXTCLASSIFIER_ANNOTATOR_VOCAB_VOCAB_LEVEL_TABLE_H_ 19*993b0882SAndroid Build Coastguard Worker 20*993b0882SAndroid Build Coastguard Worker #include "annotator/model_generated.h" 21*993b0882SAndroid Build Coastguard Worker #include "annotator/types.h" 22*993b0882SAndroid Build Coastguard Worker #include "utils/container/bit-vector.h" 23*993b0882SAndroid Build Coastguard Worker #include "marisa/trie.h" 24*993b0882SAndroid Build Coastguard Worker 25*993b0882SAndroid Build Coastguard Worker namespace libtextclassifier3 { 26*993b0882SAndroid Build Coastguard Worker 27*993b0882SAndroid Build Coastguard Worker struct LookupResult { 28*993b0882SAndroid Build Coastguard Worker // Whether to trigger define for users of beginner proficiency. 29*993b0882SAndroid Build Coastguard Worker bool beginner_level; 30*993b0882SAndroid Build Coastguard Worker // Whether if we should avoid triggering define if the leading character is in 31*993b0882SAndroid Build Coastguard Worker // upper case. 32*993b0882SAndroid Build Coastguard Worker bool do_not_trigger_in_upper_case; 33*993b0882SAndroid Build Coastguard Worker }; 34*993b0882SAndroid Build Coastguard Worker 35*993b0882SAndroid Build Coastguard Worker // A table of vocabs and their levels which is backed by a marisa trie. 36*993b0882SAndroid Build Coastguard Worker // See http://www.s-yata.jp/marisa-trie/docs/readme.en.html. 37*993b0882SAndroid Build Coastguard Worker class VocabLevelTable { 38*993b0882SAndroid Build Coastguard Worker public: 39*993b0882SAndroid Build Coastguard Worker static std::unique_ptr<VocabLevelTable> Create(const VocabModel* model); 40*993b0882SAndroid Build Coastguard Worker 41*993b0882SAndroid Build Coastguard Worker Optional<LookupResult> Lookup(const std::string& vocab) const; 42*993b0882SAndroid Build Coastguard Worker 43*993b0882SAndroid Build Coastguard Worker private: 44*993b0882SAndroid Build Coastguard Worker explicit VocabLevelTable(const VocabModel* model, 45*993b0882SAndroid Build Coastguard Worker std::unique_ptr<marisa::Trie> vocab_trie, 46*993b0882SAndroid Build Coastguard Worker const BitVector beginner_level, 47*993b0882SAndroid Build Coastguard Worker const BitVector do_not_trigger_in_upper_case); 48*993b0882SAndroid Build Coastguard Worker static const VocabModel* LoadAndVerifyModel(); 49*993b0882SAndroid Build Coastguard Worker 50*993b0882SAndroid Build Coastguard Worker const VocabModel* model_; 51*993b0882SAndroid Build Coastguard Worker const std::unique_ptr<marisa::Trie> vocab_trie_; 52*993b0882SAndroid Build Coastguard Worker const BitVector beginner_level_; 53*993b0882SAndroid Build Coastguard Worker const BitVector do_not_trigger_in_upper_case_; 54*993b0882SAndroid Build Coastguard Worker }; 55*993b0882SAndroid Build Coastguard Worker 56*993b0882SAndroid Build Coastguard Worker } // namespace libtextclassifier3 57*993b0882SAndroid Build Coastguard Worker 58*993b0882SAndroid Build Coastguard Worker #endif // LIBTEXTCLASSIFIER_ANNOTATOR_VOCAB_VOCAB_LEVEL_TABLE_H_ 59