PIG 中嵌套元组中的引用字段;

发布于 2024-12-27 04:38:28 字数 2531 浏览 2 评论 0原文

我已经被困在这个问题上几个小时了,我不知道我做错了什么。 我有一个关系“分组”,其模式

    grouped: {seedword: chararray,baggy: {outertup: (groupy: (seedword: chararray,coword: chararray))}}

为该关系的示例: (auto,{((auto,car)),((auto,truck))})

我需要生成种子词和共词元组。在我的例子中,我想要

(汽车,(汽车,卡车))。

我已经尝试过:

 FOREACH grouped GENERATE baggy::outertup.groupy.coword;

 FOREACH grouped GENERATE baggy.outertup.groupy.coword;
 FOREACH grouped GENERATE baggy.groupy.coword;

但这些都不起作用,并给我错误消息说没有这样的字段。请帮忙! !!

这是我的更多代码:

keywords = LOAD 'merged' USING as ( seedword:chararray, doc:chararray);

---COUNT HOW MANY DOCUMENTS EACH WORD IS IN
group_by_seedword = GROUP keywords BY $0;

invert_index = FOREACH group_by_seedword GENERATE $0 as seedword:chararray, keywords.$1;
word_doc_count= FOREACH invert_index GENERATE seedword, COUNT($1);

-- map words to document
words_in_doc= GROUP keywords BY doc;
word_docs = FOREACH words_in_doc GENERATE group AS doc, keywords.seedword;
--(document:(keyword, keyword, keyword...))

--map words to their cowords in doc
temp_join = JOIN keywords BY doc,word_docs BY doc;
--DUMP temp_join;
cowords_by_doc = FOREACH temp_join GENERATE $0 as seedword:chararray, $3 as cowords;

cowords_interm=  FOREACH cowords_by_doc GENERATE seedword, FLATTEN(cowords);
cowords = FILTER cowords_interm BY (seedword!=$1);---GETS RID OF SINGLE DOC WORD; 
temp_join_count1 = JOIN cowords BY $0, word_doc_count BY seedword; 

-- GETS WORDS THAT OCCURE BY THEMSELVES IN A SINGLE DOCUMENT
G = JOIN cowords_interm BY $0 LEFT OUTER, cowords by $0;
orph_word = FILTER G BY $2 is null;
orph_word_count = FOREACH orph_word GENERATE $0,null, 0;

temp_join_count= UNION temp_join_count1, orph_word_count; 

inter_frac = FOREACH temp_join_count GENERATE $0 as seedword:chararray, $1 as coword:chararray, 1.0/$3 as frac:double;
inter_frac_combine = GROUP inter_frac BY (seedword, coword); 
inter_frac_sum = FOREACH inter_frac_combine GENERATE $0 , SUM(inter_frac.frac) as frac:double;

filtered = FILTER inter_frac_sum BY ($1 >=$relatedness_ratio);
grouped= GROUP filtered by $0.seedword;
g = FOREACH grouped GENERATE group as seedword:chararray, filtered.$0;   
named = FOREACH g GENERATE $0 as seedword:chararray, $1 as baggy:bag{(outertup:tuple(groupy:tuple(seedword:chararray, coword:chararray)))};

您可以尝试的输入文件应该如下所示:

car doc1.txt
auto doc1.txt
bunny doc2.txt
ball doc2.txt
toy car doc2.txt
random doc3.txt

plane doc3.txt

I have been stuck on this for several hours and I cannot figure out what I am doing wrong.
I have a relation "grouped" with the schema of

    grouped: {seedword: chararray,baggy: {outertup: (groupy: (seedword: chararray,coword: chararray))}}

A sample of what the relation looks like is:
(auto,{((auto,car)),((auto,truck))})

I need to generate just the seedword and a tuple of cowords. In my example I would want

(auto, (car, truck)).

I have tried:

 FOREACH grouped GENERATE baggy::outertup.groupy.coword;

 FOREACH grouped GENERATE baggy.outertup.groupy.coword;
 FOREACH grouped GENERATE baggy.groupy.coword;

and none of these work, and give me error messages saying there is no such field. Please help! !!

HEre's some more of my code:

keywords = LOAD 'merged' USING as ( seedword:chararray, doc:chararray);

---COUNT HOW MANY DOCUMENTS EACH WORD IS IN
group_by_seedword = GROUP keywords BY $0;

invert_index = FOREACH group_by_seedword GENERATE $0 as seedword:chararray, keywords.$1;
word_doc_count= FOREACH invert_index GENERATE seedword, COUNT($1);

-- map words to document
words_in_doc= GROUP keywords BY doc;
word_docs = FOREACH words_in_doc GENERATE group AS doc, keywords.seedword;
--(document:(keyword, keyword, keyword...))

--map words to their cowords in doc
temp_join = JOIN keywords BY doc,word_docs BY doc;
--DUMP temp_join;
cowords_by_doc = FOREACH temp_join GENERATE $0 as seedword:chararray, $3 as cowords;

cowords_interm=  FOREACH cowords_by_doc GENERATE seedword, FLATTEN(cowords);
cowords = FILTER cowords_interm BY (seedword!=$1);---GETS RID OF SINGLE DOC WORD; 
temp_join_count1 = JOIN cowords BY $0, word_doc_count BY seedword; 

-- GETS WORDS THAT OCCURE BY THEMSELVES IN A SINGLE DOCUMENT
G = JOIN cowords_interm BY $0 LEFT OUTER, cowords by $0;
orph_word = FILTER G BY $2 is null;
orph_word_count = FOREACH orph_word GENERATE $0,null, 0;

temp_join_count= UNION temp_join_count1, orph_word_count; 

inter_frac = FOREACH temp_join_count GENERATE $0 as seedword:chararray, $1 as coword:chararray, 1.0/$3 as frac:double;
inter_frac_combine = GROUP inter_frac BY (seedword, coword); 
inter_frac_sum = FOREACH inter_frac_combine GENERATE $0 , SUM(inter_frac.frac) as frac:double;

filtered = FILTER inter_frac_sum BY ($1 >=$relatedness_ratio);
grouped= GROUP filtered by $0.seedword;
g = FOREACH grouped GENERATE group as seedword:chararray, filtered.$0;   
named = FOREACH g GENERATE $0 as seedword:chararray, $1 as baggy:bag{(outertup:tuple(groupy:tuple(seedword:chararray, coword:chararray)))};

the input file you can try should be like this:

car doc1.txt
auto doc1.txt
bunny doc2.txt
ball doc2.txt
toy car doc2.txt
random doc3.txt

plane doc3.txt

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一袭白衣梦中忆 2025-01-03 04:38:28

我遇到了类似的问题,无法引用内部元组。
我的解决方案是扁平化数据,然后进行更多过滤和分组。
干杯
V

I'd had a similar issue where I couldn't reference inner tuples.
My solution was to flatten the data and then some more filtering and grouping.
Cheers
V

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文