spaCy Wordnet
A simple extension for spaCy to leverage WordNet, one of the richest knowledge databases in the world. Use your favorite NLP tool together with a powerful dictionary.

I want to withdraw 100 euros

draw
take out
draw off

need
require

      
        import spacy
        from spacy_wordnet.wordnet_annotator import WordnetAnnotator
        # Load an spacy model (supported models are "es" and "en")
        nlp = spacy.load('en')
        nlp.add_pipe(WordnetAnnotator(nlp.lang), after='tagger')
        token = nlp('prices')[0]
# wordnet object link spacy token with nltk wordnet interface by giving acces to token._.wordnet.synsets() token._.wordnet.lemmas()
# And automatically tags with wordnet domains token._.wordnet.wordnet_domains()
# spaCy WordNet lets you find synonyms by domain of interest for example economy sentence = nlp('I want to withdraw 5,000 euros') economy_domains = ['finance', 'banking']
token_with_synsets = [(token, token._.wordnet.wordnet_synsets_for_domain(economy_domains)) for token in sentence] enriched_sentence = [] for token, synsets in token_with_synsets:     if not synsets:         enriched_sentence.append(token.text)     else:         lemmas_for_synset = {lemma for s in synsets for lemma in s.lemma_names()}         enriched_sentence.append('({})'.format('|'.join(lemmas_for_synset))) print(' '.join(enriched_sentence)) # >> I (need|want|require) to (draw|withdraw|draw_off|take_out) 5,000 euros

Want to save precious time with natural language processing and focus on value-added work?

contact us

Contact us

We are based in Madrid come visit us at:

Airbus BizLab Madrid
Calle de Manzanares, 4
Madrid Spain, 28005