"""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 | |