首页 > 其他 > 详细

从数据集输出艺术家

时间:2017-07-09 17:52:51      阅读:181      评论:0      收藏:0      [点我收藏+]
<strong><span style="font-size:18px;">/***
 * @author YangXin
 * @info 从数据集输出艺术家
 * 为了生成Last.fm数据集的特征向量,我们部署两个MapReduce作业。

* 第一个作业以词典的形式生成独立的艺术家列表,第二个作业利用生成的词典来产生向量。 */ package unitTwelve; import java.io.IOException; import java.util.regex.Pattern; import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.io.LongWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Mapper; public class DictionaryMapper extends Mapper<LongWritable, Text, Text, IntWritable>{ private Pattern splitter; protected void map(LongWritable key, Text line, Context context) throws IOException, InterruptedException{ String[] fields = splitter.split(line.toString()); if(fields.length < 4){ context.getCounter("Map", "LinesWithErrors").increment(1); return; } String artist = fields[1]; context.write(new Text(artist), new IntWritable(0)); } protected void setup(Context context) throws IOException, InterruptedException{ super.setup(context); splitter = Pattern.compile("<sep>"); } } </span></strong>


从数据集输出艺术家

原文:http://www.cnblogs.com/llguanli/p/7142075.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!