parse_expert_resume.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. )
  16. def main(PATH):
  17. """
  18. Returns the required data in a dataframe format
  19. """
  20. data_dict = defaultdict(list)
  21. required_files = [file for file in os.listdir(PATH) if file.find(".pdf") != -1]
  22. for idx, file in enumerate(required_files):
  23. print(idx, file)
  24. parse_content = parser.from_file(file)["content"].strip().replace("\n", "")
  25. data_dict["email"].append(extract_email(parse_content))
  26. data_dict["phone"].append(extract_phone(parse_content))
  27. data_dict["zipcode"].append(extract_zipcode(parse_content))
  28. data_dict["cases"].append(extract_case_numbers(parse_content))
  29. data_dict["litigation_experience"].append(
  30. extract_litigation_experience(parse_content)
  31. )
  32. data_dict["patents_issued"].append(extract_patents_issued(parse_content))
  33. return pd.DataFrame(data_dict)
  34. if __name__ == "__main__":
  35. HOME_DIR = os.path.expanduser("~")
  36. BASE_DIR = "Code/pdf_parser/expert_resume"
  37. PATH = os.path.join(HOME_DIR, BASE_DIR)
  38. display(main(PATH))