TopPage

  1. 参考サイト http://d.hatena.ne.jp/nokuno/20100123/1264239192
  2. 日本語テキストを読み込むサンプルプログラム
    	#! /usr/bin/env python
    	#encoding: utf-8
    	import nltk
    	
    	raw = open('./sample.mecab').read()
    	words = raw.split();
    	print len(words)
    	text = nltk.Text(words)
    	gen = text.generate(300)
    	print gen

ディレクトリ下の*.datファイルを読み込み、その中からtweetを抽出する。(筆跡:Ashihara)

   #vim fileencoding:utf-8 
   import commands
   import codecs
   list = commands.getoutput('ls *.dat')
   fileList = list.split("\n")
   datList = []
   for file in fileList:
           for dat in codecs.open(file,'r','utf-8'):
                   datList.append(dat.encode('utf-8'))
   tweetList = []
   swaplist = []
   tw = str()
   for dats in datList:
           swaplist = dats.split()
           index = swaplist.index('2010')#2010以下がtweet
           tw = ""
           for tweet in swaplist[index + 1:]:
                   tw += tweet
           tweetList.append(tw)
   f = open('tweetList.txt', 'w')
   for tweet in tweetList:
           f.write(tweet+'\n')
   f.close()