【实例】python jieba词性标注 并导出txt


>>> import jieba.posseg as pseg

>>> f = open('E:/西方哲学史.txt','r')

      f = f.read()

>>> words = pseg.cut(f)

>>> for w in words:
...  print (w.word,w.flag)
...
Building prefix dict from the default dictionary ...
Loading model from cache C:\Users\d\AppData\Local\Temp\jieba.cache
Loading model cost 0.892 seconds.
Prefix dict has been built succesfully.
西方 s

哲学史 n

-----------------------------------------------------

>>> import re
>>> import jieba

>>> import jieba.posseg as pseg


>>> f = open('E:/西方哲学史.txt','r')
>>> f = f.read()
>>> words = pseg.cut( f)
>>> s = open('E:/s.txt','a+')
>>> for w in words:
...  print(w.word,w.flag,file = s)
...
Building prefix dict from the default dictionary ...
Loading model from cache C:\Users\oil\AppData\Local\Temp\jieba.cache
Loading model cost 1.065 seconds.
Prefix dict has been built succesfully.
>>>

你可能感兴趣的:(python,txt,jieba)