TEST(tinybitset_unittest, test_bitset_init) {
  Bitset bitset;
  bool res = bitset.empty();
  EXPECT_EQ(true, res);
  vector<int> bitones = bitset.getbitones();
  EXPECT_EQ(0,bitones.size());
}
TEST(tinybitset_unittest, test_bitset_allsetones) {
  Bitset bitset;
  bitset.allsetones();
  bool res = bitset.empty();
  EXPECT_EQ(true, res);
  vector<int> bitones = bitset.getbitones();
  EXPECT_EQ(128,bitones.size());
  for(int i=0;i<bitones.size();i++){
    EXPECT_EQ(i,bitones[i]);
  }
}
TEST(tinybitset_unittest, test_bitset_normaltest) {
  Bitset bitset;
  bool res;
  for(int i=0;i<kNormalCaseNum;i++){
    bitset.set(kNormalCase[i]);
    res = bitset.get(kNormalCase[i]);
    EXPECT_EQ(1,res);
    res = bitset.empty();
    EXPECT_EQ(0,res);
  }
  vector<int> bitones = bitset.getbitones();
  EXPECT_EQ(kNormalCaseNum,bitones.size());
  for(int i=0;i<kNormalCaseNum;i++){
    EXPECT_EQ(kNormalCase[i],bitones[i]);
  }
}
Exemple #4
0
 static void load_model_constrain(Model * model , const char * lexicon_file = NULL) {
    if (NULL != lexicon_file) {
       std::ifstream lfs(lexicon_file);
       if (lfs) {
           std::string buffer;
           std::vector<std::string> key_values;
           int key_values_size;
           std::string key;
           int value;
           Bitset *  original_bitset;
           while (std::getline(lfs, buffer)) {
               buffer = ltp::strutils::chomp(buffer);
               if (buffer.size() == 0) {
                   continue;
               }
               Bitset values;
               key_values = ltp::strutils::split(buffer);
               key_values_size = key_values.size();
               if(key_values_size == 0 || key_values_size == 1) {
                 continue;
               }
               key = ltp::strutils::chartypes::sbc2dbc_x(key_values[0]);
               for(int i=1;i<key_values_size;i++){
                   value = model->labels.index(key_values[i]);
                   if (value != -1){
                       if(!(values.set(value))) {
                           WARNING_LOG("Tag named %s for word %s add external lexicon error.",key_values[i].c_str(),key_values[0].c_str());
                       }
                   }
                   else {
                       WARNING_LOG("Tag named %s for word %s is not existed in LTP labels set.",key_values[i].c_str(),key_values[0].c_str());
                   }
               }
               if(!values.empty()) {
                 original_bitset = model->external_lexicon.get(key.c_str());
                 if(original_bitset){
                   original_bitset->merge(values);
                 }
                 else{
                   model->external_lexicon.set(key.c_str(),values);
                 }
               }
           }
       }
   }
 }//end func load_model_constrain