示例#1
0
 void  CWord_correct::operator()(const std::string& search_word,std::string& search_result)
 {
     word_cache cache;
     std::vector<CMypair> re_vec;
     make_cache(cache,r_index,search_word);
     Json::Value correct_value;
     Json::FastWriter writer;
     if(cache.count(search_word)>0)
     {
         correct_value["type"]="输入正确";
         Json::Value value;
         Json::Value temp;
         value["result"]="输入正确";
         temp.append(value);
         correct_value["result"]=temp;
     }
     else
     {
         correct_value["type"]="输入有误,以下候选词可能是你希望输入的";
         get_correct(cache,re_vec,search_word);
         Json::Value value;
         if(re_vec.size())
         {
             std::vector<CMypair>::reverse_iterator r_iter=re_vec.rbegin();
             for(r_iter;r_iter!=re_vec.rend();r_iter++)
             {
                 //std::cout<<r_iter->m_str<<"->freq: "<<r_iter->m_freq<<"->m_dis: "<<r_iter->m_dis<<std::endl;
                 Json::Value temp;
                 temp["result"]=r_iter->m_str;
                 value.append(temp);
             }
             correct_value["result"]=value;
         }
         else
         {
             Json::Value value;
             Json::Value temp;
             value["result"]="无此纠错结果,请输入其他查询词汇";
             temp.append(value);
             correct_value["result"]=temp;
         }
     }
     search_result=writer.write(correct_value);
 }
示例#2
0
文件: yat.c 项目: AlphaShawn/ICS-Labs
int main(int argc, char *argv[])
{
    int stuff = 0;
  
    if (argc < 2)
        stuff = 1;
    else if (!strcmp(argv[1], "-h"))
        stuff = 1;
    else if (!strcmp(argv[1], "-s"))
        stuff = 2;
    else if (!strcmp(argv[1], "-S"))
        stuff = 3;
    else if (!strcmp(argv[1], "-a"))
        stuff = 4;
    else if (!strcmp(argv[1], "-A"))
        stuff = 5;
    else if (!strcmp(argv[1], "-F"))
        stuff = 6;
    else if (!strcmp(argv[1], "-c"))
        stuff = 7;
    
    if (stuff == 0) {
        fprintf(stderr, "yat: Invalid option %s\n", argv[1]);
        return 1;
    }
    
    if (stuff == 1) {
        print_usage();
        return 0;
    }
    
    if (make_y86sim()) {
        fprintf(stderr, "yat: Cannot make y86sim, go check y86sim.c or y86sim.h\n");
        return 1;
    }
    
    if (stuff == 2) {
	   if (argc == 3) {
		test_ins_bin(argv[2],0);
	} else if (argc == 4){
		int step = atoi(argv[3]);
		test_ins_bin(argv[2],step);
	} else {
            fprintf(stderr, "yat: You have to specify the arguments\n");
            return 1;
        }
    

    } else if (stuff == 4) {
        if (argc == 3)
            test_app_bin(argv[2],0);
        else if(argc == 4){
		int step = atoi(argv[3]);
            test_app_bin(argv[2],step);
		}
        else{
            fprintf(stderr, "yat: You have to specify the arguments\n");
            return 1;
        }    
    
    } else if (stuff == 3) {
        test_all_ins_bin();
    } else if (stuff == 5) {
        test_all_app_bin();
    } else if (stuff == 6) {
        test_all_ins_bin();
        test_all_app_bin();
    } else if (stuff == 7) {
		if(argc == 3)
			get_correct(argv[2],0);
		else if (argc == 4){
			int step = atoi(argv[3]);
			get_correct(argv[2],step);
		}
	}
        
    clean_up();
    
    print_result();
    
	return 0;
}