#coding=utf-8 import re #得到1元条件下的分词,并将这些分词加入到list中 with open('/home/zheng/firstproject/lecture.txt', 'r') as lecture: content = lecture.read().strip().decode('gbk').encode('utf-8') lecture_list = re.findall('([A-Za-z\']+)', content) # print lecture_list n=len(lecture_list)#计算list表中的单词总数 new_list = []#构建一个新的list #将list表中的数据以2元分词的方式存入新的list中 i=0 while i<n-1: j=1 while j<n: new_list.append(lecture_list[i] + ' ' + lecture_list[j]) j+=1 i+=1 while j>=n: print new_list break
对于2-gram 条件下对英语文本的分词处理
最新推荐文章于 2021-05-19 12:23:27 发布