Files
Mastering-Python-2e-code_2/CH_16_machine_learning/T_03_spacy_extract.rst
T
2022-05-05 18:25:55 +02:00

17 lines
442 B
ReStructuredText

>>> import spacy
>>> import en_core_web_sm
>>> nlp = en_core_web_sm.load()
>>> _ = nlp.add_pipe("merge_entities")
>>> sentence = ('Python was introduced in 1989 by Guido van '
... 'Rossum at Stichting Mathematisch Centrum in Amsterdam.')
>>> for token in nlp(sentence):
... if token.ent_type_:
... print(f'{token.ent_type_}: {token.text}')
DATE: 1989
PERSON: Guido van Rossum
ORG: Stichting Mathematisch Centrum
GPE: Amsterdam