Extracts methodology descriptions from papers for figure generation.
| 44 | |
| 45 | |
| 46 | class MethodologyExtractor: |
| 47 | """ |
| 48 | Extracts methodology descriptions from papers for figure generation. |
| 49 | """ |
| 50 | |
| 51 | def __init__(self, config: "Config"): |
| 52 | """ |
| 53 | Initialize the methodology extractor. |
| 54 | |
| 55 | Args: |
| 56 | config: AutoFigure SDK configuration |
| 57 | """ |
| 58 | self.config = config |
| 59 | self._llm_client = None |
| 60 | |
| 61 | @property |
| 62 | def llm_client(self): |
| 63 | """Lazy-load LLM client.""" |
| 64 | if self._llm_client is None: |
| 65 | from .utils.llm_client import create_client_from_config |
| 66 | self._llm_client = create_client_from_config(self.config, purpose="methodology") |
| 67 | return self._llm_client |
| 68 | |
| 69 | def extract_from_file(self, file_path: str) -> Optional[str]: |
| 70 | """ |
| 71 | Extract methodology from a file (PDF or Markdown). |
| 72 | |
| 73 | Args: |
| 74 | file_path: Path to the paper file |
| 75 | |
| 76 | Returns: |
| 77 | Extracted methodology description, or None on failure |
| 78 | """ |
| 79 | path = Path(file_path) |
| 80 | |
| 81 | if not path.exists(): |
| 82 | print(f"[MethodologyExtractor] File not found: {file_path}") |
| 83 | return None |
| 84 | |
| 85 | # Read content based on file type |
| 86 | content = self._read_file_content(path) |
| 87 | if not content: |
| 88 | return None |
| 89 | |
| 90 | return self.extract_from_text(content) |
| 91 | |
| 92 | def extract_from_text(self, text: str) -> Optional[str]: |
| 93 | """ |
| 94 | Extract methodology from raw text content. |
| 95 | |
| 96 | Args: |
| 97 | text: Paper text content |
| 98 | |
| 99 | Returns: |
| 100 | Extracted methodology description, or None on failure |
| 101 | """ |
| 102 | if not text or len(text.strip()) < 100: |
| 103 | print("[MethodologyExtractor] Text content too short") |