File size: 525 Bytes
3ef03d3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

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