Spaces:
Runtime error
Runtime error
| import os | |
| import sys | |
| sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | |
| from plagdetect.websearch import dedupe_candidates | |
| # Simulate: OpenAlex found a Nature paper but LOCKED (no pdf_url); | |
| # CORE found the SAME paper (same DOI) with an OA repository PDF. | |
| openalex_locked = { | |
| "title": "A Deep Learning Framework for Protein Folding", | |
| "doi": "10.1038/s41586-021-03819-2", "pdf_url": None, "fulltext": "", | |
| "abstract": "", "provider": "openalex", | |
| } | |
| core_oa = { | |
| "title": "A deep learning framework for protein folding", # case differs | |
| "doi": "10.1038/s41586-021-03819-2", | |
| "pdf_url": "https://repository.example.edu/oa/protein.pdf", | |
| "abstract": "We present a deep learning system ...", "provider": "core", | |
| } | |
| crossref_dup = { | |
| "title": "A Deep Learning Framework for Protein Folding", | |
| "doi": "10.1038/s41586-021-03819-2", "pdf_url": None, "provider": "crossref", | |
| } | |
| merged = dedupe_candidates([openalex_locked, crossref_dup, core_oa]) | |
| print("candidates after dedupe:", len(merged), "(expect 1)") | |
| m = merged[0] | |
| print("kept provider:", m["provider"], "(the first seen = openalex)") | |
| print("pdf_url merged in:", m.get("pdf_url")) | |
| print("oa_via:", m.get("oa_via")) | |
| print("abstract merged in:", bool(m.get("abstract"))) | |
| assert len(merged) == 1, "should dedupe to one" | |
| assert m["pdf_url"] == core_oa["pdf_url"], "CORE pdf must merge into locked paper" | |
| assert m["oa_via"] == "core" | |
| assert m["abstract"], "abstract should be filled from CORE" | |
| print("\nMERGE OK β locked Nature paper now deep-readable via CORE OA copy") | |