luoshunchong / NLP_N-gram

分词

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NLP_N-gram

本文部分代码有借鉴https://blog.csdn.net/qq_34307082/article/details/106431277 (N-Gram 分词算法 Python 实现)博客。感谢这篇博客作者的无私分享,支持原作者!!!

本文记录自己学习的过程,害怕遗忘!

分词

文件介绍:

1、test.txt

​ 需要导入的文件

​ 格式:

我	45
你	78894567879970
它	988746576587604453

​ 其中第二列为所要分词的字符

2、test2.txt

​ 写入的文件

​ 格式:

我	45	[]
你	78894567879970	['788', '889', '894', '945', '456', '567', '678', '787', '879', '799', '997', '970', '7889', '8894', '8945', '9456', '4567', '5678', '6787', '7879', '8799', '7997', '9970', '78894', '88945', '89456', '94567', '45678', '56787', '67879', '78799', '87997', '79970']
它	988746576587604453	['988', '887', '874', '746', '465', '657', '576', '765', '658', '587', '876', '760', '604', '044', '445', '453', '9887', '8874', '8746', '7465', '4657', '6576', '5765', '7658', '6587', '5876', '8760', '7604', '6044', '0445', '4453', '98874', '88746', '87465', '74657', '46576', '65765', '57658', '76587', '65876', '58760', '87604', '76044', '60445', '04453']

函数介绍:

text_filter:

文本过滤器:过滤掉文本数据中的标点符号和其他特殊字符

暂时没用到!

slide_word:

滑动取词器
Input: text='abcd',l=2
Output: ['ab','bc','cd']

打开两个txt文件,依次读入将test.txt文件的行,将第二列作为函数slide_word的输入。

如有侵权,请联系我删!!!

About

分词


Languages

Language:Python 100.0%