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, ""); ...
随机推荐
- thinkphp导出csv格式的表格
<?php /** * Created by PhpStorm. * User: hanks * Date: 2016/4/20 * Time: 13:51 */ namespace Home\ ...
- JQuery事件机制笔记
一.事件绑定及移除 1.bind() bind()为每个匹配的元素绑定一个或多个事件处理函数: 语法:bind(event,fn)//不能给未来元素添加事件: bind(event,fn); bind ...
- Vue-router结合transition实现app前进后退动画切换效果
一丶首先配置路由并且修改路由配置 路由配置就不讲了重点,给VueRoute添加一个goBack方法,用于记录路由的前进后退状态 this.isBack = true VueRouter.protot ...
- ionic项目结构解析
ionic项目结构解析 原始结构 创建一个IonicDemo项目 'ionic start IonicDemo sidemenu' 这种结构多模块开发比较麻烦,因为view跟controller分开路 ...
- PHP接入阿里云市场 阿里短信服务DEMO
阿里短信服务:支持三大运营商短信.智能管道等优质能力,产品特点:3秒可达.99%到达率.超低资费. 使用阿里短信服务步骤: 1.购买服务 到https://market.aliyun.com/prod ...
- 浅入深出之Java集合框架(上)
Java中的集合框架(上) 由于Java中的集合框架的内容比较多,在这里分为三个部分介绍Java的集合框架,内容是从浅到深,如果已经有java基础的小伙伴可以直接跳到<浅入深出之Java集合框架 ...
- VB6之反编译工具VBRezQ
该软件的下载地址:http://www.xiazaiba.com/html/5276.html 网站上是这么介绍的: VBRezQ是一个针对VB程序的反编译软件.VBRezQ反编译的可读性尤其对早期版 ...
- MapReduce执行流程及程序编写
MapReduce 一种分布式计算模型,解决海量数据的计算问题,MapReduce将计算过程抽象成两个函数 Map(映射):对一些独立元素(拆分后的小块)组成的列表的每一个元素进行指定的操作,可以高度 ...
- Watson Conversation Service Implementation Methodology
Watson Conversation Service Implementation Methodology In order to implement the WCS successfully. Y ...
- dashDB - Creating a table with CLOB column type
In order to create a table with clob column type, the table has to be created with "ORGANIZE BY ...