我如何使用 google ngram 查看器和 python 出现一个句子?

问题描述

简短的背景:我尝试在 python 中通过 Peter Norvig 增强拼写校正器。从这个意义上说,我需要出现一个句子(最多 3-4 个单词)... Ngram viewer from Google我有很大帮助,但我不知道我如何通过 API 或其他东西获得价值。

代码

# Sentence without meaning but word for word correct.
>> occurrence("were are you")
0.0000000978

# Sentence that makes sense
>> occurrence("where are you")
0.000148

# Then my method should return the sentence with the highest value. (But thats not the problem)

对不起我的英语:-D 谢谢!

解决方法

他们实际上有一个未公开的 API。

import requests
import json

term = "where are you"
url =f"https://books.google.com/ngrams/json?content={term}&year_start=1800&year_end=2000&corpus=26&smoothing=3"
resp = requests.get(url)
if resp.ok:
  results = json.loads(resp.content)

results[0]['timeseries'] 具有您需要的频率:

[2.854326695000964e-07,3.4926038665616944e-07,3.3916604043800663e-07,...]

来源:https://jameshfisher.com/2018/11/25/google-ngram-api/

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...