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. 响应式、手机端、自适应 百分比实现div等宽等高的方法

    在百分比布局中, 有时候会遇见一个头疼的问题,就是如果某个布局是正方形的话,我们在这种情况下考虑到适应各种媒体尺寸,又不能给它定固定的宽高. 之前遇见过纯色布局的结果我就用纯色图片代替实现的,现在有了 ...

  2. oracle11g的内存分配不当,导致的错误ORA-01034,ORA-00838,ORA-27101

    由于开发需要,oracle11g被应用于虚拟机,所以系统资源显得弥足珍贵,百度了一下就有答案. 用dba身份进入Oracle,笔者在plsql中对数据库进行管理: show parameter sga ...

  3. SQL手动注入解析

    作者:震灵 注入环境:DVWA 探测步骤: 1.首先探测是否可以注入以及注入方式 原SQL语句为 SELECT * FROM xxx WHERE a=''; 注入后为 SELECT * FROM xx ...

  4. CSS学习笔记08 浮动

    从CSS学习笔记05 display属性一文中,我们知道div是块元素,会独占一行,即使div的宽度很小,像下面这样 应用display属性的inline属性可以让div与div共享一行,除了这种方法 ...

  5. 【Android Developers Training】 93. 创建一个空验证器

    注:本文翻译自Google官方的Android Developers Training文档,译者技术一般,由于喜爱安卓而产生了翻译的念头,纯属个人兴趣爱好. 原文链接:http://developer ...

  6. 如何使用jedis进行发布订阅

    jedis实现发布订阅,是通过让发布者和订阅者同时对某个channel(频道)进行操作,订阅者订阅了某个频道例如channel1,发布者往这个channel1里面publish东西,在pubsubli ...

  7. JAVA基础——面向对象三大特性:封装、继承、多态

    JAVA面向对象三大特性详解 一.封装 1.概念: 将类的某些信息隐藏在类内部,不允许外部程序直接访问,而是通过该类提供的方法来实现对隐藏信息的操作和访问. 2.好处: 只能通过规定的方法访问数据. ...

  8. Linux进阶命令-sort、uniq、 cut、sed、grep、find、awk

    命令难度总体来说有简入难,参数都是工作中常常用到的.如果涉及到一些生僻的参数还请百度或man一下. sort(参考学习网站:http://www.cnblogs.com/dong008259/arch ...

  9. Centos操作系统在虚拟机VMware上的安装

    1.下载centos操作系统,提供百度云盘链接:http://pan.baidu.com/s/1pLHOR03 2.打开上篇在VMware中新建好的空白虚拟机,将centos安装在此空白虚拟机上,步骤 ...

  10. vijos1037题解

    题目: 2001年9月11日,一场突发的灾难将纽约世界贸易中心大厦夷为平地,Mr. F曾亲眼目睹了这次灾难.为了纪念"9?11"事件,Mr.F决定自己用水晶来搭建一座双塔. Mr. ...