の素朴なユーザーです。あなたは非常に簡単なuser-defined functionを書く必要があります。
-- load the data line by line
lines = LOAD 'datafile.txt' USING TextLoader() AS (line:chararray);
-- apply some sort of UDF that returns the exact line without the stop words
nostop = FOREACH lines GENERATE myudfs.removestop(line);
-- store the data out
STORE nonstop INTO 'datafile_nostop.txt';
あなたのリストをタスクにプッシュすることは別の話です。リストが比較的小さく、数千のオーダーであれば、ストップワードをコードに焼いて(つまり、リストをハードコーディングして)利用できるようにすることができます。それ以外の場合は、分散キャッシュを使用してファイルをプッシュアウトすることができます。
さらに詳しい情報をお伝えして、私は別の方法を提案できます。私の上記のUDFのアプローチは有効です。
この新しい方法では、他のファイルを読み込み、効果的に反結合を行ってリストに一致するものを削除します。これを行うには、stopwords.txt
に1行に1語が含まれていることを確認する必要があります。アンチ・ジョインを行うには(replicatedを使用して)left outer joinを実行し、ストップ・ワードの列がヌルである場所をフィルタリングします(つまり、一致したストップワードを持つ)。
A = load '/home/wrdtest.txt';
-- load the stop words list
SW = load '/home/stopwords.txt' as (stopword:chararray);
B = foreach A generate flatten(TOKENIZE((chararray)$0)) as word;
-- join the data with a left outer join
-- using replicated should be done with the right relation (SW) is small
SW2 = join B by word LEFT OUTER, SW by stopword USING 'replicated';
-- filter out where the stopword is null, meaning it is not in the stopword list
C = filter SW2 by stopword IS NULL;
-- remove the stopword column that we don't need.
C = foreach C generate word;
D = group C by word;
E = foreach D generate COUNT(C) as count, group as word;
F = order E by count desc;
store F into '/tmp/sample_data20';
要約で作成した最新の編集をお勧めします。私は現在作業中のコードを提供しています。 – Debaditya
私の回答を更新しました –
私はコードを実行しました。しかし、結果は同じように見えます。マイstopwords.txt構造 は....行につき つの単語です。 – Debaditya