forked from ShehryarX/h-parse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parseResume.py
393 lines (357 loc) · 17.6 KB
/
parseResume.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
from __future__ import with_statement
import urllib
import re, collections
import os
import tokenize
import pdfParse
import getCategory
import difflib
import subprocess
def init():
filename = raw_input("Name of directory: ")
target = raw_input("Job position target: ")
temp = raw_input("Field of study: ")
cats = ["Programming Languages", "Computer Science", "Engineering", "Finance", "Business Management", "the Arts"]
for i in range(len(cats)):
cats[i] = None
fout = open("results.tex", "w")
fout.write("\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\
\\title{Results}\n\\begin{document}\n\n")
fout.close()
if filename == " ":
return ("", "")
elif os.path.isdir(filename):
resumes = []
for doc in os.listdir(filename):
if doc.endswith(".pdf"):
resume = pdfParse.convert(os.path.join(filename,doc))
resumes.append(resume)
else:
resume = readFile(os.path.join(filename,doc)).lower()
resumes.append(resume)
return (resumes, cats)
elif filename.endswith(".pdf"):
resume = pdfParse.convert(filename)
else:
resume = readFile(filename).lower()
return (resume, cats)
def category(resume, progWords = None, csWords = None, engWords = None, finWords = None, manWords = None, artWords = None):
(cat, score) = getCategory.mainCategoryAndScore(resume, progWords, csWords, engWords, finWords, manWords, artWords)
return (cat, score)
def overall(resume):
overall = getCategory.getCategoriesAverage(resume)
fout = open("results.tex", "a")
fout.write("\\textbf{Average Score: } " + str(tenOverall(overall)) + "\\\\\n")
fout.close()
return overall
def tenCategory(score):
return score / 2.5
def tenOverall(score):
return score / 1.5
def programmingScore(resume):
proScore = getCategory.programmingScore(resume)
fout = open("results.tex", "a")
fout.write("score: "+ str(tenProgScore(proScore)) + "\\\\\n")
fout.close()
return proScore
def tenProgScore(score):
return score * 2
def gpaScoreCalculator(gpa):
gpa_unweighted = gpa / 4.00
gpa_scaled = gpa_unweighted * 10
return gpa_scaled
def gpaScore(word_tokens):
score = 0
gpaFound = False
for token in word_tokens:
if "gpa" in token.lower():
index = word_tokens.index(token)
try:
if "/" in word_tokens[index + 1]:
words = word_tokens[index + 1].split("/")
gpa = float(words[0])
score = gpaScoreCalculator(gpa)
gpaFound = True
else:
gpa = float(word_tokens[index + 1])
score = gpaScoreCalculator(gpa)
gpaFound = True
except:
if "/" in word_tokens[index - 1]:
words = word_tokens[index - 1].split("/")
gpa = float(words[0])
score = gpaScoreCalculator(gpa)
gpaFound = True
else:
gpa = float(word_tokens[index - 1])
score = gpaScoreCalculator(gpa)
gpaFound = True
fout = open("results.tex", "a")
if gpaFound == False:
fout.write("\\textbf{GPA: not found}\\\\\n")
score = gpaScoreCalculator(2.5)
else:
fout.write("\\textbf{GPA: " + str(gpa) +"}\\\\\n")
fout.close()
return score
def collegeScore(word_tokens):
university = ["Carnegie Mellon University", "Princeton University",
"Harvard University", "Yale University", "Columbia University",
"Stanford University", "University of Chicago", "Marc Garneau Collegiate Institute",
"Duke University",
"University of Pennsylvania", "California Institute of Technology",
"Johns Hopkins University", "Dartmouth College", "Northwestern University",
"Brown University", "Cornell University", "Vanderbilt University",
"Washington University in St. Louis", "Rice University",
"University of Notre Dame", "University of California-Berkeley",
"Emory University", "Georgetown University",
"University of California-Los Angeles", "University of Southern California",
"University of Virginia", "Tufts University", "Wake Forest University",
"University of Michigan-Ann Arbor", "Boston College",
"University of North Carolina-Chapel Hill", "New York University", "University of Rochester",
"Brandeis University", "College of William and Mary", "Georgia Institute of Technology",
"Case Western Reserve University", "University of California-Santa Barbara",
"University of California-San Diego", "Boston University", "Rensselaer Polytechnic Institute",
"Tulane University", "University of California-Davis", "University of Illinois-Urbana-Champaign",
"University of Wisconsin-Madison", "Lehigh University", "Northeastern University",
"Pennsylvania State University-University Park", "University of Florida", "University of Miami",
"Ohio State University-Columbus", "Pepperdine University", "University of Texas-Austin",
"University of Washington", "Yeshiva University", "George Washington University",
"University of Connecticut", "University of Maryland-College Park",
"Worchester Polytechnic Institute", "Clemson University", "Purdue University-West Lafayette",
"Southern Methodist University", "Syracuse University", "University of Georgia",
"Brigham Young University-Provo", "Fordham University", "University of Pittsburgh",
"University of Minnesota-Twin Cities", "Texas A&M University-College Station", "Virginia Tech",
"American University", "Baylor University", "Rutgers, The State University of New Jersey-New Brunswick",
"Clark University", "Colorado School of Mines", "Indiana University-Bloomington",
"Michigan State University", "Stevens Institute of Technology", "University of Delaware",
"University of Massachusetts-Amherst", "Miami University-Oxford", "Texas Christian University",
"University of California-Santa Cruz", "University of Iowa", "Marquette University",
"University of Denver", "University of Tulsa", "Binghamton University-SUNY",
"North Carolina State University-Raleigh", "Stony Brook University-SUNY",
"SUNY College of Environmental Science and Forestry", "University of Colorado-Boulder",
"University of San Diego", "University of Vermont", "Florida State University", "Saint Louis University",
"University of Alabama", "Drexel University", "Loyola University Chicago", "University at Buffalo-SUNY",
"Auburn University", "University of Missouri", "University of Nebraska-Lincoln",
"University of New Hampshire", "University of Oregon", "University of Tennessee",
"Illinois Institute of Technology", "Iowa State University", "University of Dayton",
"University of Oklahoma", "University of San Francisco", "University of South Carolina",
"University of the Pacific", "Clarkson University", "Duquesne University", "Temple University",
"University of Kansas", "University of St. Thomas", "University of Utah", "University of Arizona",
"University of California-Riverside", "The Catholic University of America", "DePaul University",
"Michigan Technological University", "Seton Hall University", "Colorado State University", "New School",
"Arizona State University-Tempe", "Louisiana State University-Baton Rouge", "University at Albany-SUNY",
"University of Arkansas", "University of Illinois-Chicago", "University of Kentucky",
"George Mason University", "Hofstra University", "Howard University", "Ohio University",
"Oregon State University", "New Jersey Institute of Technology",
"Rutgers, The State University of New Jersey-Newark", "University of Cincinnati",
"University of Mississippi", "University of Texas-Dallas", "Washington State University",
"Kansas State University", "Missouri University of Science & Technology", "St. John Fisher College",
"Illinois State University", "Oklahoma State University", "San Diego State University",
"University of Alabama-Birmingham", "Adelphi University", "Southern Illinois University-Carbondale",
"St. John's University", "University of Maryland-Baltimore County", "University of Massachusetts-Lowell",
"University of South Florida", "Virginia Commonwealth University", "University of La Verne",
"Biola University", "Florida Institute of Technology", "Immaculata University",
"Maryville University of St. Louis", "Mississippi State University", "University of Hawaii-Manoa",
"University of Rhode Island", "Ball State University", "Texas Tech University",
"University of Central Florida", "University of Idaho", "University of Louisville", "University of Maine",
"University of Wyoming", "Andrews University", "Azusa Pacific University", "Edgewood College",
"Kent State University", "West Virginia University", "Pace University",
"St. Mary's University of Minnesota", "University of New Mexico", "University of North Dakota",
"University of South Dakota", "Bowling Green State University", "North Dakota State University",
"South Dakota State University", "University of Alabama-Huntsville", "University of Houston",
"University of Nevada-Reno", "University of North Carolina-Greensboro", "Western Michigan University",
"Widener University", "Central Michigan University", "East Carolina University",
"South Carolina State University", "University of Missouri-Kansas City",
"University of North Carolina-Charlotte", "Ashland University",
"Indiana University-Purdue University-Indianapolis", "Louisiana Tech University",
"New Mexico State University", "University of Colorado-Denver", "Marc Garneau Collegiate Institute",
"University of Waterloo"]
short_words = ["university", "for", "and", "get", "the", "art", "ice", "town", "park", "van", "los"]
i = 0
fout = open("results.tex", "a")
for college in university:
for word in word_tokens:
if((word.lower() not in short_words) and (word in college) and (len(word) > 2)):
fout.write("\\textbf{"+ college + "}")
i = university.index(college)
i = i + 1
break
if(i != 0):
break
score = ((200-i)/200.0) * 15
fout.write(" \\textbf{score:} " + str(tenUniversity(score)) + "\\\\\n")
fout.close()
return score
def tenUniversity(score):
return score / 1.5
def wordCountScore(tokens):
score = 10
count = 0
for tok in tokens:
if tok != "":
count += 1
if count == 400: score -= 0
else:
score -= min(abs(400 - count) / 20, 5)
return score
def degreeScore(word_tokens):
score = 10
desiredDegree = raw_input("Search Degree: ")
word_tokens_lower = [x.lower() for x in word_tokens]
degree = difflib.get_close_matches(desiredDegree.lower(), word_tokens_lower)
close_match_fail = False
close_match = ""
if degree == []:
for word in word_tokens_lower:
if (desiredDegree.lower() in word):
close_match_fail = True
close_match = word
break
stop_search = False
while (not stop_search):
if degree == [] and close_match_fail == False:
answer2 = raw_input("There are no matches. Search again? ")
if answer2 == "Y" or answer2 == "y" or answer2 == "yes" or answer2 == "Yes":
desiredDegree = raw_input("Required degree level: ")
degree = difflib.get_close_matches(desiredDegree.lower(), word_tokens_lower)
else:
stop_search = True
else:
if close_match_fail == True:
print("Closest match to " + desiredDegree + " is " +
close_match + ".")
stop_search = True
else:
print("Closest match to " + desiredDegree + " is " +
degree[0] + ".")
stop_search = True
close_match_fail = False
close_match = ""
stop_search = False
while (not stop_search):
answer1 = raw_input("Search for another degree? ")
if answer1 == "Y" or answer1 == "y" or answer1 == "yes" or answer1 == "Yes":
desiredDegree = raw_input("Required degree level: ")
degree = difflib.get_close_matches(desiredDegree.lower(), word_tokens_lower)
if degree == []:
for word in word_tokens_lower:
if (desiredDegree.lower() in word):
close_match_fail = True
close_match = word
break
if degree == [] and close_match_fail == False:
answer3 = raw_input("There are no matches. Search again? ")
if answer3 == "Y" or answer3 == "y" or answer3 == "yes" or answer3 == "Yes":
desiredDegree = raw_input("Required degree level: ")
degree = difflib.get_close_matches(desiredDegree.lower(), word_tokens_lower)
else:
stop_search = True
else:
if close_match_fail == True:
print("Closest match to " + desiredDegree + " is " +
close_match + ".")
else:
print("Closest match to " + desiredDegree + " is " +
degree[0] + ".")
else:
stop_search = True
degreeFound = False
answer4 = raw_input("Search for word \"degree\"? ")
if answer4 == "Y" or answer4 == "y" or answer4 == "yes" or answer4 == "Yes":
print("Searching...")
for word in word_tokens_lower:
if ("degree" in word):
index = word_tokens_lower.index(word)
if index - 1 >= 0 and index + 1 < len(word_tokens_lower):
prev_word = word_tokens_lower[index - 1]
after_word = word_tokens_lower[index + 1]
print("Word before 'degree': " + prev_word)
print("Word after 'degree': " + after_word)
degreeFound = True
break
elif index - 1 >= 0 and index + 1 >= len(word_tokens_lower):
prev_word = word_tokens_lower[index - 1]
print("Word before 'degree': " + prev_word + "\n")
print("No word found after 'degree'.")
degreeFound = True
break
elif index - 1 < 0 and index + 1 < len(word_tokens_lower):
after_word = word_tokens_lower[index + 1]
print("Word after 'degree': " + after_word + "\n")
print("No word found before 'degree'.")
degreeFound = True
break
else:
print("The only word in the resume is 'degree'.")
degreeFound = True
break
if degreeFound == False:
print("The word 'degree' does not appear in the resume.")
else:
pass
answer = raw_input("Was the search sufficient? ")
if answer == "yes" or answer == "Y" or answer == "y" or answer == "Yes": score -= 0
else: score -= 10
return score
def sectionScore(resume):
section_tokens = tokenize.input_file_words(resume,[])
currentIndex = -1
wordCount = [0,0,0]
for x in section_tokens:
x = x.lower()
if(x.strip("!@#$%^&*()_+|}{:?") in ["work experience", "employment", "experience"] and currentIndex != 0):
currentIndex = 0
elif(x.strip("!@#$%^&*()_+|}{:?") in ["publications", "projects", "research"] and currentIndex != 1):
currentIndex = 1
elif(x.strip("!@#$%^&*()_+|}{:?") in ["leadership","leadership experience"] and currentIndex != 2):
currentIndex = 2
elif(x.strip("!@#$%^&*()_+|}{:?") in ["education","activites","skils", "interests", "extracurricular", "honors", "references", "awards", "acheivements"]):
currentIndex = -1
else:
wordCount[currentIndex] += 1
return min(((sum(wordCount) - min(wordCount))) / 450.0, 1.0) * 10
def main(resume, cats):
tokens = tokenize.input_file_lines(resume,[])
word_tokens = tokenize.input_file_words(resume,[])
score = 0
email = ""
for token in word_tokens:
if "@" in token:
email = token
break
fout = open("results.tex", "a")
fout.write("\\section{" + email +"}\n")
fout.close()
(cat, category_score) = category(resume, cats[0],cats[1],cats[2],cats[3],cats[4],cats[5])
overall_score = overall(resume)
programming_score = programmingScore(resume)
gpa_score = gpaScore(word_tokens)
college_score = collegeScore(word_tokens)
word_count_score = wordCountScore(tokens)
degree_score = degreeScore(word_tokens)
section_score = sectionScore(resume)
print "Finished parsing."
score = category_score + overall_score + programming_score + \
gpa_score + college_score + word_count_score + \
degree_score + section_score
fout = open("results.tex", "a")
fout.write("\\textbf{Best category: } "+cat+"\\\\\n\
\\textbf{Overall Score: }"+ str(score/ 10.0) + " (out of 10)")
fout.close()
return (cat, score, email)
def readFile(filename, mode="rt"):
with open(filename, mode) as fin:
return fin.read()
(resume, cats) = init()
if type(resume) == list:
for i in range(len(resume)):
print main(resume[i], cats)
fout = open("results.tex", "a")
fout.write("\\end{document}")
fout.close()
elif resume != "":
print main(resume, cats)
fout = open("results.tex", "a")
fout.write("\\end{document}")
fout.close()