This repository has been archived by the owner on Jan 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.py
68 lines (46 loc) · 1.52 KB
/
helpers.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
57
58
59
60
61
62
63
64
65
66
67
import os
from config import database_path, data_path, filename_regex, prepare_path
def get_dataset_path(timeframe):
return os.path.join(data_path, timeframe)
def get_timeframe_path(timeframe):
return os.path.join(data_path, f"RC_{timeframe}")
def get_db_path(timeframe):
return os.path.join(database_path, f"{timeframe}.db")
def get_timeframes():
timeframes = []
for f in os.listdir(data_path):
if os.path.isfile(get_dataset_path(f)):
print(f)
match = filename_regex.match(f)
if match is not None:
timeframe = match.group(1)
timeframes.append(timeframe)
return timeframes
def create_table_if_not_exists(cursor):
cursor.execute("""CREATE TABLE IF NOT EXISTS parent_reply (
parent_id TEXT PRIMARY KEY,
comment_id TEXT UNIQUE,
parent TEXT,
comment TEXT,
subreddit TEXT,
unix INT,
score INT
)""")
def format_data(data):
data = data.replace('\n', ' newlinechar ').replace('\r', ' newlinechar ').replace('"', "'")
return data
def acceptable(data):
if len(data.split(' ')) > 1000 or len(data) < 1:
return False
elif len(data) > 32000:
return False
elif data == '[deleted]':
return False
elif data == '[removed]':
return False
else:
return True
def get_test_path(variant):
return os.path.join(prepare_path, f"test.{variant}")
def get_train_path(variant):
return os.path.join(prepare_path, f"train.{variant}")