TopPage

nltkでtwitterのログを処理する。

  1. TwitterLog20100805 を自分のディレクトリにコピーする
    	cp -r /home/maeda/TwitterLog/20100805/ .
  2. 参考サイト http://d.hatena.ne.jp/nokuno/20100123/1264239192
  3. 日本語テキストを読み込むサンプルプログラム
    	#! /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
  4. bigrams
    	#!/usr/bin/python
    	#encoding: utf-8
    	import nltk
    	
    	raw = open('sample.dat').read()
    	words = raw.split();
    	bigrams = nltk.bigrams(words)
    	fd = nltk.FreqDist(bigrams)
    	for w in fd:
    	        if fd[w]==100 :
    	                break;
    	        print w[0],w[1],fd[w]
    	
    	#文字化けする
    	cfd = nltk.ConditionalFreqDist(bigrams)
    	print cfd['私']
  5. 24時間x60分=1440ファイルを分かち書きにする

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

復習問題