WordCount去除标点方法之一
package com.bw.day10;
import java.io.IOException;
import java.util.StringTokenizer;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
/**
*
* @author Administrator
* WordCount
* 2017-8-12 09:23
*
*/
public class Day10 {
public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
Configuration config = new Configuration();
config.set("fs.defaultFS", "hdfs://192.168.0.117:9000");
config.set("yarn.resourcemanager.hostname", "192.168.0.117");
Job job = Job.getInstance(config);
//MR
job.setMapperClass(mapper.class);
job.setReducerClass(reducer.class);
//T/L
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(LongWritable.class);
//T/L
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(LongWritable.class);
FileInputFormat.setInputPaths(job, new Path("/day10.txt"));
FileOutputFormat.setOutputPath(job, new Path("/Out"));
//BOOLEAN
boolean b = job.waitForCompletion(true);
if(b){
System.out.println("Success");
}else{
System.out.println("Error");
}
}
public static class mapper extends Mapper<LongWritable, Text, Text, LongWritable>{
@Override
protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, LongWritable>.Context context)
throws IOException, InterruptedException {
@SuppressWarnings("unused")
IntWritable one = new IntWritable(1);
Text word = new Text();
String pattern = "[^a-zA-Z0-9-']";
String line = value.toString();
line = line.replaceAll(pattern, " ");
StringTokenizer itr = new StringTokenizer(line);
while(itr.hasMoreTokens()){
word.set(itr.nextToken());
context.write(word, new LongWritable(1));
}
}
}
public static class reducer extends Reducer<Text, LongWritable, Text, LongWritable>{
@Override
protected void reduce(Text text, Iterable<LongWritable> iterable, Reducer<Text, LongWritable, Text, LongWritable>.Context context) throws IOException, InterruptedException {
int sum = 0;
for (LongWritable longWritable : iterable) {
sum += longWritable.get();
}
context.write(text,new LongWritable(sum));
}
}
}
WordCount去除标点方法之一的更多相关文章
- ◆ 火狐浏览器去除JS方法:
◆ 火狐浏览器去除JS方法: 在火狐地址栏输入about:config 回车 在搜索地址栏中输入javascript.enabled 右键 当一行的中的,值由false变成trun,就OK了 .
- html添加keyword,description帮助百度收录处理方法,jsp去除空白行方法
1.将网页的title,keyword,description写成include包含文件,例如: top.jsp <%@ page language="java" conte ...
- delphi 编译的时候 把Warning去除的方法
delphi 编译的时候 把Warning去除的方法 在 添加 {$WARNINGS OFF}
- 关于img标签浏览器自带的边框,清除边框的解决方式(即img[src=""] img无路径情况下,灰色边框去除解决方法)
详解img[src=""] img无路径情况下,灰色边框去除解决方法 1.Js解决办法 <html> <head> <meta charset=&qu ...
- AnyChartStock去除水印方法
最近在使用AnyChartStock的图表,功能很强大,但下载过来是有水印的,虽然网上也有很多破解无水印的版本,但基本都是AnyChart的,AnyChartStoc的几乎没有.所以自己尝试着去除水印 ...
- python利用opencv去除水印方法
OpenCV(Open Source Computer Vision Library)是一个跨平台计算机视觉库,实现了图像处理和计算机视觉方面的很多通用算法 在python中可以利用opencv来去除 ...
- List 中去除 null 方法讨论
先看下面的程序段: public static void main(String[] args) { List<Integer> arrays = new ArrayList<Int ...
- 三种动态加载js的jquery实例代码另附去除js方法
!-- 这里为你提供了三种动态加载js的jquery实例代码哦,由于jquery是为用户提供方便的,所以利用jquery动态加载文件只要一句话$.getscript("test.js&quo ...
- JS去除空格方法记录
JS中去掉空格 //去除空格 String.prototype.Trim = function() { return this.replace(/\s+/g, ""); ...
随机推荐
- 从Java虚拟机的内存区域、垃圾收集器及内存分配原则谈Java的内存回收机制
一.引言: 在Java中我们只需要轻轻地new一下,就可以为实例化一个类,并分配对应的内存空间,而后似乎我们也可以不用去管它,Java自带垃圾回收器,到了对象死亡的时候垃圾回收器就会将死亡对象的内存回 ...
- 【Android Developers Training】 11. 支持不同语言
注:本文翻译自Google官方的Android Developers Training文档,译者技术一般,由于喜爱安卓而产生了翻译的念头,纯属个人兴趣爱好. 原文链接:http://developer ...
- 【Android Developers Training】 41. 向另一台设备发送文件
注:本文翻译自Google官方的Android Developers Training文档,译者技术一般,由于喜爱安卓而产生了翻译的念头,纯属个人兴趣爱好. 原文链接:http://developer ...
- 【css技能提升】css高级技巧
本文是一个帮你提升 CSS 技巧的收藏集. 使用CSS复位 CSS复位可以在不同的浏览器上保持一致的样式风格.您可以使用CSS reset 库Normalize等,也可以使用一个更简化的复位方法: * ...
- Educational Codeforces Round 20.C
C. Maximal GCD time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- .net入门 - Get Started with .NET
阅读原文 有很多种方式去开始使用.net.因为.net是一个巨大的平台,在这个文档里面有很多文章,告诉你如何从不同的角度去开始使用.net. 使用.NET的语言入门 C#入门文章和C#教程提供了以C# ...
- wget访问SOAP接口
SOAP协议主要是XML交互,所以其访问过程类似于这样: wget --header='Content-Type: text/xml;charset=utf-8' --post-data='<s ...
- 某天U盘插在笔记本打不开了,是U盘坏了还是电脑的问题?
五六月份忙着毕业设计与毕业论文,U盘在这个时候就是大功臣啦! 然而打印完最终版本论文上交后,再次把U盘插在自己的笔记本上读取失败了... 只有一个空白的图标,打不开,也无法格式化. 试着删除,拔了又插 ...
- python+matplotlib+web.py
最近看了厦门大学数据库实验室林子雨老师的<大数据课程实验案例:网站用户行为分析>,可视化这块是用的R语言,我决定用Python来实现一下. 参考文献 http://dblab.xmu.ed ...
- PHPCMS修改域名
有时候服务器域名解析时,需要修改网站域名,那么在phpcms中,像一些附件地址什么的都需要修改.下面介绍一下怎么系统全面的修改这些地址. 1.在后台管理中心--设置--站点管理--修改,站点域名改为新 ...