qt在新版本中整合了qtlucene的组件,单位的机器qt版本不够,也懒得升级。先看一下中文切分词部分。
目的:对文档进行中文切分,并根据词频高低排序。
选择LibMMSeg 作为切分词组件。
下载源码,
./bootstrap
./configure --/prefix=/opt/mmseg
make
make install
完毕,
在qtcreator中新建项目,因为mmseg只提供了客户端开发文档,并未提及切分词部分的调用方法,暂时从 source code : src/mmseg_main.cpp 顺藤摸瓜。
以上代码为实现Demo:
项目文件:
QT += core webkit network
SOURCES += main.cpp \
mmseg_main.cpp
HEADERS +=
LIBS += -L/opt/mmseg/lib -lmmseg
INCLUDEPATH = /opt/mmseg/include/
main.cpp
#include
#include "mmseg_main.cpp"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
string dictpath = "/opt/mmseg/etc/";
string content = "全文检索是数据库的有力补充,全文检索并不能替代数据库在应用系统中的作用。当应用系统的数据以大量的文本信息为主时,采用全文检索技术可以极大的提升应用系统的价值。 ";
map m = segment(content, dictpath);
vector > v;
sortMapByValue(m, v);
for (int i = 0; i < 50; ++i)
cout<
mmseg_main.cpp
#include
#include
#include
#include
#include
输出结果:
6 的
3 应用
3 检索
3 全文
3 系统
2 数据库
2 ,
2 。
1 能
1 补充
1 采用
1 极大
1 有力
1 替代
1 是
1 时
1 文本
1 提升
1 数据
1
1 技术
1 当
1 并不
1 大量
1 在
1 可以
1 信息
1 作用
1 价值
1 以
1 为主
1 中