// reduce(nid m, [d1,d2,...]) public void reduce(Text key, Iterable<NodeWritable> values, Context context) throws IOException, InterruptedException { float spokeVal = 0.0f; float hubVal = 0.0f; ArrayList<NodeWritable> arr = new ArrayList<NodeWritable>(); NodeWritable M = null; // Extract Original Node from Values for (NodeWritable x : values) { if (x.getNid().toString().equals(key.toString())) { M = new NodeWritable(x.toString()); break; } } // Store All Values in arr for (NodeWritable x : values) { arr.add(x); } // Create List of All In Nodes ArrayList<NodeWritable> ins = new ArrayList<NodeWritable>(); // Create List of all Out Nodes ArrayList<NodeWritable> outs = new ArrayList<NodeWritable>(); // Populate Above Lists for (NodeWritable x : arr) { if (!x.getIsInList().toString().equals("***")) { if (x.getIsInList().toString().equals("YES")) { ins.add(x); } else { if (x.getIsInList().toString().equals("NO")) { outs.add(x); } } } } // For Each Out nodes change the current hubVal for (NodeWritable t : outs) { hubVal += Float.parseFloat(t.getSpokeVal().toString()); } // For Each In Nodes change current spokeVal for (NodeWritable t : ins) { spokeVal += (Float.parseFloat(t.getHubVal().toString())); } // Set new Hub value M.getHubVal().set(hubVal); // Set new Spoke Value M.getSpokeVal().set(spokeVal); // Store current Node in Map map.put(M.getNid(), M); }
public void map(Object key, Text value, Context context) throws IOException, InterruptedException { NodeWritable n = new NodeWritable(value.toString().trim()); // Emit node to carry forward the Model. NodeWritable p = new NodeWritable(value.toString().trim()); p.setIsNode(new Text("YES")); p.setIsInList(new Text("***")); context.write(new Text(p.getNid().toString()), p); // For Each OutLinks Emit This Node for (NodeWritable x : n.getOuts()) { if (!x.getNid().toString().equals(n.getNid().toString())) { n.setIsInList(new Text("YES")); n.setIsNode(new Text("NO")); context.write(new Text(x.getNid().toString()), n); } } // For Each Inlinks Emit This Node for (NodeWritable x : n.getIns()) { if (!x.getNid().toString().equals(n.getNid().toString())) { n.setIsInList(new Text("NO")); n.setIsNode(new Text("NO")); context.write(new Text(x.getNid().toString()), n); } } }