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, ""); ...
随机推荐
- php中的冒泡排序算法
<?php //php中的冒泡排序算法 //从大到小的排序方式 ,$arr[$j]>$arr[$j+1](这里换成了从小到大的排序方式) $arr=array(); $arr=array( ...
- Chapter 4. The MPEG-4 and H.264 Standards
本章节介绍一些关于MPEG-4标准与H.264标准的基本知识 比较重要的是第95页关于两种标准的对比表格.其他部分没有什么特别重要的细节.
- 【Android Developers Training】 29. 从Activity获得结果
注:本文翻译自Google官方的Android Developers Training文档,译者技术一般,由于喜爱安卓而产生了翻译的念头,纯属个人兴趣爱好. 原文链接:http://developer ...
- java怎么连接mysql数据库
JDBC(Java Data Base Connectivity,java数据库连接)是一种用于执行SQL语句的Java API,可以为多种关系数据库提供统一访问,它由一组用Java语言编写的类和接口 ...
- 在Visual Studio 2017中使用Asp.Net Core构建Angular4应用程序
前言 Visual Studio 2017已经发布了很久了.做为集成了Asp.Net Core 1.1的地表最强IDE工具,越来越受.NET系的开发人员追捧. 随着Google Angular4的发布 ...
- Angular路由(三)
AngularJs ng-route路由详解 其实主要是$routeProvider搭配ng-view实现. ng-view的实现原理,基本就是根据路由的切换,动态编译html模板. 前提 首先必须在 ...
- VB6之图像灰度与二值化
老代码备忘,我对图像处理不是太懂. 注:部分代码引援自网上,话说我到底自己写过什么代码... Private Declare Function GetBitmapBits Lib "gdi3 ...
- Java异常体系简析
最近在阅读<Java编程思想>的时候看到了书中对异常的描述,结合自己阅读源码经历,谈谈自己对异常的理解.首先记住下面两句话: 除非你能解决这个异常,否则不要捕获它,如果打算记录错误消息,那 ...
- Immutable的认识
Facebook 工程师 Lee Byron 花费 3 年时间打造,与 React 同期出现,但没有被默认放到 React 工具集里(React 提供了简化的 Helper).它内部实现了一套完整的 ...
- WM_COPYDATA传送指针数据类型的问题
WM_COPYDATA传送指针数据的问题 var cdds:TcopyDataStruct; strAnsi:string;begin cdds:=PCopyDataSt ...