janome
janomeのインストール
pip install janome
janomeの使い方
code:python
from janome.tokenizer import Tokenizer
from janome.analyzer import Analyzer
from janome.tokenfilter import *
CSVを読み込んで分析する
code:python
import csv
csv_file = open("./yuiseki.csv", "r", encoding="utf8", errors="", newline="" )
rows = csv.reader(csv_file, delimiter=",", doublequote=False, lineterminator="\r\n", quotechar='"', skipinitialspace=True)
for row in rows:
Twitter APIが使える場合
code:python
import twitter
api = twitter.Api(consumer_key='xxx',
consumer_secret='xxx',
access_token_key='xxx',
access_token_secret='xxx')
i = 0
max_id = 0
while i < 10:
print(".", end="")
i=i+1
if max_id is not 0:
results = api.GetSearch(term="竹達彩奈 exclude:retweets", lang="ja", result_type="recent", count=100, max_id=max_id)
else:
results = api.GetSearch(term="竹達彩奈 exclude:retweets", lang="ja", result_type="recent", count=100)
counts = dict()
for result in results:
if max_id is 0 or result.id < max_id:
max_id = result.id
text = result.text.replace('\n','')
count = dict(analizer.analyze(text))
counts.update(count)
print("sort start")
counts = dict(sorted(counts.items(), key=lambda x: x1)) print(counts)