MCPcopy Create free account
hub / github.com/917Dhj/DeepPaperNote / _reference_lines_from_pdf

Function _reference_lines_from_pdf

scripts/citation_links.py:42–61  ·  view source on GitHub ↗
(pdf_path: Path, references_start_page: int, max_pages: int)

Source from the content-addressed store, hash-verified

40
41
42def _reference_lines_from_pdf(pdf_path: Path, references_start_page: int, max_pages: int) -> list[tuple[str, int]]:
43 if fitz is None or references_start_page < 1 or max_pages < 1:
44 return []
45 doc = fitz.open(pdf_path)
46 try:
47 start_index = max(0, references_start_page - 1)
48 stop_index = min(len(doc), start_index + max_pages)
49 lines: list[tuple[str, int]] = []
50 for page_index in range(start_index, stop_index):
51 page_number = page_index + 1
52 for raw_line in doc[page_index].get_text("text").splitlines():
53 line = normalize_whitespace(raw_line)
54 if not line:
55 continue
56 if line.lower() in {"references", "bibliography", "参考文献"}:
57 continue
58 lines.append((line, page_number))
59 return lines
60 finally:
61 doc.close()
62
63
64def _group_numbered_references(lines: list[tuple[str, int]]) -> list[tuple[str, int]]:

Callers 1

Calls 4

normalize_whitespaceFunction · 0.90
openMethod · 0.45
get_textMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected