In [28]:
import pymongo
from pymongo import MongoClient
import text_analysis.dbutil as db
import text_analysis.fileutil as file
import csv
from konlpy.tag import Hannanum
from collections import Counter
# pathname
path = 'data/livetalk.csv'
# get csv data from local
# json = file.get_csv_data(path,'BLTTHG_CNTNT')
with open(path) as csvfile:
reader = csv.DictReader(csvfile)
content = ''
for line in reader:
content += ' ' + line['BLTTHG_CNTNT']
# print(content)
h = Hannanum()
nouns = h.nouns(content)
c = Counter(nouns)
In [27]:
#create MongoClient
client = MongoClient('localhost',27017)
db = client.local
tbl = db.wordcount
#tbl.insert_one()
for word,cnt in c.most_common(50):
#print(word,cnt)
tbl.insert_one({word:cnt})