google books ngram viewer数据集的下载与使用

来源:互联网 发布:scada数据采集 编辑:程序博客网 时间:2024/05/16 15:28

最近在做有关word2vec的项目,需要使用到google books ngram viewer中的数据集。但是打开网页后发现,由于数据很大,google将数据集分成了很多个文件。我如果要下载的话,需要一个一个链接去点开下载,这样似乎很麻烦。

后来我无意中发现了一个Python的package,可以直接使用到google books ngram viewer上面的数据。

首先安装一下这个包:

pip install google-ngram-downloader

这个包有两种使用方式:

命令行工具

这个包提供了一个命令行工具:google-ngram-downloader . 它可以用于下载google books ngram viewer上面的数据集。用法如下:

google-ngram-downloader helpusage: google-ngram-downloader <command> [options]commands: cooccurrence  Write the cooccurrence frequencies of a word and its contexts. download      Download The Google Books Ngram Viewer dataset version 20120701. help          Show help for a given help topic or a help overview. readline      Print the raw content.

例如:

google-ngram-downloader download -n 5 #下载5-ngram的数据集google-ngram-downloader download -h   #查看帮助,会告诉你下载路径,下载的语言

作为python API

在Python代码中,可以这样获得数据:

>>> from google_ngram_downloader import readline_google_store>>>>>> fname, url, records = next(readline_google_store(ngram_len=5))>>> fname'googlebooks-eng-all-5gram-20120701-0.gz'>>> url'http://storage.googleapis.com/books/ngrams/books/googlebooks-eng-all-5gram-20120701-0.gz'>>> next(records)Record(ngram=u'0 " A most useful', year=1860, match_count=1, volume_count=1)

链接如下:
https://pypi.python.org/pypi/google-ngram-downloader/

原创粉丝点击