parse_expert_resume.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. from collections import defaultdict
  2. import os
  3. from IPython.display import display
  4. import tika
  5. import pandas as pd
  6. tika.initVM()
  7. from tika import parser
  8. from parse_resume_utils import (
  9. extract_email,
  10. extract_phone,
  11. extract_zipcode,
  12. extract_case_numbers,
  13. extract_litigation_experience,
  14. extract_patents_issued,
  15. extract_name,
  16. )
  17. def main(PATH):
  18. """
  19. Returns the required data in a dataframe format
  20. """
  21. data_dict = defaultdict(list)
  22. required_files = [file for file in os.listdir(PATH) if file.find(".pdf") != -1]
  23. for idx, file in enumerate(required_files):
  24. print(idx, file)
  25. parse_content = parser.from_file(file)["content"]
  26. data_dict["name"].append(extract_name(parse_content))
  27. data_dict["email"].append(extract_email(parse_content))
  28. data_dict["phone"].append(extract_phone(parse_content))
  29. data_dict["zipcode"].append(extract_zipcode(parse_content))
  30. data_dict["cases"].append(extract_case_numbers(parse_content))
  31. data_dict["litigation_experience"].append(
  32. extract_litigation_experience(parse_content)
  33. )
  34. data_dict["patents_issued"].append(extract_patents_issued(parse_content))
  35. data = pd.DataFrame(data_dict)
  36. data.to_csv("required_data.csv")
  37. return data
  38. if __name__ == "__main__":
  39. HOME_DIR = os.path.expanduser("~")
  40. BASE_DIR = "Code/pdf_parser/expert_resume"
  41. PATH = os.path.join(HOME_DIR, BASE_DIR)
  42. display(main(PATH))