示例#1
0
  @Override
  public void map(LongWritable key, Text value, Context context)
      throws IOException, InterruptedException {
    String str = "1\t" + value.toString();
    Kvector vector = Kvector.fromString(str);

    int code = -1, d = Integer.MAX_VALUE;
    for (Kvector e : m_kVectors) {
      int t = vector.distance(e);
      if (t < d) {
        d = t;
        code = e.code;
      }
    }

    context.write(new KcodeWritable(code), new Text(str));
  }
示例#2
0
  @Override
  public void setup(Context context) throws IOException {
    Configuration conf = context.getConfiguration();

    int num = Integer.parseInt(conf.get("kvNum"));
    while (--num >= 0) {
      String s = conf.get(String.valueOf(num));
      m_kVectors.add(Kvector.fromString(s));
    }
  }