Clean abstract text Args: abstract_text: Raw abstract Returns: Cleaned abstract
(abstract_text: str)
| 63 | |
| 64 | |
| 65 | def clean_abstract(abstract_text: str) -> str: |
| 66 | """ |
| 67 | Clean abstract text |
| 68 | |
| 69 | Args: |
| 70 | abstract_text: Raw abstract |
| 71 | |
| 72 | Returns: |
| 73 | Cleaned abstract |
| 74 | """ |
| 75 | text = abstract_text |
| 76 | |
| 77 | # Remove LaTeX formulas |
| 78 | text = re.sub(r'\$[^$]+\$', '[FORMULA]', text) |
| 79 | text = re.sub(r'\\\[.*?\\\]', '[FORMULA]', text, flags=re.DOTALL) |
| 80 | text = re.sub(r'\\begin\{.*?\}.*?\\end\{.*?\}', '[FORMULA]', text, flags=re.DOTALL) |
| 81 | |
| 82 | # Remove citation markers |
| 83 | text = re.sub(r'\[\d+\]', '', text) |
| 84 | text = re.sub(r'\(\d+\)', '', text) |
| 85 | |
| 86 | # Compress whitespace |
| 87 | text = re.sub(r'\s+', ' ', text) |
| 88 | |
| 89 | # Remove special characters |
| 90 | text = re.sub(r'[^\w\s.,;:!?()\-\']', '', text) |
| 91 | |
| 92 | # Truncate if too long |
| 93 | if len(text) > 5000: |
| 94 | text = text[:4997] + "..." |
| 95 | |
| 96 | return text.strip() |
| 97 | |
| 98 | |
| 99 | def extract_keywords(text: str, top_k: int = 5) -> List[str]: |
no outgoing calls
no test coverage detected