我正在尝试从“en.Wiktionary.org”解析目标英语单词的定义
我考虑了已经存在的模块(https://github.com/Suyash458/WiktionaryParser/blob/master/readme.md),但是,它会根据我的目的解析冗余 - 例如词源、相关词、发音和示例。
我怎么能只根据词性解析定义?
任何建议或建议将不胜感激。
我正在尝试从“en.Wiktionary.org”解析目标英语单词的定义
我考虑了已经存在的模块(https://github.com/Suyash458/WiktionaryParser/blob/master/readme.md),但是,它会根据我的目的解析冗余 - 例如词源、相关词、发音和示例。
我怎么能只根据词性解析定义?
任何建议或建议将不胜感激。
你是这个意思吗?
>>> 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')
当你询问一个单词时,这个库返回一个有点复杂的列表和字典结构。您可能只需要练习操作它们。