allenai / scispacy

A full spaCy pipeline and models for scientific/biomedical documents.
https://allenai.github.io/scispacy/
Apache License 2.0
1.68k stars 225 forks source link

RxCUIs when 'rxnorm' is selected #435

Closed jeonge1 closed 2 years ago

jeonge1 commented 2 years ago

Hi,

First and foremost, thank you so much for all of your efforts on scispacy! 👍 When "linker_name": "rxnorm" is selected for NER, can we get the RxCUI of an entity as well as the CUI? This is the code I used:

from scispacy.linking import EntityLinker
import spacy, scispacy

def mesh_extractor(text):
    doc = nlp(text)
    for e in doc.ents:
        if e._.kb_ents:
            rxcui = e._.kb_ents[0][0]
            print(e, rxcui)

config = {
    "resolve_abbreviations": True,  
    "linker_name": "rxnorm"
    }
nlp = spacy.load("en_core_sci_lg")
nlp.add_pipe("scispacy_linker", config=config) 
linker = nlp.get_pipe("scispacy_linker")

text = "The Aspirin was not helpful so I took Advil to help with my headache."
mesh_extractor(text)

and I only got CUIs, no RxCUIs:

Aspirin C0004057
Advil C0593507

Is there any way to map CUI to get RxCUI ? Thank you

dakinggg commented 2 years ago

Hi sorry, I do not know of a way, and the docs seem to say that CUI to RxCUI is not a 1:1 mapping anyway. Looks to be some discussion of this here (http://disi.unitn.it/~p2p/RelatedWork/Matching/PIIS1532046412000950.pdf) although I did not read closely.