/** * Checks two pairs for equality. * * @param obj object for comparison * @return <code>true</code> if <code>obj</code> is equal to this object, <code>false</code> * otherwise */ public boolean equals(Object obj) { PairOfIntString pair = (PairOfIntString) obj; return leftElement == pair.getLeftElement() && rightElement.equals(pair.getRightElement()); }
/** * Creates a pair. * * @param left the left element * @param right the right element */ public PairOfIntString(int left, String right) { set(left, right); }
/** * Clones this object. * * @return clone of this object */ public PairOfIntString clone() { return new PairOfIntString(this.leftElement, this.rightElement); }
public int getPartition(PairOfIntString key, IntWritable value, int numReduceTasks) { return Math.abs(key.getLeftElement() % numReduceTasks); } }
/** * Defines a natural sort order for pairs. Pairs are sorted first by the left element, and then by * the right element. * * @return a value less than zero, a value greater than zero, or zero if this pair should be * sorted before, sorted after, or is equal to <code>obj</code>. */ public int compareTo(PairOfIntString pair) { int pl = pair.getLeftElement(); String pr = pair.getRightElement(); if (leftElement == pl) { return rightElement.compareTo(pr); } return leftElement < pl ? -1 : 1; }
public void map(IntWritable key, ArrayListWritable<AnchorText> anchors, OutputCollector<PairOfIntString, IntWritable> output, Reporter reporter) throws IOException { for(AnchorText data : anchors) { if(data.isURL()) try { //extract the hostname for a given URL host = new URI(data.getText()).getHost(); }catch(Exception e) { return; } } for(AnchorText data : anchors) { if(!data.isExternalOutLink()) continue; valueWord.set(key.get()); for(int target : data) { keyWord.set(target, host); output.collect(keyWord, valueWord); } } } }
public static PairOfIntString of(int left, String right) { return new PairOfIntString(left, right); }
public void map(IntWritable key, PairOfIntString t, OutputCollector<IntWritable, Text> output, Reporter reporter) throws IOException { KEY.set(t.getLeftElement()); VALUE.set(t.getRightElement()); output.collect(KEY, VALUE); } }
public void reduce(PairOfStringInt key, Iterator<PairOfStrings> values, OutputCollector<IntWritable, PairOfIntString> output, Reporter reporter) throws IOException { if (key.getRightElement() == 0) { targetTitle = key.getLeftElement(); targetDocid = Integer.parseInt(values.next().getLeftElement()); } else { if (!key.getLeftElement().equals(targetTitle)) { return; } while (values.hasNext()) { PairOfStrings pair = values.next(); SRCID.set(Integer.parseInt(pair.getLeftElement())); TARGET_ANCHOR_PAIR.set(targetDocid, pair.getRightElement()); output.collect(SRCID, TARGET_ANCHOR_PAIR); } } } }
firstTime = false; arrayList.clear(); currentDocument = key.getLeftElement(); } else if(currentDocument != key.getLeftElement()) { Collections.sort(arrayList); keyWord.set(currentDocument); output.collect(keyWord, arrayList); currentDocument = key.getLeftElement(); arrayList.clear(); arrayList.add(new AnchorText(AnchorTextConstants.Type.OTHER_TYPES.val, key.getRightElement())); int currentIndex = arrayList.size() - 1; arrayList.get(currentIndex).addDocument(packet); } else { arrayList.add(new AnchorText(AnchorTextConstants.Type.OTHER_TYPES.val, key.getRightElement(), packet)); currentIndex = arrayList.size() - 1;