Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract last citation #59

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions scripts/03-parse-inspection-pdfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ def add_bolded(self, text: str) -> None:
def add_narrative(self, text: str) -> None:
assert self.heading
assert self.desc

self.narrative += "\n" + text

def to_dict(self) -> dict[str, typing.Union[str, bool]]:
Expand All @@ -210,6 +211,8 @@ def get_report_body(
for line_words in cluster_objects(words, "top", tolerance=0):
first = line_words[0]
text = " ".join(x["text"] for x in line_words)


addl = text.lower().strip(":") in [
"additional inspectors", # Generic edge-case
"direct", # Specific edge-case from hash_id:0db69ec135a5b244
Expand All @@ -229,6 +232,11 @@ def get_report_body(

full_text.append(cropped.extract_text().strip())

if len(citations):
conclusion_patterns = r"(.*(exit interview|exit.*conducted|additional.*inspectors|end section|exit.*[facility representative | licensee]))"
res = re.search(conclusion_patterns, citations[-1].narrative.lower())
if res:
citations[-1].narrative = citations[-1].narrative[0:res.start()]
return ([v.to_dict() for v in citations], "\n\n".join(full_text))


Expand Down