Package com.chine.kmeans.mapreduce.canopymaker

Source Code of com.chine.kmeans.mapreduce.canopymaker.CanopyMakerMapper

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));
    }

  }
}
TOP

Related Classes of com.chine.kmeans.mapreduce.canopymaker.CanopyMakerMapper

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.