|
| 1 | +import re |
| 2 | +import PyPDF2 |
| 3 | +import nltk |
| 4 | +from nltk.corpus import stopwords |
| 5 | +from nltk.tokenize import word_tokenize, sent_tokenize |
| 6 | + |
| 7 | +nltk.download('punkt') |
| 8 | +nltk.download('stopwords') |
| 9 | + |
| 10 | + |
| 11 | +# Function to extract text from a PDF file |
| 12 | +def extract_text_from_pdf(pdf_path): |
| 13 | + text = "" |
| 14 | + with open(pdf_path, 'rb') as file: |
| 15 | + reader = PyPDF2.PdfReader(file) |
| 16 | + for page_num in range(len(reader.pages)): |
| 17 | + page = reader.pages[page_num] |
| 18 | + text += page.extract_text() |
| 19 | + return text |
| 20 | + |
| 21 | + |
| 22 | +# Function to analyze the structure of the resume |
| 23 | +def check_structure(text): |
| 24 | + structure_issues = [] |
| 25 | + sections = [ |
| 26 | + 'Education', |
| 27 | + 'Experience', |
| 28 | + 'Skills', |
| 29 | + 'Certifications', |
| 30 | + 'Achievements' |
| 31 | + ] |
| 32 | + for section in sections: |
| 33 | + if section.lower() not in text.lower(): |
| 34 | + structure_issues.append(f"Missing section: {section}") |
| 35 | + return structure_issues |
| 36 | + |
| 37 | + |
| 38 | +# Function to check keyword optimization in the resume |
| 39 | +def keyword_optimization(text, keywords): |
| 40 | + text_tokens = word_tokenize(text.lower()) |
| 41 | + keywords_found = [word for word in text_tokens if word in keywords] |
| 42 | + return keywords_found |
| 43 | + |
| 44 | + |
| 45 | +# Function to check for grammar issues |
| 46 | +def grammar_check(text): |
| 47 | + grammar_issues = [] |
| 48 | + sentences = sent_tokenize(text) |
| 49 | + stop_words = set(stopwords.words('english')) |
| 50 | + |
| 51 | + for sentence in sentences: |
| 52 | + words = word_tokenize(sentence) |
| 53 | + filtered_sentence = [w for w in words if not w.lower() in stop_words] |
| 54 | + # Check basic length and punctuation rules |
| 55 | + if len(filtered_sentence) < 3: |
| 56 | + grammar_issues.append(f"Possible fragment: {sentence}") |
| 57 | + if not re.match(r'.*[.!?]$', sentence.strip()): |
| 58 | + grammar_issues.append(f"Missing punctuation: {sentence}") |
| 59 | + |
| 60 | + return grammar_issues |
| 61 | + |
| 62 | + |
| 63 | +# Main function to run the resume analyzer |
| 64 | +def analyze_resume(pdf_path, keywords): |
| 65 | + text = extract_text_from_pdf(pdf_path) |
| 66 | + |
| 67 | + print("Analyzing structure...") |
| 68 | + structure_issues = check_structure(text) |
| 69 | + if structure_issues: |
| 70 | + print("Structure Issues Found:") |
| 71 | + for issue in structure_issues: |
| 72 | + print(f"- {issue}") |
| 73 | + else: |
| 74 | + print("Structure looks good.") |
| 75 | + |
| 76 | + print("\nAnalyzing keyword optimization...") |
| 77 | + found_keywords = keyword_optimization(text, keywords) |
| 78 | + print(f"Keywords found: {', '.join(found_keywords)}") |
| 79 | + |
| 80 | + print("\nAnalyzing grammar...") |
| 81 | + grammar_issues = grammar_check(text) |
| 82 | + if grammar_issues: |
| 83 | + print("Grammar Issues Found:") |
| 84 | + for issue in grammar_issues: |
| 85 | + print(f"- {issue}") |
| 86 | + else: |
| 87 | + print("No major grammar issues found.") |
| 88 | + |
| 89 | + print("\nAnalysis complete.") |
| 90 | + |
| 91 | + |
| 92 | +if __name__ == "__main__": |
| 93 | + # Keywords to check for in the resume (can be customized) |
| 94 | + resume_keywords = ['python', 'machine learning', 'data analysis', 'sql'] |
| 95 | + |
| 96 | + # Example usage |
| 97 | + resume_path = 'your_resume.pdf' # Replace with the actual file path |
| 98 | + analyze_resume(resume_path, resume_keywords) |
0 commit comments