parse_expert_pdf_utils.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. import re
  2. def date_extraction(content):
  3. """
  4. extracts filing date from the documents.
  5. """
  6. pattern = r"((FILING\sDATE.*?)\d{1,2}\/\d{1,2}\/\d{2,4}|(Date\:\s)\w{1,9}\s\d{1,2}\,\s\d{4}|(Entered\:\s.*?)\w.*?\d{1,2}\,\s\d{4}|(Filed.*?)\d{1,2}\/\d{1,2}\/\d{1,2})" # "((FILING\sDATE.*?)\d{1,2}\/\d{1,2}\/\d{2,4}|(Date\:\s)\w{1,9}\s\d{1,2}\,\s\d{4})"
  7. try:
  8. return re.search(pattern, content).groups()[0]
  9. except:
  10. return "None"
  11. def address_extraction(content):
  12. """
  13. extracts address from the documents.
  14. """
  15. regex_address = r"\w+.*\n\w+.*\n\w+.*\w{2,4}\s\d{5}"
  16. try:
  17. return re.search(regex_address, content).group(0)
  18. except:
  19. return "None"
  20. def refer_exteraction(content):
  21. """
  22. extract referals from the documents.
  23. """
  24. regex = r"(\w+)\srefer?s\sto(.*?)as\s"
  25. # 1. by reference
  26. # 2. In re
  27. # 3. in qoutes ""
  28. try:
  29. print("group1", re.search(regex, content).groups()[0])
  30. except:
  31. return "None"
  32. def case_number_extraction(content):
  33. """
  34. Extracts the case number from the documents.
  35. """
  36. regex = r"Case\sNo\.\s(\d\:\d{2}\-\w{2}\-\d{5}\-\w{3})" # Case\sNo\.\s(\d\:\d{2}\-\w{2}\-\d{5}\-\w{3})
  37. results = set()
  38. case_number = re.compile(regex, re.IGNORECASE)
  39. for current in case_number.finditer(content):
  40. results.add(current.groups()[0])
  41. return list(results)
  42. def expert_name_extraction(content):
  43. """
  44. Extracts the name of the expert from the document.
  45. """
  46. regex = r"(REPORT|DECLARATION)\sOF(\s(DR.)?\s?\w+\s(.*?\.)?\s?\w+)"
  47. try:
  48. return re.search(regex, content).group(2)
  49. except:
  50. return "None"
  51. def plaintiff_extraction(content):
  52. """
  53. Extracts the plaintiff from the document
  54. """
  55. regex = r"(\w.*)\n\s?\n?\s?(Plaintiffs?|Petitioner)"
  56. try:
  57. return re.search(regex, content).group(1)
  58. except:
  59. return "None"
  60. def defendent_extraction(content):
  61. """
  62. Extracts the defendant from the document
  63. """
  64. regex = r"(\w.*?)\n\s?\n?\s?\s?(Defendants|Patent\sOwners?)"
  65. try:
  66. return re.search(regex, content).group(1)
  67. except:
  68. return "None"
  69. def patent_extraction(content):
  70. """
  71. Extracts patent numbers from the document
  72. """
  73. regex = r"\d{1,3}\,\d{1,3}\,\d{3}\,?"
  74. results = []
  75. patent = re.compile(regex, re.IGNORECASE)
  76. for current in patent.finditer(content):
  77. results.append(current.group().replace(",", ""))
  78. return list(set(results))
  79. def law_firm_extraction(content):
  80. regex = r""
  81. results = []
  82. firm = re.compile(regex, re.IGNORECASE)
  83. for current in firm.finditer(content):
  84. results.append(current.groups()[0].strip())
  85. return results
  86. def on_behalf_of_extraction(content):
  87. regex = "on\sbehalf\sof(.*?)(C|c)ase"
  88. on_behalf_of = re.search(regex, content).groups()[0].strip()
  89. return on_behalf_of
  90. def hourly_compensation(content):
  91. """
  92. Returns the hourly compensation of the expert.
  93. """
  94. regex = "\$\s?\d+"
  95. pay = re.findall(regex, content)
  96. return pay
  97. def ref_patents(content):
  98. return
  99. def acronym_extraction(content):
  100. regex = r"\([A-Z]+\)"
  101. # results = []
  102. # acronym = re.compile(regex, re.IGNORECASE)
  103. # for current in acronym.finditer(content):
  104. # results.append(current)
  105. acronym = re.findall(regex, content)
  106. return list(set(acronym))