数学の道(マシン学習実践ガイド)-テキストマイニングとNLP(3)

1419 ワード

#--coding:utf-8--
#code by myhaspl 
from __future__ import unicode_literals
from __future__ import division


import nltk


import sys
sys.path.append("../")

import jieba


def cutstring(txt):
    #  http://blog.csdn.net/myhaspl
    cutstr = jieba.cut(txt)
    result=" ".join(cutstr)
    return result
    
#    http://blog.csdn.net/myhaspl
txtfileobject = open('test2.txt','r')

try:
   filestr = txtfileobject.read( )
finally:
   txtfileobject.close( )

cutstr=cutstring(filestr)
tokenstr=nltk.word_tokenize(cutstr)

fdist=nltk.FreqDist(tokenstr)

#      ,          http://blog.csdn.net/myhaspl   
print "----  -----"
fdist1=nltk.FreqDist([len(w) for w in tokenstr])
for w,c  in fdist1.items():
    print w,"=>",c,"||",
#  http://blog.csdn.net/myhaspl
print
print "----  -----"
print fdist1.keys()

# http://blog.csdn.net/myhaspl
print 
print "---  ---"
fdist2=nltk.FreqDist(tokenstr)
for w,c  in fdist2.items():
    print w,"=>",c,"||",
このブログの内容はすべてオリジナルです。転載したら、ソースを明記してください。
http://blog.csdn.net/myhaspl/
语频----------------------------------------------------------------------[1、2、3、4、5、6]---脳の意识が高まっている----------------[1、2、3、4、5、6]---意识が高まって、脳の意识が高まってきます。=>1𞓜𞓜一方=>1 124124; 124124124124;𞓜特性=>1 124124124;テレビ視聴者=>1 124124124124124124;窓=>1 124124124124124;聖哲=