public Frequency(IntPairWritable bigram, double frequency) { this.pair = new IntPairWritable(bigram); this.frequency = frequency; }
@Override public Object clone() { return new IntPairWritable(this); }
@Override public Object clone() { return new IntPairWritable(this); }
@Override public Object clone() { return new IntPairWritable(this); }
public Frequency(IntPairWritable bigram, double frequency) { this.pair = new IntPairWritable(bigram); this.frequency = frequency; }
public Frequency(IntPairWritable bigram, double frequency) { this.pair = new IntPairWritable(bigram); this.frequency = frequency; }
@Override protected void map(LongWritable key, Text value, Context ctx) throws IOException, InterruptedException { String[] tokens = TasteHadoopUtils.splitPrefTokens(value.toString()); int userIDIndex = TasteHadoopUtils.idToIndex(Long.parseLong(tokens[0])); int itemIDIndex = TasteHadoopUtils.idToIndex(Long.parseLong(tokens[1])); double rating = Double.parseDouble(tokens[2]); ctx.write(new IntPairWritable(userIDIndex, itemIDIndex), new DoubleWritable(rating)); } }
@Test public void testComparable() { IntPairWritable[] input = { new IntPairWritable(2,3), new IntPairWritable(2,2), new IntPairWritable(1,3), new IntPairWritable(1,2), new IntPairWritable(2,1), new IntPairWritable(2,2), new IntPairWritable(1,-2), new IntPairWritable(1,-1), new IntPairWritable(-2,-2), new IntPairWritable(-2,-1),
@Test public void testWritable() throws Exception { IntPairWritable one = new IntPairWritable(1,2); IntPairWritable two = new IntPairWritable(3,4); assertEquals(1, one.getFirst()); assertEquals(2, one.getSecond()); assertEquals(3, two.getFirst()); assertEquals(4, two.getSecond()); ByteArrayOutputStream bout = new ByteArrayOutputStream(); DataOutput out = new DataOutputStream(bout); two.write(out); byte[] b = bout.toByteArray(); ByteArrayInputStream bin = new ByteArrayInputStream(b); DataInput din = new DataInputStream(bin); one.readFields(din); assertEquals(two.getFirst(), one.getFirst()); assertEquals(two.getSecond(), one.getSecond()); }
@Test public void testGetSet() { IntPairWritable n = new IntPairWritable(); assertEquals(0, n.getFirst()); assertEquals(0, n.getSecond()); n.setFirst(5); n.setSecond(10); assertEquals(5, n.getFirst()); assertEquals(10, n.getSecond()); n = new IntPairWritable(2,4); assertEquals(2, n.getFirst()); assertEquals(4, n.getSecond()); }