Skip to content

Instantly share code, notes, and snippets.

@goodbyegangster
Last active October 27, 2021 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goodbyegangster/0dbdc9164935ac28e4f66a4c9f3ce6f9 to your computer and use it in GitHub Desktop.
Save goodbyegangster/0dbdc9164935ac28e4f66a4c9f3ce6f9 to your computer and use it in GitHub Desktop.
negative-positive analyzer script for shikiho-data
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import csv, glob, MeCab
result_file = "XXXXXXXX"
dic_file = "XXXXXXXX"
shikiho_file = "XXXXXXXX"
headmsg = ["code","comment","value"]
wordtable = {}
with open(dic_file, newline="") as dicfile:
dic = csv.reader(dicfile, delimiter=":")
for row in dic:
wordtable[row[0]] = row[3]
m = MeCab.Tagger("")
with open(result_file, "w") as resultfile:
csvwriter = csv.writer(resultfile, quoting=csv.QUOTE_ALL)
csvwriter.writerow(headmsg)
output_files = glob.glob(shikiho_file)
for output_file in output_files:
with open(output_file, newline="") as outputs:
value_list = []
output = csv.reader(outputs)
next(output, None)
for row in output:
m.parse("")
node = m.parseToNode(row[12]+row[13])
while node:
featurelist = node.feature.split(",")
if featurelist[0] in ["名詞", "動詞", "形容詞", "副詞"]:
for key, value in wordtable.items():
if featurelist[6] == key:
value_list.append(float(value))
node = node.next
csvwriter.writerow([row[0],row[12]+row[13],sum(value_list)/len(value_list)])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment