forked from amitKr85/project_student_allocation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_skill_Set.py
140 lines (114 loc) · 4.62 KB
/
make_skill_Set.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
from nltk.stem import WordNetLemmatizer
from nltk.corpus import stopwords
from nltk.corpus import wordnet
import nltk
import pickle
lemmatizer = WordNetLemmatizer()
stop_words = set(stopwords.words("english"))
def get_wordnet_pos(treebank_tag):
if treebank_tag.startswith('J'):
return wordnet.ADJ
elif treebank_tag.startswith('V'):
return wordnet.VERB
elif treebank_tag.startswith('N'):
return wordnet.NOUN
elif treebank_tag.startswith('R'):
return wordnet.ADV
else:
return ''
def make_skill_dict():
topics = open("test_files/finalDict.txt","r").read().split('\n\n')
# print(len(lines))
skill_dict = {}
for topic in topics:
topic_words = []
for i,line in enumerate(topic.split('\n')):
if i == 0:
print("for topic",line)
for top_word in line.split(' '):
if top_word.strip().isalpha():
word = top_word.strip().lower()
wordnet_pos = get_wordnet_pos(nltk.pos_tag([word])[0][1])
if wordnet_pos == '':
word = lemmatizer.lemmatize(word)
else:
word = lemmatizer.lemmatize(word,wordnet_pos)
if word != 'skill' and word not in stop_words:
topic_words.append(word)
print(word,"added")
else:
print("for sbtop",line)
for topic_word in topic_words:
print("for topic word",topic_word," sub_top addred",line)
if topic_word in skill_dict:
skill_dict[topic_word].add(line.lower().strip())
else:
skill_dict[topic_word] = {line.lower().strip()}
for sub_top_word in line.split(' '):
if sub_top_word.strip().isalpha():
word = sub_top_word.strip().lower()
wordnet_pos = get_wordnet_pos(nltk.pos_tag([word])[0][1])
if wordnet_pos == '':
word = lemmatizer.lemmatize(word)
else:
word = lemmatizer.lemmatize(word, wordnet_pos)
if word != 'skill' and word not in stop_words:
if word in skill_dict:
skill_dict[word].add(line.lower().strip())
else:
skill_dict[word] = {line.lower().strip()}
print()
print("printing dict.......")
for key in skill_dict:
print("for key=",key)
for item in skill_dict[key]:
print(item)
pick_file = open("pickled_data/final_skill_dict.pickle","wb")
pickle.dump(skill_dict,pick_file)
pick_file.close()
return skill_dict
def load_skill_set():
skill_dict = dict()
pick_file = open("pickled_data/final_skill_dict.pickle", "rb")
skill_dict = pickle.load(pick_file)
pick_file.close()
return skill_dict
# skill_dict = make_skill_dict()
skill_dict = load_skill_set()
def get_skills(skill_dic,topic):
print("getting skill set for ",topic)
skill_set = set()
for word in topic.split(' '):
print("for word=",word)
if word.strip().isalpha():
word = word.strip().lower()
wordnet_pos = get_wordnet_pos(nltk.pos_tag([word])[0][1])
if wordnet_pos == '':
word = lemmatizer.lemmatize(word)
else:
word = lemmatizer.lemmatize(word, wordnet_pos)
try:
curr_skill_set = skill_dic[word]
print("skill set=",curr_skill_set)
if len(skill_set) == 0:
skill_set = curr_skill_set
else:
skill_set = skill_set.intersection(curr_skill_set)
print("intersection=",skill_set)
except KeyError as e:
print("no skill set found",e)
return skill_set
print(get_skills(skill_dict,'communication development'))
# while True:
# inp = input("input:")
# inp = inp.lower().strip()
# wordnet_pos = get_wordnet_pos(nltk.pos_tag([inp])[0][1])
# if wordnet_pos == '':
# inp = lemmatizer.lemmatize(inp)
# else:
# inp = lemmatizer.lemmatize(inp, wordnet_pos)
#
# try:
# print(skill_dict[inp])
# except Exception as e:
# print("nothing found",e)