From 168ad8ec4e0c35d63c917178a21830aec244e751 Mon Sep 17 00:00:00 2001 From: Codex Bot Date: Wed, 25 Nov 2026 22:44:36 +0800 Subject: [PATCH] Extend global audit to author variants and large rosters --- docs/operations.md | 5 ++- paper_atlas/audits/global_identity.py | 48 ++++++++++++++++++++------- tests/test_global_identity_audit.py | 30 +++++++++++++++++ 3 files changed, 70 insertions(+), 13 deletions(-) diff --git a/docs/operations.md b/docs/operations.md index 96e7c24..f304e96 100644 --- a/docs/operations.md +++ b/docs/operations.md @@ -7,12 +7,15 @@ ```bash paper-atlas audit global-identity \ --pg-service foundry-research --pg-schema research \ + --extended-titles \ --scratch-root /data/paper-index/validation \ --candidate-output /data/paper-index/validation/identity-candidates-2026-11-22.jsonl \ > /data/paper-index/validation/identity-report-2026-11-22.json ``` -JSON 报告记录快照时间、论文与缺摘要计数、稳定标识冲突、约束状态、会议年度与轨道的来源覆盖,以及一次实际的全文搜索和执行计划。JSONL 保存同题且规范化作者集合相同的论文组,以及相同作者集合中标题相似度至少为 0.90 的论文对。超过 100 条记录的作者组会列入报告,留作后续逐组核对。缺作者、作者增减或换名的版本需要结合 DOI、论坛或作者说明,使用 `audit source-identities` 和原始来源复核。 +JSON 报告记录快照时间、论文与缺摘要计数、稳定标识冲突、约束状态、会议年度与轨道的来源覆盖,以及一次实际的全文搜索和执行计划。JSONL 保存同题且规范化作者集合相同的论文组,以及相同作者集合中标题相似度至少为 0.90 的论文对。全库验收使用 `--extended-titles`,可额外获得同题但署名不同或缺失的候选,以及超过 100 条记录的同作者组中的近似题名候选。由于需要比较这些组的题名,运行时间随组内题名数增加。日常核查省略该参数时,大组只输出规模和样例。 + +近似题名比较要求规范化作者集合一致。题名与署名均变动的版本,使用 `audit source-identities` 并结合 DOI、论坛、作者说明或原始来源复核。候选仍需核实论文身份和投稿决定的证据。 将报告、候选文件、运行版本与 SHA-256 一起保留。使用 `audit histories` 核对拒稿、撤稿、后续录用和来源链接。需要合并候选时先确认论文版本关系并保存投稿、决定、标签及来源证据,再按已授权的流程操作。新一批导入完成后更新快照和审计报告。 diff --git a/paper_atlas/audits/global_identity.py b/paper_atlas/audits/global_identity.py index 645aa1c..04ee4fa 100644 --- a/paper_atlas/audits/global_identity.py +++ b/paper_atlas/audits/global_identity.py @@ -96,7 +96,8 @@ def _stage_titles(connection, scratch): counts = Counter(papers=0, missing_abstract=0, missing_author_keys=0, invalid_authors_json=0) with connection.connection.cursor(name='paper_atlas_global_identity_scan') as titles: titles.itersize = 5000 - titles.execute('SELECT id,title_key,authors_json,abstract IS NULL OR btrim(abstract)=\'\' FROM papers ORDER BY id') + # The scratch indexes provide the ordering used by every candidate query. + titles.execute('SELECT id,title_key,authors_json,abstract IS NULL OR btrim(abstract)=\'\' FROM papers') while rows := titles.fetchmany(5000): batch = [] for row in rows: @@ -117,7 +118,7 @@ def _stage_titles(connection, scratch): return dict(counts) -def _candidates(scratch, output): +def _candidates(scratch, output, *, extended_titles=False): counts = Counter(exact_title_groups=0, exact_title_and_roster_groups=0, exact_title_and_roster_papers=0, near_title_and_roster_pairs=0, oversized_rosters=0, papers_in_oversized_rosters=0) @@ -134,6 +135,20 @@ def _candidates(scratch, output): ids = [row[0] for row in scratch.execute(''' SELECT id FROM titles WHERE title_key=? AND authors=? ORDER BY id''', (title,roster))] emit({'kind':'exact_title_and_roster','title_key':title,'paper_ids':ids}) + if extended_titles: + counts['exact_title_with_roster_variation_groups'] = 0 + counts['near_title_pairs_in_oversized_rosters'] = 0 + for title,roster_count,missing in scratch.execute(''' + SELECT title_key,count(DISTINCT authors),count(*)-count(authors) + FROM titles WHERE title_key<>'' + GROUP BY title_key HAVING count(*)>1 + AND (count(DISTINCT authors)>1 OR count(authors)=25 ORDER BY authors,title_key,id''') @@ -142,29 +157,34 @@ def _candidates(scratch, output): size = 0 for _, title, paper_id in group: size += 1 - if size <= ROSTER_GROUP_LIMIT: + if extended_titles or size <= ROSTER_GROUP_LIMIT: entries.append((title,paper_id)) - if size > ROSTER_GROUP_LIMIT: + oversized = size > ROSTER_GROUP_LIMIT + if oversized: counts['oversized_rosters'] += 1 counts['papers_in_oversized_rosters'] += size - emit({'kind':'oversized_roster','size':size,'sample_paper_ids':[p for _,p in entries[:5]]}) - continue + if not extended_titles: + emit({'kind':'oversized_roster','size':size,'sample_paper_ids':[p for _,p in entries[:5]]}) + continue for (left,left_id),(right,right_id) in combinations(entries,2): if left==right or 2*min(len(left),len(right))/(len(left)+len(right)) < TITLE_SCORE: continue matcher = SequenceMatcher(None,left,right,autojunk=False) if matcher.quick_ratio()>=TITLE_SCORE and (score:=matcher.ratio())>=TITLE_SCORE: counts['near_title_and_roster_pairs'] += 1 + if oversized: + counts['near_title_pairs_in_oversized_rosters'] += 1 emit({'kind':'near_title_and_roster','paper_ids':[left_id,right_id],'score':round(score,5)}) return dict(counts) -def report(connection, scratch_root, candidates): +def report(connection, scratch_root, candidates, *, extended_titles=False): transaction = dict(connection.execute(''' SELECT current_database() AS database,current_schema() AS schema, current_setting('transaction_read_only') AS read_only, current_setting('transaction_isolation') AS isolation, - transaction_timestamp()::text AS snapshot_at''').fetchone()) + transaction_timestamp()::text AS snapshot_at, + (SELECT max(id) FROM ingest_runs) AS last_ingest_run''').fetchone()) if transaction['read_only']!='on' or transaction['isolation']!='repeatable read': raise ValueError('A read-only repeatable-read snapshot is required') if shutil.disk_usage(scratch_root).free < 2*1024**3: @@ -177,12 +197,14 @@ def report(connection, scratch_root, candidates): with closing(sqlite3.connect(Path(directory)/'titles.sqlite')) as scratch: scratch.execute('PRAGMA temp_store=FILE') counts = _stage_titles(connection,scratch) - candidate_counts = _candidates(scratch,candidates) + candidate_counts = _candidates(scratch,candidates,extended_titles=extended_titles) return {'snapshot':transaction,'papers':counts,'integrity':integrity, 'candidate_counts':candidate_counts,'edition_sources':coverage,'search':search, 'candidate_rules':{'minimum_normalized_title_length':25,'near_title_score':TITLE_SCORE, - 'max_papers_per_near_title_author_group':ROSTER_GROUP_LIMIT, - 'requires_exact_normalized_author_set':True}, + 'max_papers_per_near_title_author_group':None if extended_titles else ROSTER_GROUP_LIMIT, + 'includes_exact_title_with_roster_variation':extended_titles, + 'requires_exact_normalized_author_set':not extended_titles, + 'near_title_requires_exact_normalized_author_set':True}, 'canonical_data_changed':False} @@ -192,8 +214,10 @@ def main(argv=None, *, prog=None): parser.add_argument('--pg-schema') parser.add_argument('--scratch-root',type=Path,required=True) parser.add_argument('--candidate-output',type=Path,required=True) + parser.add_argument('--extended-titles',action='store_true', + help='同时输出同题不同或缺失署名的候选,并扫描超出默认规模的作者组') args = parser.parse_args(argv) with closing(ReadConnection(args.pg_service,args.pg_schema)) as connection: with args.candidate_output.open('x',encoding='utf-8') as candidates: - result = report(connection,args.scratch_root,candidates) + result = report(connection,args.scratch_root,candidates,extended_titles=args.extended_titles) print(json.dumps(result,ensure_ascii=False)) diff --git a/tests/test_global_identity_audit.py b/tests/test_global_identity_audit.py index 1f90625..11a2995 100644 --- a/tests/test_global_identity_audit.py +++ b/tests/test_global_identity_audit.py @@ -52,6 +52,36 @@ class GlobalIdentityCandidatesTest(unittest.TestCase): global_identity._author_fingerprint(records)) self.assertIsNone(global_identity._author_fingerprint('[]')) + def test_extended_titles_include_changed_rosters_and_scan_oversized_rosters(self): + output = io.StringIO() + with sqlite3.connect(':memory:') as scratch: + scratch.execute('CREATE TABLE titles (id INTEGER, title_key TEXT, authors BLOB)') + scratch.executemany('INSERT INTO titles VALUES (?,?,?)', [ + (1, 'astronomicaltransientcatalogue', b'first'), + (2, 'astronomicaltransientcatalogues', b'first'), + (3, 'astronomicaltransientcatalogued', b'first'), + (4, 'astronomicaltransientcatalogue', b'second'), + (5, 'astronomicaltransientcatalogue', None), + (6, 'anotherunrelatedarticleheading', None), + (7, 'anotherunrelatedarticleheading', None), + ]) + with patch.object(global_identity, 'ROSTER_GROUP_LIMIT', 2): + counts = global_identity._candidates(scratch, output, extended_titles=True) + + records = [json.loads(row) for row in output.getvalue().splitlines()] + self.assertEqual(counts['oversized_rosters'], 1) + self.assertEqual(counts['near_title_pairs_in_oversized_rosters'], 3) + self.assertEqual(counts['near_title_and_roster_pairs'], 3) + self.assertEqual(counts['exact_title_with_roster_variation_groups'], 2) + self.assertEqual(records[:2], [ + {'kind': 'exact_title_with_roster_variation', 'title_key': 'anotherunrelatedarticleheading', + 'paper_ids': [6, 7], 'distinct_known_rosters': 0, 'papers_missing_roster': 2}, + {'kind': 'exact_title_with_roster_variation', 'title_key': 'astronomicaltransientcatalogue', + 'paper_ids': [1, 4, 5], 'distinct_known_rosters': 2, 'papers_missing_roster': 1}, + ]) + self.assertEqual({tuple(sorted(record['paper_ids'])) for record in records[2:]}, + {(1, 2), (1, 3), (2, 3)}) + def test_doi_pattern_is_bound_as_a_parameter(self): connection = Mock()