【Linux】jieba的安装和使用

目录

链接

jieba库简介

​获得jieba库

怎么使用jieba库


链接

因为github下载东西的时间原因,下面这个网站会定期将jieba从github镜像回来

项目 · 探索 · GitCodehttps://gitcode.net/explore输入cppjieba进行搜索,点击相应链接进入

jieba库简介

需要头文件 #include/cppjieba/*.hpp

进入include文件

我们这里主要使用里面jieba.hpp

获得jieba库

1)点击克隆

2)复制对应的链接

3>进入Linux,输入如下命令获取链接

git clone git@gitcode.net:qq_55172408/cppjieba.git

怎么使用jieba库

1)我们进入到下载的cppjieba目录下

root@iZbp1f6xfzvrfki6wwxqjvZ test# ll

total 4

drwxr-xr-x 7 root root 4096 Feb 27 21:11 cppjieba

root@iZbp1f6xfzvrfki6wwxqjvZ test# cd cppjieba/

root@iZbp1f6xfzvrfki6wwxqjvZ cppjieba# ll

total 56

-rw-r--r-- 1 root root 611 Feb 27 21:11 appveyor.yml

-rw-r--r-- 1 root root 10250 Feb 27 21:11 ChangeLog.md

-rw-r--r-- 1 root root 675 Feb 27 21:11 CMakeLists.txt

drwxr-xr-x 4 root root 4096 Feb 27 21:11 deps

drwxr-xr-x 3 root root 4096 Feb 27 21:11 dict

drwxr-xr-x 3 root root 4096 Feb 27 21:11 include

-rw-r--r-- 1 root root 4746 Feb 27 21:11 README_EN.md

-rw-r--r-- 1 root root 11175 Feb 27 21:11 README.md

drwxr-xr-x 4 root root 4096 Feb 27 21:11 test

root@iZbp1f6xfzvrfki6wwxqjvZ cppjieba#

2)进入cppjieba目录下test文件 ,有一个demo.cpp文件

root@iZbp1f6xfzvrfki6wwxqjvZ cppjieba# cd test

root@iZbp1f6xfzvrfki6wwxqjvZ test# ll

total 20

-rw-r--r-- 1 root root 148 Feb 27 21:11 CMakeLists.txt

-rw-r--r-- 1 root root 2797 Feb 27 21:11 demo.cpp

-rw-r--r-- 1 root root 1532 Feb 27 21:11 load_test.cpp

drwxr-xr-x 4 root root 4096 Feb 27 21:11 testdata

drwxr-xr-x 2 root root 4096 Feb 27 21:11 unittest

3)我们将它拷贝出来

root@iZbp1f6xfzvrfki6wwxqjvZ test# cp demo.cpp ../../

4)此时我们自己创建的目录下有两个文件cppjieba、demo.cpp

root@iZbp1f6xfzvrfki6wwxqjvZ test# ll

total 8

drwxr-xr-x 7 root root 4096 Feb 27 21:11 cppjieba

-rw-r--r-- 1 root root 2797 Feb 27 21:15 demo.cpp

demo.cpp中的内容大致如下:

5)建立软链接 使其能快速找到需要的头文件和词库

root@iZbp1f6xfzvrfki6wwxqjvZ test# ln -s cppjieba/dict dict

查看软链接是否建立

root@iZbp1f6xfzvrfki6wwxqjvZ test# ll

total 8

drwxr-xr-x 7 root root 4096 Feb 27 21:11 cppjieba

-rw-r--r-- 1 root root 2797 Feb 27 21:15 demo.cpp

lrwxrwxrwx 1 root root 13 Feb 27 21:21 dict -> cppjieba/dict

因为cppjieba在include里面,因此我们需要让其找到下述的路径

root@iZbp1f6xfzvrfki6wwxqjvZ test# ls cppjieba/include/cppjieba/

DictTrie.hpp HMMSegment.hpp MixSegment.hpp PreFilter.hpp SegmentTagged.hpp Unicode.hpp

FullSegment.hpp Jieba.hpp MPSegment.hpp QuerySegment.hpp TextRankExtractor.hpp

HMMModel.hpp KeywordExtractor.hpp PosTagger.hpp SegmentBase.hpp Trie.hpp

建立软链接

root@iZbp1f6xfzvrfki6wwxqjvZ test# ln -s cppjieba/include/ inc

6)修改demo.cpp文件如下

7)此时编译会出现如下问题

此时需要将下述文件拷贝下来

root@iZbp1f6xfzvrfki6wwxqjvZ cppjieba# cp deps/limonp include/cppjieba/ -rf

该文件包含了我们需要的头文件,也就是上述报错中缺少的Logging.hpp

7)此时在编译demo.cpp

相关推荐
姜鱼问生5 分钟前
大屏突然 502?一次 Nginx Buffer 溢出引发的血案:upstream sent too big header
运维
深圳市恒星物联科技有限公司18 分钟前
排水管网监测后期运维成本高吗?成本构成与控制策略分析
运维·缓存
Shadow(⊙o⊙)31 分钟前
LangChain 自定义工具全解析:从 @tool 到 bind_tools 的完整调用链路
java·服务器·前端·1024程序员节
Pointer Pursuit32 分钟前
Linux环境变量
linux·服务器·c语言·链表·1024程序员节
星恒随风1 小时前
Linux网络编程基础(二):彻底理解局域网通信、MAC与IP地址、数据封装、端口号、网络字节序及Socket接口
linux·网络·笔记·学习·tcp/ip·1024程序员节
Marst Code1 小时前
(Unix)pipe 把程序当成可组合的函数
服务器·unix
CHHH_HHH1 小时前
【Linux网络篇】初识网络与Socket编程基础
linux·服务器·c语言·开发语言·网络·后端·1024程序员节
AIex-YH1 小时前
发酵罐里点一盏灯:光发酵,正在重算微藻蛋白的成本账
运维·制造·策略模式
郭涤生1 小时前
Jetson Orin 启动链
linux·jetson
jimmyleeee2 小时前
Agent安全之一:Agent Goal Hijack(ASI01)----当智能体“正确地”执行了错误的目标
运维·网络·安全