コード例 #1
0
void init_loop()
{
    init_sqlite();
    init_ac();
    init_trie_tree();
    init_query_table();
    init_query_table_N();
    down_ac();
    add_query_rule("Li & Hong # Zhi");
    add_query_rule("free");
    add_query_rule("sun # peiyuan");
}
コード例 #2
0
ファイル: get_addr.cpp プロジェクト: SeTriones/56wlk
int GetAddr::init(const char* path,const char* file)
{
	Ul_confdata *pconf;
	pconf = ul_initconf(CONF_NUM);
	int ret;
	ret = ul_readconf(path, file, pconf);
	if (ret < 0) 
	{
		FATAL_LOG_NLP("load config file error!");
		return -1;
	}
    char buf[100];
	string loc_map_dict;
	ul_getconfstr(pconf, "loc_map_path", buf);
	loc_map_dict=buf;

    string adcode_map_dict; 
    ul_getconfstr(pconf, "adcode_map_path", buf);
    adcode_map_dict=buf;

    string suffix_dict; 
    ul_getconfstr(pconf, "suffix_path", buf);
    suffix_dict=buf;

    string extendMap_dict;
    ul_getconfstr(pconf, "extend_dict_path", buf);
    extendMap_dict=buf;

    ul_freeconf(pconf);

	ifstream fin1;
	fin1.open(loc_map_dict.c_str());
	if( !fin1 )
	{
		FATAL_LOG_NLP("open loc_map_dict failed");
		return -1; 
	}

    ifstream fin2;
    fin2.open(adcode_map_dict.c_str());
    if( !fin2 )
    {
        FATAL_LOG_NLP("open adcode_map_dict failed");
        return -1; 
    }

    ifstream fin3;
    fin3.open(suffix_dict.c_str());
    if( !fin3 )
    {
        FATAL_LOG_NLP("open suffix_dict failed");
        return -1; 
    }

    ifstream fin4;
    fin4.open(extendMap_dict.c_str());
    if( !fin4 )
    {
        FATAL_LOG_NLP("open extendMap_dict failed, errno:%d, dir:%s", errno, extendMap_dict.c_str());
        return -1;
    }

	tree = init_trie_tree();
	if(!tree)
	{
		FATAL_LOG_NLP("init_trie_tree failed");
		return -1;
	}

	string line;
    string word_1,word_2;
    string pattern = "\t";
    string::size_type pos = 0;
	trie_node *node;
	while(getline(fin1,line))
	{
        pos = line.find(pattern);
        if (pos != -1) {
            word_1 = line.substr(0,pos);
		    node = add_word(tree, word_1.c_str());
            if(!node)
            {
                FATAL_LOG_NLP("add_word failed");
                return -1;
            }
            ++node->preq;
        }
	}

    while(getline(fin2,line))
    {
        pos = line.find(pattern);
        if (pos != -1) {
            word_2 = line.substr(pos+1,line.length());
            node = add_word(tree, word_2.c_str());
            if(!node)
            {
                FATAL_LOG_NLP("add_word failed");
                return -1;
            }
            ++node->preq;
        }
    }
   
    while(getline(fin3,line))
    {
        filter_dict.push_back(line);
    }

    while(getline(fin4,line))
    {
        pos = line.find(pattern);
        if (pos != -1) {
            word_1 = line.substr(0,pos);
            node = add_word(tree, word_1.c_str());
            if(!node)
            {
                FATAL_LOG_NLP("add_word failed");
                return -1;
            }   
            ++node->preq;
        }
    }

    fin1.close();
    fin2.close();
    fin3.close();
    fin4.close();
	return 0;
}