Ⅰ python将怎么将jieba分词结果写入文本,各种编码问题啊
能不能解释下“jieba分词”啊
Ⅱ python3怎么使用结巴分词
下面这个程序是对一个文本文件里的内容进行分词的程序:test.py
[python] view plain
#!/usr/bin/python
#-*-encoding:utf-8-*-
importjieba#导入jieba模块
defsplitSentence(inputFile,outputFile):
fin=open(inputFile,'r')#以读的方式打开文件
fout=open(outputFile,'w')#以写得方式打开文件
foreachLineinfin:
line=eachLine.strip().decode('utf-8','ignore')#去除每行首尾可能出现的空格,并转为Unicode进行处理
wordList=list(jieba.cut(line))#用结巴分词,对每行内容进行分词
outStr=''
forwordinwordList:
outStr+=word
outStr+='/'
fout.write(outStr.strip().encode('utf-8')+' ')#将分词好的结果写入到输出文件
fin.close()
fout.close()
splitSentence('myInput.txt','myOutput.txt')
写完程序之后,在Linux重点输入:python test.py即可运行程序进行分词。
输入的文件内容如下所示:
注意:第11行的 jieba.cut()返回的结构是一个可迭代的generator,可以用list(jieba.cut(...))转化为list
Ⅲ python jieba 分词 打印
这个问题是因为在控制台输出的原因,你可以尝试输出到表格或者txt。在看下是否有空行
Ⅳ 如何用python和jieba分词,统计词频
#!python3
#-*-coding:utf-8-*-
importos,codecs
importjieba
fromcollectionsimportCounter
defget_words(txt):
seg_list=jieba.cut(txt)
c=Counter()
forxinseg_list:
iflen(x)>1andx!=' ':
c[x]+=1
print('常用词频度统计结果')
for(k,v)inc.most_common(100):
print('%s%s%s%d'%(''*(5-len(k)),k,'*'*int(v/3),v))
if__name__=='__main__':
withcodecs.open('19d.txt','r','utf8')asf:
txt=f.read()
get_words(txt)
Ⅳ python 使用jieba分词出错
在你的第一行,用#coding=utf-8 试试
Ⅵ python jieba什么用
- python安装jieba分词,运行ytho程序,遇到错误“Nomoleamedjiea”,说明你需要安装jiea
Ⅶ 怎么是用python 语言 使用结巴分词 呢
Python代码
#encoding=utf-8
importjieba
seg_list=jieba.cut("我来到北京清华大学",cut_all=True)
print"FullMode:","/".join(seg_list)#全模式
seg_list=jieba.cut("我来到北京清华大学",cut_all=False)
print"DefaultMode:","/".join(seg_list)#默认模式
seg_list=jieba.cut("他来到了网易杭研大厦")
print",".join(seg_list)
输出:
FullMode:我/来/来到/到/北/北京/京/清/清华/清华大学/华/华大/大/大学/学
DefaultMode:我/来到/北京/清华大学
他,来到,了,网易,杭研,大厦(此处,“杭研”并没有在词典中,但是也被Viterbi算法识别出来了)
Ⅷ python如何装jieba库
pip install jieba