MedQA / backend /umls_linker.py
mgbam's picture
Upload 4 files
3ef03d3 verified
raw
history blame contribute delete
525 Bytes
"""Simple UMLS linker using SciSpacy."""
import spacy
from scispacy.linking import UmlsEntityLinker
nlp = spacy.load("en_core_sci_lg")
linker = UmlsEntityLinker(resolve_abbreviations=True, disambiguate=True)
nlp.add_pipe(linker)
def link_umls(text: str):
doc = nlp(text)
results = []
for ent in doc.ents:
for cui, score in ent._.kb_ents:
results.append(
{"text": ent.text, "cui": cui, "score": score}
)
break # take top candidate
return results