【问题标题】:Apache Pig: Removing Stopwords from Bag of Token Tuples?Apache Pig:从标记元组包中删除停用词?
【发布时间】:2016-05-20 10:05:04
【问题描述】:

我正在尝试使用 Pig 从职位描述关系中删除停用词。但是我无法加入两个关系以将停用词与我的文本匹配。

我的数据是一个 csv 文件,每行有两个条目:

我还有一个包含 630 个英语停用词的列表:

在 Pig 中,我正在加载两个文件并按以下方式转换第一个文件:

 jobs10 = load 'data/hw4/jobs/20140213_descriptions10.csv' using PigStorage(',') as (id:chararray,descr:chararray);
 descrFlat = foreach jobs10 generate id,flatten(TOKENIZE(descr));
 stopwords = load 'data/hw4/stopwords-en.txt' using PigStorage('\n') as (word:chararray);

descrFlat 现在看起来像这样:

grunt> describe descrFlat
descrFlat: {id: chararray,bag_of_tokenTuples_from_descr::token: chararray}

类似于thisthis 示例,我现在正在尝试将这两个文件进行OUTER JOIN...

J = JOIN stopwords BY $0 RIGHT OUTER, descrFlat BY $0;

...导致J 的以下结构:

grunt> describe J
J: {stopwords::word: chararray,descrFlat::id: chararray,descrFlat::bag_of_tokenTuples_from_descr::token: chararray}

但这并不是使用K = FILTER J BY $0 IS NULL; 的期望结果;数据只是胡言乱语:

grunt> dump J

这可能是因为我使用的是一袋令牌元组,而不是上述示例中的简单元组。

【问题讨论】:

    标签: join apache-pig stop-words


    【解决方案1】:

    我发现了我的错误。下面指的是 descrFlat 中的第一列,而它实际上应该指的是第二列 ($1),其中包含单词。此外,删除不必要的标点也有帮助。

    J = JOIN stopwords BY $0 RIGHT OUTER, descrFlat BY $0;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-21
      • 2021-09-16
      • 2013-07-11
      • 1970-01-01
      相关资源
      最近更新 更多