Reducer<Text, Text, Text, Text> {
public void reduce(Text key, Iterator<Text> values,
OutputCollector<Text, Text> output, Reporter reporter)
throws IOException {
String vertexId = key.toString();
Vertex v = new Vertex(vertexId);
while (values.hasNext()) {
// neighbor/self edge_weight/inject_score
String val = values.next().toString();
String[] fields = val.split(_kDelim);
String msgType = fields[0];
String trgVertexId = fields[1];
if (msgType.equals(neighMsgType)) {
v.setNeighbor(trgVertexId, Double.parseDouble(fields[2]));
} else if (msgType.equals(goldLabMsgType)) {
v.setGoldLabel(trgVertexId, Double.parseDouble(fields[2]));
} else if (msgType.equals(injLabMsgType)) {
v.SetInjectedLabelScore(trgVertexId,
Double.parseDouble(fields[2]));
}
}
// normalize transition probabilities
v.NormalizeTransitionProbability();
// remove dummy labels
v.SetInjectedLabelScore(Constants.GetDummyLabel(), 0);
v.SetEstimatedLabelScore(Constants.GetDummyLabel(), 0);
// calculate random walk probabilities
v.CalculateRWProbabilities(_kBeta);
// generate the random walk probability string of the node
String rwProbStr = Constants._kInjProb + " "
+ v.pinject() + " " + Constants._kContProb
+ " " + v.pcontinue() + " "
+ Constants._kTermProb + " "
+ v.pabandon();
// represent neighborhood information as a string
Object[] neighNames = v.GetNeighborNames();
String neighStr = "";
int totalNeighbors = neighNames.length;
for (int ni = 0; ni < totalNeighbors; ++ni) {
// if the neighborhood string is already too long, then
// print it out. It is possible to split the neighborhood
// information of a node into multiple lines. However, all
// other fields should be repeated in all the split lines.
if (neighStr.length() > 0 && (ni % kMaxNeighorsPerLine_ == 0)) {
// output format
// id gold_label injected_labels estimated_labels neighbors
// rw_probabilities
output.collect(
key,
new Text(
CollectionUtil.Map2String(v.goldLabels())
+ _kDelim
+ CollectionUtil.Map2String(v
.injectedLabels())
+ _kDelim
+ CollectionUtil.Map2String(v
.estimatedLabels())
+ _kDelim + neighStr.trim()
+ _kDelim + rwProbStr));
// reset the neighborhood string
neighStr = "";
}
neighStr += neighNames[ni] + " "
+ v.GetNeighborWeight((String) neighNames[ni]) + " ";
}
// print out any remaining neighborhood information, plus all other
// info
if (neighStr.length() > 0) {
// output format
// id gold_label injected_labels estimated_labels neighbors
// rw_probabilities
output.collect(
key,
new Text(CollectionUtil.Map2String(v.goldLabels())
+ _kDelim
+ CollectionUtil.Map2String(v
.injectedLabels())
+ _kDelim
+ CollectionUtil.Map2String(v
.estimatedLabels()) + _kDelim
+ neighStr.trim() + _kDelim + rwProbStr));
}
}