Spaces:
Sleeping
Sleeping
| #!/usr/bin/env python3 | |
| """ | |
| 测试OpenAlex集成到推荐系统的功能 | |
| """ | |
| import sys | |
| import os | |
| sys.path.append(os.path.dirname(os.path.abspath(__file__))) | |
| from reviewer_recommendation import ( | |
| PaperInfo, OpenAlexSearcher, DynamicAcademicSearcher, LLMRecommendationEngine | |
| ) | |
| def test_openalex_integration(): | |
| """测试OpenAlex集成功能""" | |
| print("=== 测试OpenAlex集成到推荐系统 ===") | |
| print("=" * 60) | |
| # 1. 测试OpenAlexSearcher | |
| print("\n--- 测试OpenAlexSearcher ---") | |
| openalex_searcher = OpenAlexSearcher(limit=5) | |
| # 测试基本搜索 | |
| results = openalex_searcher.search("machine learning", sort_by_citations=True) | |
| print(f"OpenAlex搜索返回 {len(results)} 个结果") | |
| if results: | |
| print("前3个结果:") | |
| for i, result in enumerate(results[:3], 1): | |
| title = result.get('title', 'N/A')[:50] + '...' if len(result.get('title', '')) > 50 else result.get('title', 'N/A') | |
| cited_count = result.get('citedByCount', 0) | |
| print(f" {i}. {title} (引用量: {cited_count})") | |
| # 2. 测试DynamicAcademicSearcher with OpenAlex | |
| print("\n--- 测试DynamicAcademicSearcher with OpenAlex ---") | |
| dynamic_searcher = DynamicAcademicSearcher(openalex_searcher=openalex_searcher) | |
| # 创建测试论文 | |
| test_paper = PaperInfo( | |
| title="Deep Learning for Protein Structure Prediction", | |
| abstract="This paper presents a novel deep learning approach for predicting protein structures using neural networks and molecular dynamics simulations.", | |
| keywords=["deep learning", "protein structure", "neural networks"], | |
| authors=["John Smith", "Jane Doe"], | |
| affiliations=["MIT", "Stanford University"] | |
| ) | |
| # 执行动态查询 | |
| print("执行动态查询...") | |
| channel1_candidates, channel2_candidates = dynamic_searcher.search_with_dynamic_queries( | |
| paper=test_paper, | |
| num_queries=2 | |
| ) | |
| print(f"通道1(高引用量): {len(channel1_candidates)} 个候选") | |
| print(f"通道2(相关性): {len(channel2_candidates)} 个候选") | |
| # 显示通道1的前几个结果 | |
| if channel1_candidates: | |
| print("\n通道1前3个结果(按引用量排序):") | |
| for i, candidate in enumerate(channel1_candidates[:3], 1): | |
| title = candidate.get('title', 'N/A')[:50] + '...' if len(candidate.get('title', '')) > 50 else candidate.get('title', 'N/A') | |
| cited_count = candidate.get('citedByCount', 0) | |
| print(f" {i}. {title} (引用量: {cited_count})") | |
| # 显示通道2的前几个结果 | |
| if channel2_candidates: | |
| print("\n通道2前3个结果(按相关性排序):") | |
| for i, candidate in enumerate(channel2_candidates[:3], 1): | |
| title = candidate.get('title', 'N/A')[:50] + '...' if len(candidate.get('title', '')) > 50 else candidate.get('title', 'N/A') | |
| cited_count = candidate.get('citedByCount', 0) | |
| print(f" {i}. {title} (引用量: {cited_count})") | |
| # 3. 测试完整的推荐流程 | |
| print("\n--- 测试完整推荐流程 ---") | |
| engine = LLMRecommendationEngine() | |
| # 合并候选者 | |
| all_candidates = channel1_candidates + channel2_candidates | |
| print(f"总候选者数量: {len(all_candidates)}") | |
| if all_candidates: | |
| # 执行LLM分析 | |
| print("执行LLM分析...") | |
| try: | |
| reviewers = engine.analyze_candidates( | |
| paper=test_paper, | |
| channel1_candidates=channel1_candidates, | |
| channel2_candidates=channel2_candidates, | |
| reviewer_count=3 | |
| ) | |
| print(f"推荐了 {len(reviewers)} 个审稿人:") | |
| for i, reviewer in enumerate(reviewers, 1): | |
| print(f" {i}. {reviewer.name} ({reviewer.affiliation})") | |
| print(f" 推荐理由: {reviewer.reason}") | |
| print(f" 匹配度: {reviewer.relevance_score}") | |
| print() | |
| except Exception as e: | |
| print(f"LLM分析失败: {str(e)}") | |
| print("=" * 60) | |
| print("OpenAlex集成测试完成") | |
| if __name__ == "__main__": | |
| test_openalex_integration() | |