1
同じ行に複数の単語が他の単語と一緒に表示される回数と同じように、テキスト内の単語の同時発生をカウントしたいと考えています。そのために、特別なクラスの単語ペアを作成しました。そのため、MapReduceは私に単語のペアを与え、次にカウントを与えます。事は、私は異なる単語の共起だけを表示したいです。MapReduceで同じ単語のペアを削除する
これはコードです:
public class Co_OcurrenciaMapper extends Mapper<LongWritable, Text, Par, IntWritable> {
@Override
public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
IntWritable one = new IntWritable(1);
String[] palabras = value.toString().split("\\W+");
String palabra = new String();
String vecino = new String();
if (palabras.length > 1) {
for (int i = 0; i < palabras.length - 1; i++) {
for (int j = i + 1; j < palabras.length; j++) {
palabra = palabras[i];
vecino = palabras[j];
if (palabra.length() == 0 || vecino.length() == 0 || Character.isDigit(palabra.charAt(0)) || Character.isDigit(vecino.charAt(0))) {
continue;
}
if (palabra.compareTo(vecino) != 0) {
context.write(new Par(palabras[i], palabras[j]), one); /* here I am trying to go to the next pair if the words in the current pair are the same */
}
}
}
}
}
}
}
は「パー」は単語のペアを含む新しいクラスです。
そして、これはマッパ出力されます:
[[email protected] ~]$ hadoop fs -cat salidaO34/part-r-00000 |tail -15
Par [young , youthful] 1
Par [younger , your] 5
Par [your , your] 88
Par [your , yours] 23
Par [your , yourself] 36
Par [your , yourselves] 8
Par [your , youth] 18
Par [your , youthful] 3
Par [your , zeal] 3
Par [your , zir] 1
Par [your , zounds] 1
Par [yours , yours] 2
Par [yours , yourself] 3
Par [yours , zeal] 1
Par [yourself , yourself] 1
そして、あなたは私が同じである単語のペアを持っていることがわかります。
「palabras [i] .equals(palabras [j])」を比較するだけでいいですか? –