-
Notifications
You must be signed in to change notification settings - Fork 2
/
handcraft_classify.py
56 lines (45 loc) · 2.19 KB
/
handcraft_classify.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import os
import yaml
import pandas as pd
from subprocess import call
import argparse
from ChatLogParser import TwitchChatParser
from utils import *
parser = argparse.ArgumentParser()
parser.add_argument("-f", "--file", type=str, help="Specify the location of cleaned log file")
parser.add_argument("-t", "--streamer", type=str, help="Specify a twitch streamer's name")
parser.add_argument("-s", "--sentiment", action='store_true', help="Add handed sentiment analysis to cleaned comments")
parser.add_argument("-c", "--class", action='store_true', help="Add handed class analysis to cleaned comments")
parser.add_argument("-a", "--all", action='store_true', help="Add all handed analysis to cleaned comments")
kwargs = vars(parser.parse_args())
streamer = kwargs['streamer'] if kwargs['streamer'] else None
with open('global.yaml', 'r') as f:
_global = yaml.load(f)
streamerDir = os.path.join(_global['STREAMER_DIR'], streamer)
with open(os.path.join(streamerDir, 'local.yaml'), 'r') as f:
_local = yaml.load(f)
log_dir = os.path.join(streamerDir, 'log')
output_dir = os.path.join(streamerDir, 'output')
saved_log_path = os.path.join(output_dir, 'cleaned_%s.txt' % streamer)
meme_file_path = os.path.join(streamerDir, 'memes.txt')
call(['mkdir', '-p', streamerDir + '/output/model'])
if kwargs['file'] is not None:
data = load_logfile(kwargs['file'])
else:
data = load_logfiles_from_dir(log_dir)
text_parser = TwitchChatParser(streamer=streamer)
text_parser.parsing(data, output_dir, remove_repeated_letters=False)
if kwargs['file'] is None:
data = pd.read_table(os.path.join(output_dir, 'cleaned_comments.txt'))
else:
data = pd.read_table(kwargs['file'])
if kwargs['all']:
data['sentiment'] = data.comments.apply(handed_sentiment_tagging)
data['class'] = data.comments.apply(handed_category_tagging, args=(text_parser.emotes, streamer, meme_file_path))
else:
if kwargs['sentiment']:
data['sentiment'] = data.comments.apply(handed_sentiment_tagging)
if kwargs['class']:
data['class'] = data.comments.apply(handed_category_tagging, args=(text_parser.emotes, streamer, meme_file_path))
csv = pd.DataFrame(data)
csv.to_csv(os.path.join(output_dir, 'handed_classification.csv'))