#ifndef SEGMENT_H #define SEGMENT_H #include #include #include "Trie.h" #include "globals.h" namespace CppJieba { class Segment { private: Trie _trie; public: Segment(); ~Segment(); public: bool init(const char* const dictFilePath); bool destroy(); public: bool cutDAG(const string& chStr, vector& res); bool extract(const string& utf8Str, vector& keywords); double getUtf8WordWeight(const string& word); double getUniWordWeight(const string& word); private: string _utf8ToUni(const string& chStr); bool _calcDAG(const string& uniStr, vector >& dag); bool _calcDP(const string& uniStr, const vector >& dag, vector >& res); bool _cutDAG(const string& uniStr, const vector >& dp, vector& res); bool _filter(vector& utf8Strs); bool _filterSingleWord(vector& utf8Strs); bool _filterSubstr(vector& utf8Strs); static bool _pair_compare(const pair& a, const pair& b); bool _extract(const vector& words, vector& keywords, uint topN); private: enum {bufSize = 1024}; }; } #endif