forked from coffee-cup/mbti
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
76 lines (54 loc) · 1.8 KB
/
utils.py
File metadata and controls
76 lines (54 loc) · 1.8 KB
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
68
69
70
71
72
73
74
75
76
# Utils file for useful functions
import os
import numpy as np
from config import parse_config, print_usage
first_codes = ['I', 'E']
second_codes = ['S', 'N']
third_codes = ['T', 'F']
fourth_codes = ['J', 'P']
codes = [first_codes, second_codes, third_codes, fourth_codes]
FIRST = 0
SECOND = 1
THIRD = 2
FOURTH = 3
ALL = 16
personality_types = [
'ISTJ', 'ISFJ', 'INFJ', 'INTJ', 'ISTP', 'ISFP', 'INFP', 'INTP', 'ESTP',
'ESFP', 'ENFP', 'ENTP', 'ESTJ', 'ESFJ', 'ENFJ', 'ENTJ'
]
def one_hot_encode_type(t):
i = personality_types.index(t)
Y = np.zeros(len(personality_types))
Y[i] = 1
return Y.astype(int).tolist()
def one_hot_to_type(Y):
i = np.where(np.array(Y) == 1)[0][0]
return personality_types[i]
def get_binary_for_code(code, personality_type):
c = codes[code]
return int(personality_type[code] != c[0])
def get_char_for_binary(code, binary):
if type(binary) is list:
binary = binary[0]
c = codes[code]
return c[binary]
def get_config(return_unparsed=False):
"""Gets config and creates data_dir."""
config, unparsed = parse_config()
# If we have unparsed args, print usage and exit
if len(unparsed) > 0 and not return_unparsed:
print_usage()
exit(1)
def append_data_dir(p):
return os.path.join(config.data_dir, p)
# Append data_dir to all filepaths
config.pre_save_file = append_data_dir(config.pre_save_file)
config.raw_csv_file = append_data_dir(config.raw_csv_file)
config.embeddings_model = append_data_dir(config.embeddings_model)
config.embeddings_file = append_data_dir(config.embeddings_file)
# Create data_dir if it doesn't exist
if not os.path.exists(config.data_dir):
os.makedirs(config.data_dir)
if return_unparsed:
return config, unparsed
return config