Ejemplo n.º 1
0
 bool init(const string& dictPath, const string& hmmFilePath, const string& charStatus, const string& startProb, const string& emitProb, const string& endProb, const string& transProb)
 {
     
     assert(!_getInitFlag());
     _dictTrie.init(dictPath);
     assert(_dictTrie);
     return _setInitFlag(_segment.init(dictPath, hmmFilePath));
 };
Ejemplo n.º 2
0
 bool init(const string& dictPath, const string& userDictPath = "")
 {
     if(_getInitFlag())
     {
         LogError("already inited before now.");
         return false;
     }
     _dictTrie.init(dictPath, userDictPath);
     assert(_dictTrie);
     LogInfo("MPSegment init(%s) ok", dictPath.c_str());
     return _setInitFlag(true);
 }
Ejemplo n.º 3
0
TEST(DictTrieTest, Test1) {

    string s1, s2;
    DictTrie trie;
    trie.init(DICT_FILE);
    ASSERT_LT(trie.getMinWeight() + 15.6479, 0.001);
    string word("来到");
    Unicode uni;
    ASSERT_TRUE(TransCode::decode(word, uni));
    DictUnit nodeInfo;
    nodeInfo.word = uni;
    nodeInfo.tag = "v";
    nodeInfo.weight = -8.87033;
    s1 << nodeInfo;
    s2 << (*trie.find(uni.begin(), uni.end()));

    EXPECT_EQ("[\"26469\", \"21040\"] v -8.870", s2);
    word = "清华大学";
    LocalVector<pair<size_t, const DictUnit*> > res;
    //vector<pair<size_t, const DictUnit* > resMap;
    LocalVector<pair<size_t, const DictUnit*> > res2;
    const char * words[] = {"清", "清华", "清华大学"};
    for(size_t i = 0; i < sizeof(words)/sizeof(words[0]); i++) {
        ASSERT_TRUE(TransCode::decode(words[i], uni));
        res.push_back(make_pair(uni.size() - 1, trie.find(uni.begin(), uni.end())));
        //resMap[uni.size() - 1] = trie.find(uni.begin(), uni.end());
    }
    //DictUnit
    //res.push_back(make_pair(0, ))

    vector<pair<size_t, const DictUnit*> > vec;
    ASSERT_TRUE(TransCode::decode(word, uni));
    ASSERT_TRUE(trie.find(uni.begin(), uni.end(), res2, 0));
    s1 << res;
    s2 << res;
    ASSERT_EQ(s1, s2);
}
Ejemplo n.º 4
0
 bool init(const string& dictPath, const string& userDictPath = "")
 {
     LIMONP_CHECK(_dictTrie.init(dictPath, userDictPath));
     LogInfo("MPSegment init(%s) ok", dictPath.c_str());
     return true;
 }