SpacyGrounder
- class SpacyGrounder(matcher: Matcher[R], spacy_model: str | spacy.Language)[source]
Bases:
Grounder[R],WrappedMatcher[R],Generic[R]An annotator that works via spacy.
Warning
SpaCy is very difficult to get working on modern versions of Python, due to its dependence on NumPy’s pre-2.0 release. You’re on your own, good luck!
Create a grounder based on a pre-defined matcher and a SpaCy NER model.
- Parameters:
matcher – A pre-defined matcher
spacy_model – The name of a SpaCy model. See https://allenai.github.io/scispacy/ for a list of biomedical and clincal NER models from
scispacy.
In the following example, a SpaCy grounder is instantiated using an underlying Gilda matcher, which incorporates the disease branch of Medical Subject Headings (MeSH). You’ll need to install a SciSpaCy model first with
pip install https://s3-us-west-2.amazonaws.com/ai2-s2-scispacy/releases/v0.5.4/en_core_sci_sm-0.5.4.tar.gz.import spacy from ssslm import GildaMatcher, SpacyGrounder spacy_model = spacy.load("en_core_sci_sm") matcher = GildaMatcher.default() grounder = SpacyGrounder( matcher=matcher, spacy_model=spacy_model, ) annotations = grounder.annotate( "The APOE e4 mutation is correlated with risk for Alzheimer's disease." )
Methods Summary
annotate(text, **kwargs)Annotate the text using a combination of the spacy annotator, and the wrapped matcher.
Methods Documentation