对于2-gram 条件下对英语文本的分词处理

来源:互联网 发布:投资网络电影赚钱吗 编辑:程序博客网 时间:2024/05/30 18:30
#coding=utf-8import re#得到1元条件下的分词,并将这些分词加入到listwith 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元分词的方式存入新的listi=0while 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