List of usage examples for org.apache.mahout.math VarLongWritable VarLongWritable
public VarLongWritable(long value)
From source file:nl.gridline.free.taalserver.CountDocumentsMap.java
License:Apache License
@Override protected void map(ImmutableBytesWritable key, Result value, Context context) throws IOException, InterruptedException { // this is easy, every document is a key // so we write doc-id, doc-id CollectionItem item = new CollectionItem(value.getFamilyMap(COLLUMN_INTR)); Long itemid = item.getId();//from w ww.j ava 2 s. c o m if (itemid != null) { context.write(one, new VarLongWritable(itemid.longValue())); context.progress(); } else { throw new IOException("collection item not valid (missing id): " + item.toString()); } }
From source file:org.apache.hadoop.mapred.nativetask.testutil.BytesUtil.java
License:Apache License
private static Object newMahoutObject(byte[] seed, String className) { if (className.equals(VarIntWritable.class.getName())) { return new VarIntWritable(Bytes.toInt(seed)); } else if (className.equals(VarLongWritable.class.getName())) { return new VarLongWritable(Bytes.toLong(seed)); } else if (className.equals(TreeID.class.getName())) { TreeID treeID = new TreeID(); treeID.set(Bytes.toLong(seed));/*from ww w. j a v a 2 s. c o m*/ return treeID; } else if (className.equals(SplitPartitionedWritable.class.getName())) { SplitPartitionedWritable spWritable = new SplitPartitionedWritable(); long taskItemOrdinal = Math.abs(Bytes.toLong(seed, 4)); spWritable.setTaskItemOrdinal(taskItemOrdinal); return spWritable; } else if (className.equals(EntityEntityWritable.class.getName())) { EntityEntityWritable entityWritable = new EntityEntityWritable(Bytes.toLong(seed, 0), Bytes.toLong(seed, 8)); return entityWritable; } else if (className.equals(Gram.class.getName())) { String ngram = Bytes.toStringBinary(seed); return new Gram(ngram, Gram.Type.NGRAM); } else if (className.equals(GramKey.class.getName())) { int primaryLength = r.nextInt(seed.length); Gram gram = new Gram(Bytes.toStringBinary(seed, 0, Math.max(primaryLength, 1)), Gram.Type.NGRAM); byte[] order = new byte[seed.length - primaryLength]; System.arraycopy(seed, primaryLength, order, 0, order.length); return new GramKey(gram, order); } else if (className.equals(StringTuple.class.getName())) { int tupleSize = r.nextInt(4); StringTuple stringTuple = new StringTuple(); for (int i = 0; i < tupleSize; i++) { int index = r.nextInt(seed.length); stringTuple.add(Bytes.toStringBinary(seed, index, seed.length - index)); } return stringTuple; } else { return null; } }
From source file:org.gpfvic.mahout.cf.taste.hadoop.ToEntityPrefsMapper.java
License:Apache License
@Override public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException { String[] tokens = DELIMITER.split(value.toString()); long userID = Long.parseLong(tokens[0]); long itemID = Long.parseLong(tokens[1]); if (itemKey ^ transpose) { // If using items as keys, and not transposing items and users, then users are items! // Or if not using items as keys (users are, as usual), but transposing items and users, // then users are items! Confused? long temp = userID; userID = itemID;//from w w w .j ava 2 s.c o m itemID = temp; } if (booleanData) { context.write(new VarLongWritable(userID), new VarLongWritable(itemID)); } else { float prefValue = tokens.length > 2 ? Float.parseFloat(tokens[2]) + ratingShift : 1.0f; context.write(new VarLongWritable(userID), new EntityPrefWritable(itemID, prefValue)); } }