推断研究方向
(text: str)
| 548 | |
| 549 | |
| 550 | def infer_research_directions(text: str) -> List[Dict]: |
| 551 | """推断研究方向""" |
| 552 | text_lower = text.lower() |
| 553 | direction_map: Dict[str, Dict[str, Any]] = {} |
| 554 | |
| 555 | for area, keywords in RESEARCH_AREA_KEYWORDS.items(): |
| 556 | match_count = sum(1 for kw in keywords if kw in text_lower) |
| 557 | if match_count >= 2: |
| 558 | confidence = score_direction_confidence(match_count, len(keywords)) |
| 559 | if confidence > 0: |
| 560 | direction_map[area] = {"name": area, "confidence": confidence} |
| 561 | |
| 562 | embedding_service = _get_embedding_service() |
| 563 | semantic_text = text[:4000].strip() |
| 564 | if embedding_service and semantic_text: |
| 565 | try: |
| 566 | text_embedding = embedding_service.embed_text(semantic_text) |
| 567 | prototype_names = list(SEMANTIC_DIRECTION_PROTOTYPES.keys()) |
| 568 | prototype_embeddings = embedding_service.embed_batch( |
| 569 | [SEMANTIC_DIRECTION_PROTOTYPES[name] for name in prototype_names] |
| 570 | ) |
| 571 | |
| 572 | for area, prototype_embedding in zip(prototype_names, prototype_embeddings): |
| 573 | similarity = embedding_service.cosine_similarity(text_embedding, prototype_embedding) |
| 574 | if similarity < SEMANTIC_DIRECTION_MIN_SIMILARITY: |
| 575 | continue |
| 576 | |
| 577 | confidence = score_semantic_direction_confidence(similarity) |
| 578 | current = direction_map.get(area) |
| 579 | if current is None or confidence > float(current.get("confidence", 0.0)): |
| 580 | direction_map[area] = {"name": area, "confidence": confidence} |
| 581 | except Exception as exc: |
| 582 | print(f"Semantic PDF direction inference failed: {exc}") |
| 583 | |
| 584 | directions = list(direction_map.values()) |
| 585 | directions.sort(key=lambda x: x["confidence"], reverse=True) |
| 586 | return directions[:5] |
| 587 | |
| 588 | |
| 589 | def infer_methodology_preferences(text: str, sections: Dict[str, str]) -> Dict[str, bool]: |
no test coverage detected