Wiktionary Parser for Python 3.6_ only for definitions

1.6k views Asked by At

I am trying to parse the definitions of target English word from "en.Wiktionary.org"

I had considered already existing module(https://github.com/Suyash458/WiktionaryParser/blob/master/readme.md) ,however, it parses redundancies to my purpose - such as etymology, related words, pronounciation and examples.

How could I only parse the definitions according to the Part of Speech?

Any recommendation or advice would be grateful.

1

There are 1 answers

0
Bill Bell On

Is this what you mean?

>>> from wiktionaryparser import WiktionaryParser
>>> parser = WiktionaryParser()
>>> word = parser.fetch('satiate', 'english')
>>> for item in word[0]['definitions']:
...     item['partOfSpeech'], item['text']
... 
('verb', 'satiate (third-person singular simple present satiates, present participle satiating, simple past and past participle satiated)\n(transitive) To fill to satisfaction; to satisfy.Nothing seemed to satiate her desire for knowledge.\n(transitive) To satisfy to excess. To fill to satiety.\n')
('adjective', "satiate (comparative more satiate, superlative most satiate)\nFilled to satisfaction or to excess.Alexander PopeOur generals now, retir'd to their estates,Hang their old trophies o'er the garden gates;In life's cool evening satiate of applause […]\nAlexander PopeOur generals now, retir'd to their estates,Hang their old trophies o'er the garden gates;In life's cool evening satiate of applause […]\n")

>>> word = parser.fetch('arrondissement', 'french')
>>> for item in word[0]['definitions']:
...     item['partOfSpeech'], item['text']
... 
('noun', 'arrondissement\xa0m (plural arrondissements)\nArrondissement\n(Canada) Arrondissement, a borough (submunicipal administrative division)\n')

When you ask for a word this library returns a somewhat complicated structure of lists and dictionaries. You might just need for practice in manipulating them.