mirror of
https://github.com/yanyiwu/cppjieba.git
synced 2025-07-18 00:00:12 +08:00
removed test/demo.cpp and linked https://github.com/yanyiwu/cppjieba-demo
This commit is contained in:
parent
30aaf7b9ad
commit
e521f26456
@ -19,7 +19,6 @@ ADD_DEFINITIONS(-O3 -Wall -g)
|
||||
ADD_SUBDIRECTORY(test)
|
||||
|
||||
ENABLE_TESTING()
|
||||
ADD_TEST(NAME ./demo COMMAND ./demo)
|
||||
if(NOT MSVC)
|
||||
ADD_TEST(NAME ./test/test.run COMMAND ./test/test.run)
|
||||
ADD_TEST(NAME ./load_test COMMAND ./load_test)
|
||||
|
@ -1,6 +1,5 @@
|
||||
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR})
|
||||
|
||||
ADD_EXECUTABLE(demo demo.cpp)
|
||||
if(NOT MSVC)
|
||||
ADD_EXECUTABLE(load_test load_test.cpp)
|
||||
ADD_SUBDIRECTORY(unittest)
|
||||
|
@ -1,80 +0,0 @@
|
||||
#include "cppjieba/Jieba.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
const char* const DICT_PATH = "../dict/jieba.dict.utf8";
|
||||
const char* const HMM_PATH = "../dict/hmm_model.utf8";
|
||||
const char* const USER_DICT_PATH = "../dict/user.dict.utf8";
|
||||
const char* const IDF_PATH = "../dict/idf.utf8";
|
||||
const char* const STOP_WORD_PATH = "../dict/stop_words.utf8";
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
cppjieba::Jieba jieba(DICT_PATH,
|
||||
HMM_PATH,
|
||||
USER_DICT_PATH,
|
||||
IDF_PATH,
|
||||
STOP_WORD_PATH);
|
||||
vector<string> words;
|
||||
vector<cppjieba::Word> jiebawords;
|
||||
string s;
|
||||
string result;
|
||||
|
||||
s = "他来到了网易杭研大厦";
|
||||
cout << s << endl;
|
||||
cout << "[demo] Cut With HMM" << endl;
|
||||
jieba.Cut(s, words, true);
|
||||
cout << limonp::Join(words.begin(), words.end(), "/") << endl;
|
||||
|
||||
cout << "[demo] Cut Without HMM " << endl;
|
||||
jieba.Cut(s, words, false);
|
||||
cout << limonp::Join(words.begin(), words.end(), "/") << endl;
|
||||
|
||||
s = "我来到北京清华大学";
|
||||
cout << s << endl;
|
||||
cout << "[demo] CutAll" << endl;
|
||||
jieba.CutAll(s, words);
|
||||
cout << limonp::Join(words.begin(), words.end(), "/") << endl;
|
||||
|
||||
s = "小明硕士毕业于中国科学院计算所,后在日本京都大学深造";
|
||||
cout << s << endl;
|
||||
cout << "[demo] CutForSearch" << endl;
|
||||
jieba.CutForSearch(s, words);
|
||||
cout << limonp::Join(words.begin(), words.end(), "/") << endl;
|
||||
|
||||
cout << "[demo] Insert User Word" << endl;
|
||||
jieba.Cut("男默女泪", words);
|
||||
cout << limonp::Join(words.begin(), words.end(), "/") << endl;
|
||||
jieba.InsertUserWord("男默女泪");
|
||||
jieba.Cut("男默女泪", words);
|
||||
cout << limonp::Join(words.begin(), words.end(), "/") << endl;
|
||||
|
||||
cout << "[demo] CutForSearch Word With Offset" << endl;
|
||||
jieba.CutForSearch(s, jiebawords, true);
|
||||
cout << jiebawords << endl;
|
||||
|
||||
cout << "[demo] Lookup Tag for Single Token" << endl;
|
||||
const int DemoTokenMaxLen = 32;
|
||||
char DemoTokens[][DemoTokenMaxLen] = {"拖拉机", "CEO", "123", "。"};
|
||||
vector<pair<string, string> > LookupTagres(sizeof(DemoTokens) / DemoTokenMaxLen);
|
||||
vector<pair<string, string> >::iterator it;
|
||||
for (it = LookupTagres.begin(); it != LookupTagres.end(); it++) {
|
||||
it->first = DemoTokens[it - LookupTagres.begin()];
|
||||
it->second = jieba.LookupTag(it->first);
|
||||
}
|
||||
cout << LookupTagres << endl;
|
||||
|
||||
cout << "[demo] Tagging" << endl;
|
||||
vector<pair<string, string> > tagres;
|
||||
s = "我是拖拉机学院手扶拖拉机专业的。不用多久,我就会升职加薪,当上CEO,走上人生巅峰。";
|
||||
jieba.Tag(s, tagres);
|
||||
cout << s << endl;
|
||||
cout << tagres << endl;
|
||||
|
||||
cout << "[demo] Keyword Extraction" << endl;
|
||||
const size_t topk = 5;
|
||||
vector<cppjieba::KeywordExtractor::Word> keywordres;
|
||||
jieba.extractor.Extract(s, keywordres, topk);
|
||||
cout << s << endl;
|
||||
cout << keywordres << endl;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user