package com.chine.kmeans.mapreduce.canopymaker;
import java.io.IOException;
import java.util.List;
import java.util.ArrayList;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.io.Text;
import com.chine.kmeans.models.Movie;
import com.chine.kmeans.mapreduce.ConfiguredKmeans;
public class CanopyMakerMapper extends Mapper<Text, Text, Text, Text> {
private List<Movie> canopyMovieCenters;
@Override
public void setup(Context context) {
this.canopyMovieCenters = new ArrayList<Movie>();
}
@Override
public void map(Text key, Text value, Context context) throws IOException,
InterruptedException {
int movieId = Integer.valueOf(key.toString());
String data = value.toString();
Movie currentMovie = new Movie(movieId, data);
boolean tooClose = false;
for (Movie m : canopyMovieCenters) {
if (m.getMatchCount(currentMovie) >= ConfiguredKmeans.T1) {
tooClose = true;
break;
}
}
if (!tooClose) {
canopyMovieCenters.add(currentMovie);
context.write(key, new Text(key.toString() + ":" + data));
}
}
}