fix(ingest): support .txt sources + fix citing_id FK violation #7

Merged
user2595 merged 1 commits from fix/ingest-txt-and-citing-id into main 2026-06-14 13:56:05 +00:00

View File

@@ -139,6 +139,8 @@ def ingest_paper(
if suffix == ".tex":
text = latex_to_text(Path(source_path).read_text())
elif suffix == ".txt":
text = Path(source_path).read_text(encoding="utf-8", errors="replace")
elif suffix == ".pdf":
text = pdf_to_markdown(source_path)
# Also extract GROBID refs
@@ -176,7 +178,10 @@ def ingest_paper(
# ---------------------------------------------------------------
api_citations: list[Citation]
if paper.openalex_id:
api_citations = openalex.fetch_citations(paper.openalex_id)
raw = openalex.fetch_citations(paper.openalex_id)
# OpenAlex returns citing_id=openalex_id, but papers.id uses the DOI.
# Rewrite citing_id to paper.id so the FK constraint is satisfied.
api_citations = [Citation(citing_id=paper.id, cited_id=c.cited_id, context=c.context) for c in raw]
else:
api_citations = semanticscholar.fetch_references(paper_id)