MCP_Res / mcp /nlp.py
mgbam's picture
Create nlp.py
0a3aede verified
raw
history blame
369 Bytes
# mcp/nlp.py
import spacy
try:
nlp = spacy.load("en_core_sci_sm")
except Exception:
nlp = spacy.load("en_core_web_sm") # Fallback to general English
def extract_keywords(text: str):
"""Extract biomedical entities and drugs from text."""
doc = nlp(text)
keywords = list(set(ent.text for ent in doc.ents if len(ent.text) > 2))
return keywords