database - 如何按频率对 Google 数据库(或托管在 AWS 上的数据库)中的 ngram 进行排序

标签 database hadoop

我正在寻找一种按频率订购 Google Book 的 Ngram 的方法。

原始数据集在这里:http://books.google.com/ngrams/datasets .在每个文件中,ngram 按字母顺序排序,然后按时间顺序排序。

我的电脑不够强大,无法处理 2.2 TB 的数据,所以我认为唯一的排序方式是“在云端”。

AWS 托管版本在这里:http://aws.amazon.com/datasets/8172056142375670 .

是否有经济有效的方法来找到 10,000 个最常见的 1grams、2grams、3grams、4grams 和 5grams?

麻烦的是,数据集包含多年的数据:

As an example, here are the 30,000,000th and 30,000,001st lines from file 0 
of the English 1-grams (googlebooks-eng-all-1gram-20090715-0.csv.zip):

circumvallate   1978   313    215   85 
circumvallate   1979   183    147   77

The first line tells us that in 1978, the word "circumvallate" (which means 
"surround with a rampart or other fortification", in case you were wondering) 
occurred 313 times overall, on 215 distinct pages and in 85 distinct books 
from our sample.

理想情况下,频率列表只包含 1980 年至今的数据(每年的总和)。

如有任何帮助,我们将不胜感激!

干杯,

最佳答案

我建议使用 Pig !

Pig 使此类事情变得非常简单直接。这是一个示例 pig 脚本,它几乎可以满足您的需要:

raw = LOAD '/foo/input' USING PigStorage('\t') AS (ngram:chararray, year:int, count:int, pages:int, books:int);
filtered = FILTER raw BY year >= 1980;
grouped = GROUP filtered BY ngram;
counts = FOREACH grouped GENERATE group AS ngram, SUM(filtered.count) AS count;
sorted = ORDER counts BY count DESC;
limited = LIMIT sorted 10000;
STORED limited INTO '/foo/output' USING PigStorage('\t');

AWS Elastic MapReduce 上的 Pig 甚至可以直接对 S3 数据进行操作,因此您可能也会用 S3 存储桶替换 /foo/input/foo/output

关于database - 如何按频率对 Google 数据库(或托管在 AWS 上的数据库)中的 ngram 进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12455658/

相关文章:

java - 在 Hadoop 中拆分Reducer 输出

hadoop - 我正在通过使用自由格式查询和使用where条件来进行sqoop导入

logging - Hadoop 守护进程日志

database - 如何使用反射调用扫描可变参数函数

sql - 比较具有大量数据的两组以找到相同的值

mysql - 在 OSX Sierra 中找不到错误 MySQL 服务器 PID 文件

hadoop - 我对hadoop 2.7感到困惑。运行start-all.sh之后,在jps列表中找不到jobtracker和tasktracker,为什么?

java - 通过 Java API 从远程主机访问 HDFS,用户身份验证

database - 导出 SPSS 变量标签

java - 需要帮助来创建数据库 (Java)