维基百科api似乎几乎总是把有问题的词弄错了
我正在使用 wikipedia python 库(https://pypi.org/project/wikipedia/),在大多数情况下,它似乎会自动更正我正在使用的术语或其他东西,因此它们经常是错误的。
例如,“frog”变成“food”,“crown”变成“cross”:
input: wikipedia.page("frog")
output: <WikipediaPage 'Food'>
input: wikipedia.summary("Frog")
output: 'Food is any substance consumed to provide nutritional support for an organism..."
input: wikipedia.page("crown")
output: <WikipediaPage 'Cross'>
使用 wikipedia.search 时,它似乎提供了一个适当的列表,但我不知道如何在使用 .summary 等时利用它来获取正确的页面:
input: print(wikipedia.search("frog"))
output: ['Frog', 'FROG', 'The Princess and the Frog', 'Boiling frog', 'Frog legs', 'Frogger', 'The Scorpion and the Frog', 'Pepe the Frog', 'The Frog Prince', 'Common frog']
回答
这是由于默认auto_suggest的summary()是True。
根据文档,您可以将其更改为False,它将正确返回frog.
wikipedia.summary("Frog", auto_suggest=False)
#'A frog is any member of a diverse and largely carnivorous group of short-bodied, tailless amphibians composing the order Anura (literally without tail in Ancient Greek)
看来,无论出于什么奇怪的原因,该API's suggest()功能都......很奇怪。这很可能是最好保持auto_suggest到False..
wikipedia.suggest("Frog")
#'food'
wikipedia.suggest("Steak")
#'steam'
wikipedia.suggest("Dog")
#'do'
wikipedia.suggest("cat")
#'cats'
wikipedia.suggest("david attenborough")
#None