Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python3.6的Wiktionary解析器仅用于定义_Python_Parsing_Wiktionary - Fatal编程技术网

Python3.6的Wiktionary解析器仅用于定义

Python3.6的Wiktionary解析器仅用于定义,python,parsing,wiktionary,Python,Parsing,Wiktionary,我试图解析“en.Wiktionary.org”中目标英语单词的定义 我曾经考虑过已经存在的module(),但是,它会根据我的目的解析冗余内容,例如词源、相关单词、发音和示例 我怎么能只根据词性来解析定义呢 任何建议都将不胜感激。这就是你的意思吗 >>> from wiktionaryparser import WiktionaryParser >>> parser = WiktionaryParser() >>> word = parse

我试图解析“en.Wiktionary.org”中目标英语单词的定义

我曾经考虑过已经存在的module(),但是,它会根据我的目的解析冗余内容,例如词源、相关单词、发音和示例

我怎么能只根据词性来解析定义呢

任何建议都将不胜感激。

这就是你的意思吗

>>> 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')

当你需要一个单词时,这个库返回一个有点复杂的列表和字典结构。您可能只需要练习操作它们。

您尝试过什么?粘贴代码和错误。事实上,我正在查看WikiParse.py(在给定的链接中可以找到),并尝试稍微修改它,只返回定义,而不返回词源、相关、发音和示例。但是keep会为我返回错误,因为我之前没有漂亮的Soap和json的背景。