首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用google ngram查看器和python获取句子的出现情况?

如何使用google ngram查看器和python获取句子的出现情况?
EN

Stack Overflow用户
提问于 2021-05-29 23:29:27
回答 1查看 58关注 0票数 0

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

伪代码:

代码语言:javascript
复制
# 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谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-05-30 17:41:06

他们实际上有一个未记录的api。

代码语言:javascript
复制
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']拥有您需要的频率:

代码语言:javascript
复制
[2.854326695000964e-07,
 3.4926038665616944e-07,
 3.3916604043800663e-07,
 ...]

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67753096

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档