-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpipeline.py
More file actions
2618 lines (2159 loc) · 103 KB
/
pipeline.py
File metadata and controls
2618 lines (2159 loc) · 103 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import json, re
from pathlib import Path
from rapidfuzz import fuzz
from unidecode import unidecode
from tqdm import tqdm
import arxiv
import bibtexparser
import requests
from bs4 import BeautifulSoup
import hashlib
from datetime import datetime
import urllib.parse
import time
DATA = Path("data")
DATA.mkdir(exist_ok=True)
CACHE_DIR = Path("cache")
CACHE_DIR.mkdir(exist_ok=True)
# Keywords
APR_TERMS = [
"program repair", "automatic program repair", "APR",
"bug fixing", "patch generation", "patch synthesis",
"code repair", "vulnerability repair", "automated repair",
"vulnerability fixing", "vulnerability patching", "security patch",
"CVE repair", "vulnerability mitigation"
]
LLM_TERMS = [
"large language model", "LLM", "GPT", "CodeX", "CodeT5",
"StarCoder", "LLaMA", "Llama", "transformer", "neural network",
"generative model", "deep learning", "DeepSeek", "Claude",
"Incoder", "CodeGen", "BERT"
]
BENCH_TERMS = [
# 通用 APR benchmarks
"Defects4J", "SWE-bench", "SWE-bench Lite", "SWE-bench Verified", "SWE-bench Multimodal",
"QuixBugs", "Bugs.jar", "HumanEvalFix", "HumanEval-Java", "HumanEval-Perl",
"IntroClass", "ManySStuBs4J", "CodeFLAWS", "Bears", "d4j", "humaneval",
# 漏洞相关 benchmarks
"CVEFixes", "Big-Vul", "VulnLoc", "ExtractFix", "InstructVul",
# 其他 benchmarks
"BugsInPy", "RepoBugs", "LMDefects", "TutorCode", "MBPP", "APPS",
"CodeNet", "CodeNet4Repair", "ACPR", "InferredBugs", "PyTyDefects",
"LeetCode", "MODIT", "ATLAS", "DS-1000", "Zero-Day", "xCodeEval",
"ARVO", "APR Competition", "LoopInv", "BFP"
]
TOOL_TERMS = [
# Agentic
"RepairAgent", "AutoCodeRover", "Autocoderover", # AutoCodeRover 的变体
"SWE-agent", "SWE-Agent", "Swe-agent", # SWE-agent 的变体
"OpenHands", "Openhands", # OpenHands 的变体
"LANTERN", "VulDebugger", "Magis", "MAGIS", # Magis 的变体
"SWE-Search", "Learn-by-Interact", "Learn-by-interact", # 大小写变体
# Procedural
"ChatRepair", "ThinkRepair", "Thinkrepair", # ThinkRepair 的变体
"ContrastRepair", "Contrastrepair", # ContrastRepair 的变体
"Agentless", "REx",
"CREF", "Cref", # CREF 的变体
"HULA", "DRCodePilot", "PATCH", "KGCompass",
"Repilot", "SAN2PATCH", "PredicateFix", "LLM4CVE",
# Prompting
"AlphaRepair", "CEDAR", "RLCE", "DSrepair", "D4C",
"Appatch", "APPATCH", # Appatch 的变体
"TracePrompt",
# Fine-tuning
"VulMaster", "RepairCAT", "RepairLLaMA", "Repairllama", # RepairLLaMA 的变体
"MORepair", "KNOD", "Knod", # KNOD 的变体
"DistiLRR", "NARRepair", "Narrepair", # NARRepair 的变体
"RePair", "SecRepair",
"Swe-rl", "SWE-RL", "Swe-agent", # SWE-RL 的变体
"AdaPatcher", "Vul-R2", "VulR2", # Vul-R2 的变体
"Tracefixer", "TraceFixer", # TraceFixer 的变体
"InferFix", "Inferfix", # InferFix 的变体
"PyTy", "Pyty", # PyTy 的变体
"NTR",
# LLM-as-Judges
"TSAPR", "SpecRover", "Abstain and Validate",
# Legacy/Other
"CURE", "CoCoNut", "Recoder", "FitRepair"
]
MANDATORY_ARXIV_IDS = [
# 保留此机制用于特殊情况(如已知arXiv API搜索不到的论文)
# 但正常情况下应该为空,让搜索策略自己找到论文
]
# ========== 通用数据源配置 ==========
SOURCE_CONFIG = [
# ICSE (2022-2026)
{"id": "icse-2022", "venue": "ICSE", "year": 2022, "type": "conference", "parser": "researchr_track",
"url": "https://conf.researchr.org/track/icse-2022/icse-2022-papers", "track_keyword": "Technical Track"},
{"id": "icse-2023", "venue": "ICSE", "year": 2023, "type": "conference", "parser": "researchr_track",
"url": "https://conf.researchr.org/track/icse-2023/icse-2023-technical-track", "track_keyword": "Technical Track"},
{"id": "icse-2024", "venue": "ICSE", "year": 2024, "type": "conference", "parser": "researchr_track",
"url": "https://conf.researchr.org/track/icse-2024/icse-2024-research-track", "track_keyword": "Research Track"},
{"id": "icse-2025", "venue": "ICSE", "year": 2025, "type": "conference", "parser": "researchr_track",
"url": "https://conf.researchr.org/track/icse-2025/icse-2025-research-track", "track_keyword": "Research Track"},
{"id": "icse-2026", "venue": "ICSE", "year": 2026, "type": "conference", "parser": "researchr_track",
"url": "https://conf.researchr.org/track/icse-2026/icse-2026-research-track", "track_keyword": "Research Track"},
# FSE (2022-2025)
{"id": "fse-2022", "venue": "FSE", "year": 2022, "type": "conference", "parser": "researchr_track",
"url": "https://conf.researchr.org/track/fse-2022/fse-2022-research-papers", "track_keyword": "Research Papers"},
{"id": "fse-2023", "venue": "FSE", "year": 2023, "type": "conference", "parser": "researchr_track",
"url": "https://conf.researchr.org/track/fse-2023/fse-2023-research-papers", "track_keyword": "Research Papers"},
{"id": "fse-2024", "venue": "FSE", "year": 2024, "type": "conference", "parser": "researchr_track",
"url": "https://conf.researchr.org/track/fse-2024/fse-2024-research-papers", "track_keyword": "Research Papers"},
{"id": "fse-2025", "venue": "FSE", "year": 2025, "type": "conference", "parser": "researchr_track",
"url": "https://conf.researchr.org/track/fse-2025/fse-2025-research-papers", "track_keyword": "Research Papers"},
# ASE (2022-2025)
{"id": "ase-2022", "venue": "ASE", "year": 2022, "type": "conference", "parser": "researchr_track",
"url": "https://conf.researchr.org/track/ase-2022/ase-2022-research-papers", "track_keyword": "Research Papers"},
{"id": "ase-2023", "venue": "ASE", "year": 2023, "type": "conference", "parser": "researchr_track",
"url": "https://conf.researchr.org/track/ase-2023/ase-2023-papers", "track_keyword": "Research Papers"},
{"id": "ase-2024", "venue": "ASE", "year": 2024, "type": "conference", "parser": "researchr_track",
"url": "https://conf.researchr.org/track/ase-2024/ase-2024-papers", "track_keyword": "Research Papers"},
{"id": "ase-2025", "venue": "ASE", "year": 2025, "type": "conference", "parser": "researchr_track",
"url": "https://conf.researchr.org/track/ase-2025/ase-2025-papers", "track_keyword": "Research Papers"},
# ISSTA (2022-2025)
{"id": "issta-2022", "venue": "ISSTA", "year": 2022, "type": "conference", "parser": "researchr_track",
"url": "https://conf.researchr.org/track/issta-2022/issta-2022-technical-papers", "track_keyword": "Technical Papers"},
{"id": "issta-2023", "venue": "ISSTA", "year": 2023, "type": "conference", "parser": "researchr_track",
"url": "https://conf.researchr.org/track/issta-2023/issta-2023-technical-papers", "track_keyword": "Technical Papers"},
{"id": "issta-2024", "venue": "ISSTA", "year": 2024, "type": "conference", "parser": "researchr_track",
"url": "https://2024.issta.org/track/issta-2024-papers#event-overview", "track_keyword": "Technical Papers"},
{"id": "issta-2025", "venue": "ISSTA", "year": 2025, "type": "conference", "parser": "researchr_track",
"url": "https://conf.researchr.org/track/issta-2025/issta-2025-papers", "track_keyword": "Papers"},
# USENIX Security (2022-2025) - Summer and Fall cycles
{"id": "usenix-sec-2022-summer", "venue": "USENIX Security", "year": 2022, "type": "conference", "parser": "usenix_accepted",
"url": "https://www.usenix.org/conference/usenixsecurity22/summer-accepted-papers"},
{"id": "usenix-sec-2022-fall", "venue": "USENIX Security", "year": 2022, "type": "conference", "parser": "usenix_accepted",
"url": "https://www.usenix.org/conference/usenixsecurity22/fall-accepted-papers"},
{"id": "usenix-sec-2023-summer", "venue": "USENIX Security", "year": 2023, "type": "conference", "parser": "usenix_accepted",
"url": "https://www.usenix.org/conference/usenixsecurity23/summer-accepted-papers"},
{"id": "usenix-sec-2023-fall", "venue": "USENIX Security", "year": 2023, "type": "conference", "parser": "usenix_accepted",
"url": "https://www.usenix.org/conference/usenixsecurity23/fall-accepted-papers"},
{"id": "usenix-sec-2024-summer", "venue": "USENIX Security", "year": 2024, "type": "conference", "parser": "usenix_accepted",
"url": "https://www.usenix.org/conference/usenixsecurity24/summer-accepted-papers"},
{"id": "usenix-sec-2024-fall", "venue": "USENIX Security", "year": 2024, "type": "conference", "parser": "usenix_accepted",
"url": "https://www.usenix.org/conference/usenixsecurity24/fall-accepted-papers"},
{"id": "usenix-sec-2025-c1", "venue": "USENIX Security", "year": 2025, "type": "conference", "parser": "usenix_accepted",
"url": "https://www.usenix.org/conference/usenixsecurity25/cycle1-accepted-papers"},
{"id": "usenix-sec-2025-main", "venue": "USENIX Security", "year": 2025, "type": "conference", "parser": "usenix_accepted",
"url": "https://www.usenix.org/conference/usenixsecurity25/technical-sessions"},
# APR Workshop (ICSE co-located)
{"id": "apr-2023", "venue": "APR", "year": 2023, "type": "workshop", "parser": "apr_workshop",
"url": "https://program-repair.org/workshop-2023/"},
{"id": "apr-2024", "venue": "APR", "year": 2024, "type": "workshop", "parser": "apr_workshop",
"url": "https://conf.researchr.org/program/icse-2024/program-icse-2024/?track=APR"},
{"id": "apr-2025", "venue": "APR", "year": 2025, "type": "workshop", "parser": "apr_workshop",
"url": "https://program-repair.org/workshop-2025/"},
# TOSEM (Journal) - 使用OpenAlex API
{"id": "tosem-openalex", "venue": "TOSEM", "type": "journal", "parser": "openalex_journal",
"openalex_id": "S142627899", "years": [2022, 2023, 2024, 2025]},
# TSE (Journal) - 使用OpenAlex API
{"id": "tse-openalex", "venue": "TSE", "type": "journal", "parser": "openalex_journal",
"openalex_id": "S8351582", "years": [2022, 2023, 2024, 2025]},
# NeurIPS (Conference 2022-2024) - 使用网页爬虫
{"id": "neurips-2022", "venue": "NeurIPS", "year": 2022, "type": "conference", "parser": "nips_web",
"url": "https://papers.nips.cc/paper_files/paper/2022"},
{"id": "neurips-2023", "venue": "NeurIPS", "year": 2023, "type": "conference", "parser": "nips_web",
"url": "https://papers.nips.cc/paper_files/paper/2023"},
{"id": "neurips-2024", "venue": "NeurIPS", "year": 2024, "type": "conference", "parser": "nips_web",
"url": "https://papers.nips.cc/paper_files/paper/2024"},
# ACL (Conference 2023-2025) - 使用网页爬虫
# Main Conference Papers
{"id": "acl-2023-main", "venue": "ACL", "year": 2023, "type": "conference", "parser": "acl_web",
"url": "https://2023.aclweb.org/program/accepted_main_conference/", "paper_type": "main"},
{"id": "acl-2024-main", "venue": "ACL", "year": 2024, "type": "conference", "parser": "acl_web",
"url": "https://2024.aclweb.org/program/main_conference_papers/", "paper_type": "main"},
{"id": "acl-2025-main", "venue": "ACL", "year": 2025, "type": "conference", "parser": "acl_web",
"url": "https://2025.aclweb.org/program/main_papers/", "paper_type": "main"},
# Findings Papers
{"id": "acl-2023-findings", "venue": "ACL", "year": 2023, "type": "conference", "parser": "acl_web",
"url": "https://2023.aclweb.org/program/accepted_findings/", "paper_type": "findings"},
{"id": "acl-2024-findings", "venue": "ACL", "year": 2024, "type": "conference", "parser": "acl_web",
"url": "https://2024.aclweb.org/program/finding_papers/", "paper_type": "findings"},
{"id": "acl-2025-findings", "venue": "ACL", "year": 2025, "type": "conference", "parser": "acl_web",
"url": "https://2025.aclweb.org/program/find_papers/", "paper_type": "findings"},
# ICLR (Conference 2022-2025)
# 2022-2024使用GitHub精选列表,2025使用OpenReview完整列表
{"id": "iclr-2022", "venue": "ICLR", "year": 2022, "type": "conference", "parser": "iclr_github",
"url": "https://raw.githubusercontent.com/yinizhilian/ICLR2025-Papers-with-Code/main/ICLR2022-Papers-with-Code.md"},
{"id": "iclr-2023", "venue": "ICLR", "year": 2023, "type": "conference", "parser": "iclr_github",
"url": "https://raw.githubusercontent.com/yinizhilian/ICLR2025-Papers-with-Code/main/ICLR2023-Papers-with-Code.md"},
{"id": "iclr-2024", "venue": "ICLR", "year": 2024, "type": "conference", "parser": "iclr_github",
"url": "https://raw.githubusercontent.com/yinizhilian/ICLR2025-Papers-with-Code/main/ICLR2024-Papers-with-Code.md"},
{"id": "iclr-2025", "venue": "ICLR", "year": 2025, "type": "conference", "parser": "openreview_venue",
"venue_name": "ICLR 2025"},
# # SANER (2022-2025)
# {"id": "saner-2022", "venue": "SANER", "year": 2022, "type": "conference", "parser": "researchr_track",
# "url": "https://conf.researchr.org/track/saner-2022/saner-2022-papers", "track_keyword": "Research Track"},
# {"id": "saner-2023", "venue": "SANER", "year": 2023, "type": "conference", "parser": "researchr_track",
# "url": "https://conf.researchr.org/track/saner-2023/saner-2023-papers", "track_keyword": "Research Track"},
# {"id": "saner-2024", "venue": "SANER", "year": 2024, "type": "conference", "parser": "researchr_track",
# "url": "https://conf.researchr.org/track/saner-2024/saner-2024-papers", "track_keyword": "Research Track"},
# {"id": "saner-2025", "venue": "SANER", "year": 2025, "type": "conference", "parser": "researchr_track",
# "url": "https://conf.researchr.org/track/saner-2025/saner-2025-papers", "track_keyword": "Research Track"},
# # MSR (2022-2025)
# {"id": "msr-2022", "venue": "MSR", "year": 2022, "type": "conference", "parser": "researchr_track",
# "url": "https://conf.researchr.org/track/msr-2022/msr-2022-technical-papers", "track_keyword": "Technical Papers"},
# {"id": "msr-2023", "venue": "MSR", "year": 2023, "type": "conference", "parser": "researchr_track",
# "url": "https://conf.researchr.org/track/msr-2023/msr-2023-technical-papers", "track_keyword": "Technical Papers"},
# {"id": "msr-2024", "venue": "MSR", "year": 2024, "type": "conference", "parser": "researchr_track",
# "url": "https://conf.researchr.org/track/msr-2024/msr-2024-technical-papers", "track_keyword": "Technical Papers"},
# {"id": "msr-2025", "venue": "MSR", "year": 2025, "type": "conference", "parser": "researchr_track",
# "url": "https://conf.researchr.org/track/msr-2025/msr-2025-technical-papers", "track_keyword": "Technical Papers"},
]
TIER1_VENUES = {
"ICSE", "FSE", "ASE", "ISSTA", "TSE", "TOSEM",
"NeurIPS", "ICML", "ICLR", "AAAI", "ACL",
"USENIX Security", "APR" # APR Workshop (ICSE co-located)
}
# Heuristics
ABSTRACT_POSITIVE_HINTS = [
# Bug/Code repair - 核心关键词
r"\bpatch(es)?\b", r"\brepair(s|ed|ing)?\b", r"\bfix(es|ed|ing)?\b",
r"\bcorrect(ing|ion|ed)?\s+bug(s)?\b",
r"\bgenerate(d|s|ing)?\s+(correct\s+)?code\b",
# Vulnerability repair
r"\bvulnerabilit(y|ies)\s+(repair|fix|patch|mitigation)\b",
r"\bsecurity\s+(patch|fix)\b", r"\bCVE\s+(repair|fix)\b",
r"\bpatch(ing)?\s+vulnerabilit(y|ies)\b",
# Issue/Problem resolution - 扩展表达
r"\bresolv(e|ed|ing)\s+(issue|bug|problem)s?\b",
r"\bsolv(e|ed|ing)\s+(issue|bug|problem)s?\b",
r"\bGitHub\s+issue(s)?\b", # GitHub issue本身就是APR相关
# Software agents (APR领域的重要方向)
r"\bsoftware\s+(engineering|development)\s+agent(s)?\b",
r"\b(autonomous|agentic)\s+(program|software|code)\b",
r"\bautomated\s+(debugging|repair|fixing)\b",
r"\bprogram\s+improvement\b",
# LLM应用于代码任务
r"\b(llm|language\s+model).{0,50}(code|program|software)\b",
r"\b(code|program|software).{0,50}(llm|language\s+model)\b",
# Bug定位/识别(APR的上游任务)
r"\bbug(gy)?\s+(identif|detect|locat|find)\b",
r"\bfault\s+localization\b",
r"\bbugginess\b"
]
# Expanded evaluation hints
EVAL_HINTS = [
r"\bevaluat(e|ion|ed|ing)\b", r"\bbenchmark(s)?\b",
r"\bempirical\b", r"\bdataset(s)?\b", r"\bstudy\b",
r"\bexperiment(s|al)?\b", r"\bresult(s)?\b", r"\bperformance\b",
r"\baccura(cy|te)\b", r"\bcomparison\b", r"\bcompare(d)?\b",
r"\boutperform(s|ed)?\b", r"\bstate-of-the-art\b", r"\bsota\b",
# Metrics
r"\bpass@\d+\b", r"\bF1\b", r"\bprecision\b", r"\brecall\b",
r"\bCodeBLEU\b", r"\bexact\s+match\b"
]
# Explicit exclusion for non-repair topics (unless seed)
EXCLUDE_TITLE_TERMS = [
"detection", "localization", "prediction", "classification",
"generating tests", "test generation"
]
# Only exclude if these are NOT present in title
RETAIN_TITLE_TERMS = [
# 直接修复相关
"repair", "fix", "patch", "correct", "fixing",
"vulnerability", "CVE", "security",
# APR相关的同义表达(不是trick,而是领域通用术语)
"agent", "autonomous", # software agents是APR的重要方向
"improvement", # program improvement
"debug", # debugging
]
# APR技术特征词(用于辅助判断)
APR_TECH_INDICATORS = [
"llm", "language model", "gpt", "codex", "chatgpt",
"automated", "automatic", "autonomous",
"agent", "agentic",
"issue resolution", "github issue", "bug fixing"
]
def norm_title(s: str) -> str:
"""标准化标题用于比较
处理流程:
1. 清除LaTeX/BibTeX格式(如$\{$text$\}$, {text}, etc.)
2. Unicode标准化
3. 转小写
4. 只保留字母数字和空格
5. 合并多余空格
"""
s = s or ""
# 1. 清除LaTeX/BibTeX格式
# 移除各种LaTeX包装:$\{$, $\}$, {, }, $, \
s = re.sub(r'\$\\{?\$', '', s) # 移除 $\{$, $$
s = re.sub(r'\$\\}?\$', '', s) # 移除 $\}$, $$
s = re.sub(r'[{}\\$]', '', s) # 移除剩余的 {, }, \, $
# 2-5. 标准化处理
s = unidecode(s).lower().strip()
s = re.sub(r"[^a-z0-9\s]", " ", s)
s = re.sub(r"\s+", " ", s)
return s.strip()
def has_tool_name_in_title(title: str) -> bool:
"""检查标题是否包含代表性工具名(严格匹配,避免误判)
匹配策略:
1. 只做精确匹配(单词边界)
2. 不做词干变化匹配(避免"patch"误判为"PATCH工具")
3. 特殊处理:一些工具名需要额外验证APR上下文
"""
title_lower = title.lower()
# 通用工具(可能造成误判的)需要配合APR上下文
# 例如:PATCH, REx 这些通用词
ambiguous_tools = ['patch', 'rex', 'repair', 'cure']
# APR上下文关键词
apr_context = ['program', 'code', 'bug', 'software', 'automated', 'llm', 'agent']
has_apr_context = any(kw in title_lower for kw in apr_context)
for tool in TOOL_TERMS:
tool_lower = tool.lower()
# 精确匹配(单词边界)
pattern = r'\b' + re.escape(tool_lower) + r'\b'
if re.search(pattern, title_lower):
# 如果是通用词,需要APR上下文验证
if tool_lower in ambiguous_tools:
if has_apr_context:
return True
else:
continue # 跳过,不认为是工具名
else:
return True
return False
def token_diff_leq3(a: str, b: str) -> bool:
ta = set(norm_title(a).split())
tb = set(norm_title(b).split())
return len(ta.symmetric_difference(tb)) <= 3
def title_sim(a: str, b: str) -> int:
return max(
fuzz.token_set_ratio(a, b),
fuzz.token_sort_ratio(a, b),
fuzz.QRatio(a, b)
)
def is_tier1(venue: str) -> bool:
if not venue: return False
v = venue.replace(".", "").strip()
return any(t.lower() in v.lower() for t in TIER1_VENUES)
def from_arxiv(rec):
short_id = rec.get_short_id()
base_id = short_id.split("v")[0] if short_id and "v" in short_id else short_id
return {
"source": "arxiv",
"title": rec.title,
"year": rec.published.year if rec.published else None,
"doi": (rec.doi or "").lower(),
"venue": "arXiv",
"type": "preprint",
"authors": [a.name for a in rec.authors],
"abstract": rec.summary,
"url": rec.entry_id,
"openalex_id": None,
"arxiv_id": base_id.lower() if base_id else "",
"citation_count": 0 # 初始值,后续通过 OpenAlex 查询
}
def get_arxiv_citation_count(arxiv_id, use_cache=True):
"""通过 OpenAlex API 获取 arXiv 论文的引用次数
Args:
arxiv_id: arXiv ID (例如: "2401.12345")
use_cache: 是否使用缓存
Returns:
引用次数(整数),失败时返回 0
"""
if not arxiv_id:
return 0
# 缓存键:使用 arxiv_id 作为缓存标识
cache_id = f"citation_{arxiv_id}"
# 尝试从缓存加载
if use_cache:
cached = load_from_cache(cache_id)
if cached is not None:
# 缓存格式:{"citation_count": N}
return cached.get("citation_count", 0)
# 构建 OpenAlex API URL
# OpenAlex 通过 DOI 查询 arXiv 论文:10.48550/arxiv.XXXX.XXXXX
arxiv_doi = f"10.48550/arxiv.{arxiv_id}"
url = f"https://api.openalex.org/works?filter=doi:{arxiv_doi}"
try:
resp = requests.get(url, timeout=10)
if resp.status_code == 200:
data = resp.json()
results = data.get("results", [])
if results:
# 取第一个结果的引用数
citation_count = results[0].get("cited_by_count", 0)
# 保存到缓存
if use_cache:
save_to_cache(cache_id, {"citation_count": citation_count})
return citation_count
else:
# OpenAlex 没有找到该论文
return 0
else:
# API 请求失败
return 0
except Exception as exc:
# 网络错误或解析错误,返回 0
# print(f"[WARN] Failed to fetch citation count for arXiv:{arxiv_id}: {exc}")
return 0
def normalize_doi(url_or_doi: str) -> str:
if not url_or_doi:
return ""
doi = url_or_doi.strip()
doi = doi.replace("https://doi.org/", "").replace("http://doi.org/", "")
doi = doi.replace("https://dx.doi.org/", "").replace("http://dx.doi.org/", "")
return doi.strip()
# ========== 缓存机制 ==========
def get_cache_key(source_id):
"""生成缓存键"""
return hashlib.md5(source_id.encode()).hexdigest()
def get_cache_path(source_id):
"""获取缓存文件路径"""
cache_key = get_cache_key(source_id)
return CACHE_DIR / f"{cache_key}_{source_id}.json"
def load_from_cache(source_id):
"""从缓存加载数据"""
cache_path = get_cache_path(source_id)
if cache_path.exists():
try:
with open(cache_path, 'r', encoding='utf-8') as f:
cache_data = json.load(f)
# 检查缓存是否过期(默认7天)
cache_time = cache_data.get('timestamp', 0)
cache_age_days = (datetime.now().timestamp() - cache_time) / 86400
if cache_age_days < 7: # 7天内的缓存有效
print(f"[CACHE] 从缓存加载 {source_id} ({cache_data.get('count', 0)} 条记录, {cache_age_days:.1f} 天前)")
return cache_data.get('records', [])
else:
print(f"[CACHE] 缓存已过期 {source_id} ({cache_age_days:.1f} 天前)")
except Exception as exc:
print(f"[CACHE] 缓存加载失败 {source_id}: {exc}")
return None
def save_to_cache(source_id, records):
"""保存数据到缓存"""
cache_path = get_cache_path(source_id)
try:
cache_data = {
'source_id': source_id,
'timestamp': datetime.now().timestamp(),
'count': len(records),
'records': records
}
with open(cache_path, 'w', encoding='utf-8') as f:
json.dump(cache_data, f, ensure_ascii=False, indent=2)
print(f"[CACHE] 已缓存 {source_id} ({len(records)} 条记录)")
except Exception as exc:
print(f"[CACHE] 缓存保存失败 {source_id}: {exc}")
def clear_cache(source_id=None):
"""清除缓存"""
if source_id:
cache_path = get_cache_path(source_id)
if cache_path.exists():
cache_path.unlink()
print(f"[CACHE] 已清除缓存: {source_id}")
else:
# 清除所有缓存
for cache_file in CACHE_DIR.glob("*.json"):
cache_file.unlink()
print(f"[CACHE] 已清除所有缓存")
# ========== 解析器实现 ==========
def parse_researchr_track(source_meta):
"""解析 conf.researchr.org 的会议 track 页面 (ICSE/FSE/ASE/ISSTA 等)"""
records = []
try:
resp = requests.get(source_meta["url"], timeout=30)
resp.raise_for_status()
except Exception as exc:
print(f"[WARN] Failed to fetch {source_meta['id']}: {exc}")
return records
soup = BeautifulSoup(resp.text, "html.parser")
track_keyword = source_meta.get("track_keyword", "")
# 尝试三种常见的结构
# 结构1: table.session-table (程序表格)
rows = soup.select("table.session-table tr")
for row in rows:
tds = row.find_all("td")
if len(tds) < 4:
continue
detail_cell = tds[-1]
title_anchor = detail_cell.find("a", attrs={"data-event-modal": True})
if not title_anchor:
continue
# 过滤 track
if track_keyword:
track_div = detail_cell.find("div", class_="prog-track")
if track_div and track_keyword not in track_div.get_text(strip=True):
continue
title = title_anchor.get_text(strip=True)
if not title:
continue
performer_anchors = detail_cell.select("div.performers a")
authors = [a.get_text(strip=True) for a in performer_anchors if a.get_text(strip=True)]
doi_link = detail_cell.find("a", class_="publication-link")
doi_url = doi_link["href"].strip() if doi_link and doi_link.get("href") else ""
doi = normalize_doi(doi_url)
records.append({
"source": f"conf:{source_meta['venue']}:{source_meta['year']}",
"title": title,
"year": source_meta.get("year"),
"doi": doi,
"venue": f"{source_meta['venue']} {source_meta['year']}",
"type": "conference",
"authors": authors,
"abstract": "",
"url": doi_url or source_meta["url"],
"openalex_id": None,
"arxiv_id": None
})
# 结构2: div.event-item (事件列表)
if not records:
events = soup.select("div.event-item, div.program-event")
for event in events:
title_elem = event.find("a", class_="event-title") or event.find("h4")
if not title_elem:
continue
title = title_elem.get_text(strip=True)
if not title:
continue
authors_elem = event.find("div", class_="authors") or event.find("span", class_="authors")
authors = []
if authors_elem:
author_links = authors_elem.find_all("a")
authors = [a.get_text(strip=True) for a in author_links if a.get_text(strip=True)]
doi_link = event.find("a", href=re.compile(r"doi\.org"))
doi_url = doi_link["href"].strip() if doi_link else ""
doi = normalize_doi(doi_url)
records.append({
"source": f"conf:{source_meta['venue']}:{source_meta['year']}",
"title": title,
"year": source_meta.get("year"),
"doi": doi,
"venue": f"{source_meta['venue']} {source_meta['year']}",
"type": "conference",
"authors": authors,
"abstract": "",
"url": doi_url or source_meta["url"],
"openalex_id": None,
"arxiv_id": None
})
# 结构3: 简单的两列表格 (ICSE 2026 风格)
# 第一列为空,第二列包含标题链接、作者和track信息
if not records:
tables = soup.find_all("table")
for table in tables:
table_rows = table.find_all("tr")
if len(table_rows) < 10: # 跳过小表格(如日期表)
continue
for row in table_rows[1:]: # 跳过标题行
cells = row.find_all("td")
if len(cells) < 2:
continue
title_cell = cells[1]
# 查找标题链接
title_link = title_cell.find("a")
if not title_link:
continue
title = title_link.get_text(strip=True)
if not title or len(title) < 10: # 过滤太短的标题
continue
# 从完整文本中提取信息
full_text = title_cell.get_text(strip=True)
# 检查 track 关键词(如果指定)
if track_keyword and track_keyword not in full_text:
continue
# 尝试提取作者(标题后面的文本,通常以逗号分隔)
# 格式: "Title...Research TrackAuthor1,Author2,Author3..."
authors = []
if track_keyword:
# 移除标题和track关键词,剩下的是作者
author_text = full_text.replace(title, "").replace(track_keyword, "")
# 分割作者(以逗号分隔)
author_parts = [a.strip() for a in author_text.split(",") if a.strip()]
# 过滤掉太长的部分(可能是其他信息)
authors = [a for a in author_parts if len(a) < 50 and len(a) > 2]
records.append({
"source": f"conf:{source_meta['venue']}:{source_meta['year']}",
"title": title,
"year": source_meta.get("year"),
"doi": "",
"venue": f"{source_meta['venue']} {source_meta['year']}",
"type": "conference",
"authors": authors,
"abstract": "",
"url": source_meta["url"],
"openalex_id": None,
"arxiv_id": None
})
# 如果找到了论文,就不再检查其他表格
if records:
break
print(f"[INFO] Parsed {len(records)} entries from {source_meta['id']}")
return records
def parse_usenix_accepted(source_meta):
"""解析 USENIX Security 的 accepted papers 页面"""
records = []
try:
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'
}
resp = requests.get(source_meta["url"], timeout=30, headers=headers)
resp.raise_for_status()
except Exception as exc:
print(f"[WARN] Failed to fetch {source_meta['id']}: {exc}")
return records
soup = BeautifulSoup(resp.text, "html.parser")
# 尝试多种结构
# 结构1: article.node-paper (最新版,2024+)
paper_divs = soup.select("article.node-paper")
if not paper_divs:
# 结构2: div.views-row (旧版)
paper_divs = soup.select("div.views-row")
if not paper_divs:
# 结构3: div.node--paper (中间版本)
paper_divs = soup.select("div.node--paper")
if not paper_divs:
# 结构4: 简单的列表项
paper_divs = soup.select("div.field--name-field-paper-title")
for div in paper_divs:
# 标题提取 - 多种方式
title = None
title_elem = (div.find("h2") or div.find("h3") or
div.find("div", class_="title") or
div.find("span", class_="field--name-field-paper-title"))
if title_elem:
title_link = title_elem.find("a")
title = title_link.get_text(strip=True) if title_link else title_elem.get_text(strip=True)
if not title:
continue
# 作者信息 - 多种方式
authors = []
author_elem = (div.find("div", class_="authors") or
div.find("p", class_="authors") or
div.find("div", class_="field--name-field-paper-people-text"))
if author_elem:
author_text = author_elem.get_text(strip=True)
# 清理格式
author_text = re.sub(r'\s+', ' ', author_text)
# 分割作者 "Author1, Author2, and Author3" 或 "Author1; Author2"
authors = [a.strip() for a in re.split(r'[,;]\s*(?:and\s+)?', author_text) if a.strip()]
# PDF/DOI 链接
url = source_meta["url"]
pdf_link = div.find("a", href=re.compile(r'\.pdf$', re.I))
if pdf_link and pdf_link.get("href"):
url = pdf_link["href"]
if not url.startswith("http"):
url = "https://www.usenix.org" + url
records.append({
"source": f"conf:{source_meta['venue']}:{source_meta['year']}",
"title": title,
"year": source_meta.get("year"),
"doi": "",
"venue": f"{source_meta['venue']} {source_meta['year']}",
"type": "conference",
"authors": authors,
"abstract": "",
"url": url,
"openalex_id": None,
"arxiv_id": None
})
print(f"[INFO] Parsed {len(records)} entries from {source_meta['id']}")
return records
def parse_apr_workshop(source_meta):
"""解析 ICSE APR Workshop accepted papers"""
records = []
url = source_meta.get('url')
year = source_meta.get('year')
try:
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'
}
resp = requests.get(url, headers=headers, timeout=30)
if resp.status_code != 200:
print(f"[WARN] Failed to fetch {source_meta['id']}: status {resp.status_code}")
return records
soup = BeautifulSoup(resp.text, 'html.parser')
# 查找 Accepted Papers 部分
accepted_section = soup.find('h2', string=re.compile(r'Accepted Papers', re.I))
if not accepted_section:
print(f"[INFO] No 'Accepted Papers' section found for APR {year}")
return records
# 查找该部分后的表格
table = accepted_section.find_next('table')
if table:
rows = table.find_all('tr')
for row in rows:
cells = row.find_all(['td', 'th'])
if not cells:
continue
# 提取论文信息
cell_text = cells[0].get_text(strip=True)
# 分离标题和作者(通常标题是粗体)
bold = cells[0].find('strong')
if bold:
title = bold.get_text(strip=True)
# 作者在粗体后面
authors_text = cell_text.replace(title, '').strip()
else:
# 如果没有粗体,整个当作标题
title = cell_text
authors_text = ""
if not title or len(title) < 10:
continue
# 解析作者
authors = []
if authors_text:
# 通常以逗号分隔
author_names = [a.strip() for a in authors_text.split(',')]
authors = [a for a in author_names if len(a) > 2]
records.append({
"source": f"workshop:APR:{year}",
"title": title,
"year": year,
"doi": "",
"venue": "APR", # APR Workshop视为ICSE的一部分
"type": "workshop",
"authors": authors,
"abstract": "",
"url": url,
"openalex_id": None,
"arxiv_id": None
})
except Exception as exc:
print(f"[WARN] Failed to parse APR {year}: {exc}")
print(f"[INFO] Parsed {len(records)} entries from {source_meta['id']}")
return records
def parse_openalex_journal(source_meta):
"""使用OpenAlex API解析期刊数据"""
records = []
openalex_id = source_meta.get('openalex_id')
years = source_meta.get('years', [2022, 2023, 2024, 2025])
venue_name = source_meta.get('venue')
if not openalex_id:
print(f"[WARN] No OpenAlex ID specified for {source_meta['id']}")
return records
for year in years:
url = f"https://api.openalex.org/works?filter=primary_location.source.id:{openalex_id},publication_year:{year}&per-page=200"
try:
resp = requests.get(url, timeout=30)
if resp.status_code != 200:
print(f"[WARN] OpenAlex API returned {resp.status_code} for {venue_name} {year}")
continue
data = resp.json()
results = data.get('results', [])
print(f"[INFO] Fetched {len(results)} articles from {venue_name} {year}")
for work in results:
title = work.get('title', '')
if not title:
continue
# 安全处理DOI(可能为None)
doi_raw = work.get('doi')
doi = doi_raw.replace('https://doi.org/', '') if doi_raw else ''
# 提取作者
authors = []
for authorship in work.get('authorships', []):
author_info = authorship.get('author', {})
author_name = author_info.get('display_name', '')
if author_name:
authors.append(author_name)
# 重建摘要
abstract = ""
inverted_abstract = work.get('abstract_inverted_index', {})
if inverted_abstract:
words = []
for word, positions in inverted_abstract.items():
for pos in positions:
words.append((pos, word))
words.sort()
abstract = ' '.join([w[1] for w in words])
# URL
url_value = work.get('doi') or work.get('id')
records.append({
"source": f"openalex:{venue_name}",
"title": title,
"year": year,
"doi": doi.lower() if doi else "",
"venue": venue_name,
"type": "journal",
"authors": authors,
"abstract": abstract if abstract else "", # 不再截断摘要
"url": url_value,
"openalex_id": work.get('id'),
"arxiv_id": None
})
except Exception as exc:
print(f"[ERROR] OpenAlex API failed for {venue_name} {year}: {exc}")
continue
print(f"[INFO] Parsed {len(records)} entries from {source_meta['id']}")
return records
def parse_acl_web(source_meta):
"""解析 ACL 会议的网页论文列表
支持 main papers 和 findings papers
"""
records = []
year = source_meta.get('year')
url = source_meta.get('url')
paper_type = source_meta.get('paper_type', 'main') # 'main' or 'findings'
try:
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'
}
resp = requests.get(url, headers=headers, timeout=30)
resp.raise_for_status()
except Exception as exc:
print(f"[WARN] Failed to fetch {source_meta['id']}: {exc}")
return records
soup = BeautifulSoup(resp.text, 'html.parser')
# ACL网页通常在<ul>或<li>中列出论文
# 格式:<li><strong>Title</strong> <i>Authors</i></li>
paper_items = soup.find_all('li')
for item in paper_items:
# 提取标题(通常是加粗的文本或链接)
title_elem = item.find('strong') or item.find('b')
if not title_elem:
# 如果没有加粗,尝试查找链接
title_elem = item.find('a')
if not title_elem:
continue
title = title_elem.get_text(strip=True)
if not title or len(title) < 10: # 过滤太短的标题
continue
# 提取作者(通常在斜体标签中)
authors = []
author_elem = item.find('i') or item.find('em')
if author_elem:
authors_text = author_elem.get_text(strip=True)
authors = [a.strip() for a in authors_text.split(',') if a.strip()]
# 提取链接
paper_url = url
link_elem = item.find('a', href=True)
if link_elem:
href = link_elem['href']
if href.startswith('http'):
paper_url = href
elif href.startswith('/'):
# 相对路径,补全域名
from urllib.parse import urljoin
paper_url = urljoin(url, href)
records.append({
"source": f"conf:ACL:{year}:{paper_type}",
"title": title,
"year": year,
"doi": None,
"venue": f"ACL {year}",
"type": "conference",
"authors": authors,
"abstract": "",
"url": paper_url,
"openalex_id": None,
"arxiv_id": None
})
print(f"[INFO] Parsed {len(records)} entries from {source_meta['id']}")
return records
def parse_nips_web(source_meta):
"""解析 NeurIPS 论文网页
URL格式: https://papers.nips.cc/paper_files/paper/YYYY
"""
records = []
year = source_meta.get('year')
url = source_meta.get('url')
try:
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'
}
resp = requests.get(url, headers=headers, timeout=30)
resp.raise_for_status()
except Exception as exc:
print(f"[WARN] Failed to fetch {source_meta['id']}: {exc}")