python - Wikipedia api python 返回奇怪的结果

标签 python wikipedia wikipedia-api pywikibot

import wikipedia

print(wikipedia.summary("Tomato", sentences=3))

为什么此代码会返回“tom tom”的消歧错误,而不仅仅是条目“tomato”的摘要/消歧错误? 搜索词显然不是 tom tom 或者我在这里遗漏了什么?为什么这行不通?

最佳答案

搜索 "Tomato" 会得到建议 "tom tom"。不知道为什么...无论如何,您可以在 wikipedia.summary 中禁用 auto_suggest:

import wikipedia

wikipedia.summary("Tomato", sentences=3, auto_suggest=False)

输出是

'The tomato is the edible, often red, berry of the plant Solanum lycopersicum, commonly known as a tomato plant.  The species originated in western South America and Central America. The Nahuatl (the language used by the Aztecs) word tomatl gave rise to the Spanish word tomate, from which the English word tomato derived.'

您可以看到,使用 wikipedia.search 函数搜索 "Tomato" 会提示 "tom tom":

results, suggestion = wikipedia.search("Tomato", suggestion=True)

suggestion"tom tom"results是与tomato密切相关的标题列表。

关于python - Wikipedia api python 返回奇怪的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63059866/

相关文章:

javascript - 使用维基百科的 opensearch api 时,主题标签符号不会填充数据列表。为什么?

python - 将我的 virtualenv 目录放在我的 git 存储库中是不是很糟糕?

python - 如何迭代 grib2 文件的纬度经度值?

python - 为什么保存到数据库后 CreateView 中的 self.object 没有 id?

php - 如何使用维基百科 API 从维基百科的类别页面获取所有子类别?

jquery - 使用 jQuery 的 MediaWiki API 没有响应

python - Python 如何访问 X11 剪贴板?

wikipedia - 从维基百科挖掘人群

javascript - api调用后如何获取对象数据?

c# - 如何通过 API 从维基百科获取地标性地点的标题?