forked from adwait-thattey/stackoverflow_api_recommender
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
53 lines (41 loc) · 1.6 KB
/
utils.py
File metadata and controls
53 lines (41 loc) · 1.6 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
import constants
import os
import log
import shared
import nltk
import random
def enforce_types(*types, return_type=None):
def decorator(f):
def new_f(*args, **kwds):
# we need to convert args into something mutable
for (a, t) in zip(args, types):
if not isinstance(a, t):
raise TypeError(" [Enforced Types]: Arguments of wrong type passed to function")
# feel free to have more elaborated convertion
result = f(*args, **kwds)
if return_type:
if not isinstance(result, return_type):
raise TypeError(
f" [Enforced Types]: Function returned wrong type \n Expected {repr(return_type)}. Received {type(result)} ")
return result
return new_f
return decorator
def gen_stopwords():
log.log(f"generating Stop Words", module="utils")
try:
stopwords = nltk.corpus.stopwords
stop_words = set(stopwords.words('english'))
shared.STOP_WORDS = stop_words
except LookupError:
nltk.download('stopwords')
log.log(
f"Could not generate stop words. Downloaded the nltk english dataset. \n Recommended to close and run program again \n Press Enter to continue",
module="utils")
input()
def get_new_question_segment_id():
file_list = [f for f in os.listdir(constants.pickled_questions_dir) if
os.path.isfile(os.path.join(constants.pickled_questions_dir, f))]
start = 1
while str(start) in file_list:
start += 1
return start