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去除标点方法之一的更多相关文章

  1. ◆ 火狐浏览器去除JS方法:

    ◆ 火狐浏览器去除JS方法: 在火狐地址栏输入about:config   回车 在搜索地址栏中输入javascript.enabled 右键 当一行的中的,值由false变成trun,就OK了 . 

  2. html添加keyword,description帮助百度收录处理方法,jsp去除空白行方法

    1.将网页的title,keyword,description写成include包含文件,例如: top.jsp <%@ page language="java" conte ...

  3. delphi 编译的时候 把Warning去除的方法

    delphi  编译的时候  把Warning去除的方法 在 添加 {$WARNINGS OFF}

  4. 关于img标签浏览器自带的边框,清除边框的解决方式(即img[src=""] img无路径情况下,灰色边框去除解决方法)

    详解img[src=""] img无路径情况下,灰色边框去除解决方法 1.Js解决办法 <html> <head> <meta charset=&qu ...

  5. AnyChartStock去除水印方法

    最近在使用AnyChartStock的图表,功能很强大,但下载过来是有水印的,虽然网上也有很多破解无水印的版本,但基本都是AnyChart的,AnyChartStoc的几乎没有.所以自己尝试着去除水印 ...

  6. python利用opencv去除水印方法

    OpenCV(Open Source Computer Vision Library)是一个跨平台计算机视觉库,实现了图像处理和计算机视觉方面的很多通用算法 在python中可以利用opencv来去除 ...

  7. List 中去除 null 方法讨论

    先看下面的程序段: public static void main(String[] args) { List<Integer> arrays = new ArrayList<Int ...

  8. 三种动态加载js的jquery实例代码另附去除js方法

    !-- 这里为你提供了三种动态加载js的jquery实例代码哦,由于jquery是为用户提供方便的,所以利用jquery动态加载文件只要一句话$.getscript("test.js&quo ...

  9. JS去除空格方法记录

    JS中去掉空格 //去除空格  String.prototype.Trim = function() {      return this.replace(/\s+/g, ""); ...

随机推荐

  1. Kafka 源代码分析之MessageSet

    这里分析MessageSet类 MessageSet是一个抽象类,定义了一条log的一些接口和常量,FileMessageSet就是MessageSet类的实现类.一条日志中存储的log完整格式如下 ...

  2. Java算法-------无序数组中的最长连续序列---------leetcode128

    Given an unsorted array of integers, find the length of the longest consecutive elements sequence. F ...

  3. Java 9 揭秘(8. JDK 9重大改变)

    Tips 做一个终身学习的人. 在本章,主要介绍以下内容: 新的JDK版本控制方案是什么 如何使用Runtime.Version类解析JDK版本字符串 JDK JRE 9的新目录布局是什么 JDK 9 ...

  4. angular4.0 父子组建之间的相互通信

    父组建---->子组建 传递信息 首先先通过angular脚手架生成两个基本组件,有一个好处是 会自动关联到跟模版,节约时间,而且还是偷懒 ng generate component compo ...

  5. VB6之SOAP

    根据网上搜来的资料,MS有个组件可以用来支撑VB6访问SOAP接口. 于是下载了个msSoapToolkit.exe安装后试了下,发现确实可以访问用C#或者VB.net写的webservice. 但是 ...

  6. Kubernetes服务之“运行单实例的有状态服务”

    目标 在你的环境中创建一个PV 创建一个MySQl的Deployment 在集群中以DNS名称的方式,将MySQL暴露给其他的pod 开始之前 你需要一个Kubernetes集群,一个可以连接到集群的 ...

  7. win10常用的运行命令

    WIN+R调出命令框: 1.calc:启动计算器 2.appwiz.cpl:程序和功能 3.certmgr.msc:证书管理实用程序 4.charmap:启动字符映射表 5.chkdsk.exe:Ch ...

  8. poj3276

    Face The Right Way Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 5121   Accepted: 237 ...

  9. 集合用法笔记-Map用法

    一.Map遍历 Map<String, String> map = new HashMap<String, String>(); map.put("1", ...

  10. 【.net 深呼吸】监听剪贴板更新(针对Vista之后系统)

    针对 XP 及以前的监视剪贴板更改的方法就不讲了,因为 XP 已严重过时.本篇老周介绍的方法面向 Vista 以上的系统. 在托管应用程序中监听剪贴板更新行为必须用到 Win 32 API ,具体做法 ...