Extract the first author's institution from paper content. Args: paper_content: Text content of the paper (markdown format) Returns: First author's institution if found and matched with available logos
(self, paper_content: str)
| 338 | } |
| 339 | |
| 340 | def extract_first_author_institution(self, paper_content: str) -> Optional[str]: |
| 341 | """ |
| 342 | Extract the first author's institution from paper content. |
| 343 | |
| 344 | Args: |
| 345 | paper_content: Text content of the paper (markdown format) |
| 346 | |
| 347 | Returns: |
| 348 | First author's institution if found and matched with available logos |
| 349 | """ |
| 350 | print(" 📝 Looking for first author's institution...") |
| 351 | |
| 352 | # Look for authors section in the beginning of the paper |
| 353 | lines = paper_content.split('\n')[:100] # Focus on first 100 lines where authors usually appear |
| 354 | |
| 355 | # Common institution patterns |
| 356 | institution_patterns = [ |
| 357 | r"(?:University of|University) [\w\s]+", |
| 358 | r"[\w\s]+ University", |
| 359 | r"[\w\s]+ Institute of Technology", |
| 360 | r"[\w\s]+ Institute", |
| 361 | r"MIT|CMU|UCLA|UCSD|NYU|ETH|EPFL|Stanford|Berkeley|Harvard|Princeton|Oxford|Cambridge", |
| 362 | r"Google Research|DeepMind|Microsoft Research|Facebook AI Research|OpenAI|NVIDIA Research", |
| 363 | r"Max Planck Institute", |
| 364 | r"[\w\s]+ College", |
| 365 | r"[\w\s]+ Research", |
| 366 | r"[\w\s]+ Lab", |
| 367 | r"[\w\s]+ Laboratory" |
| 368 | ] |
| 369 | |
| 370 | all_pattern = '|'.join(f'({p})' for p in institution_patterns) |
| 371 | |
| 372 | # First pass: Look for the first line with superscript 1 (¹) which typically indicates first author affiliation |
| 373 | first_institution = None |
| 374 | for i, line in enumerate(lines): |
| 375 | # Stop at abstract or introduction |
| 376 | if 'abstract' in line.lower() or 'introduction' in line.lower(): |
| 377 | break |
| 378 | |
| 379 | # Look for lines with ¹ (first affiliation marker) at the beginning |
| 380 | if '¹' in line: |
| 381 | # Use finditer on each pattern individually to find all matches |
| 382 | # This avoids the issue where re.findall() with alternation only finds non-overlapping matches |
| 383 | all_matches = [] |
| 384 | for pattern_idx, pattern in enumerate(institution_patterns): |
| 385 | for match in re.finditer(pattern, line, re.IGNORECASE): |
| 386 | matched_text = match.group() |
| 387 | # Filter out very short matches (1-2 chars) but allow valid abbreviations (MIT, NYU, etc.) |
| 388 | if matched_text and len(matched_text.strip()) >= 3: |
| 389 | all_matches.append((match.start(), matched_text.strip(), pattern_idx)) |
| 390 | |
| 391 | if all_matches: |
| 392 | # Prioritize pattern 0 (University of X) over pattern 1 (X University) |
| 393 | pattern0_matches = [m for m in all_matches if m[2] == 0] |
| 394 | if pattern0_matches: |
| 395 | first_institution = pattern0_matches[0][1] # Take first pattern 0 match |
| 396 | print(f" 🎯 Found first author institution (from affiliation marker): {first_institution}") |
| 397 | break |