Code: Select all
Traceback (most recent call last):
File "", line 2, in
File "", line 5, in extract_topics
File "C:\Users\Emma\AppData\Local\Programs\Python\Python312\Lib\site-packages\spacy\tokens\underscore.py", line 48, in __getattr__
raise AttributeError(Errors.E046.format(name=name))
AttributeError: [E046] Can't retrieve unregistered extension attribute 'umls_ents'. Did you forget to call the `set_extension` method?
< /code>
Ich weiß nicht wirklich, was die set_extension -Methode ist. Ich habe schon add_pipe auf der NLP gemacht. Hier ist mein Code: < /p>
import spacy
import scispacy
from scispacy.linking import EntityLinker
nlp = spacy.load("en_core_sci_sm")
linker = EntityLinker(name="umls")
nlp.add_pipe("scispacy_linker", config={"linker_name": "umls"})
def extract_topics(text):
doc = nlp(text)
topic_set = set()
for ent in doc.ents:
for umls_ent in ent._.umls_ents:
concept = linker.umls.cui_to_entity[umls_ent[0]]
topic_set.add(concept.canonical_name)
return list(topic_set) if topic_set else ["Unknown"]