下面的无法运行。
@Override
protected void map(LongWritable key, Text value,
Mapper<LongWritable, Text, Text, DoubleWritable>.Context context)
throws IOException, InterruptedException {
Configuration conf = context.getConfiguration();
int tot = Integer.parseInt(conf.get("TOTALWORDS")); System.out.println("total === " + total);
System.out.println("tot = " + tot); // 输入的格式如下:
// ALB weekend 1
// ALB weeks 3
Map<String, List<String>> baseMap = new HashMap<String, List<String>>(); // 保存基础数据
// Map<String, List<Double>> priorMap = new HashMap<String, List<Double>>(); // 保存每个单词出现的概率 String[] temp = value.toString().split("\t");
// 先将数据存到baseMap中
if (temp.length == 3) {
// 文件夹名类别名temp[0]
String wordAndNumber = null;
wordAndNumber = temp[1] + "\t" + temp[2];
if (baseMap.containsKey(temp[0])) { baseMap.get(temp[0]).add(wordAndNumber);
} else {
List<String> oneList = new ArrayList<String>();
oneList.add(wordAndNumber);
baseMap.put(temp[0], oneList);
} } // 读取数据完毕,全部保存在baseMap中 // 两层循环计算出每个类别中每个单词的概率 Iterator<Map.Entry<String, List<String>>> iterators = baseMap.entrySet().iterator();
while (iterators.hasNext()) {// 遍历类别
Map.Entry<String, List<String>> iterator = iterators.next();
int allWordsInClass = 0; // list遍历
Iterator<String> its = iterator.getValue().iterator(); // 得到每个类别的单词总数
while (its.hasNext()) {
String[] temp1 = its.next().split("\t");
allWordsInClass += Integer.parseInt(temp1[1]);
}
System.out.println(allWordsInClass);// 这个数据没有计算成功???? //
// Map<String, List<Double>> pMap = new HashMap<String, List<Double>>();
// List<Double> pList = new ArrayList<Double>();
// 遍历每个单词的词频计算器概率
while (its.hasNext()) {
String[] temp1 = its.next().split("\t");
double p = (Integer.parseInt(temp1[1]) + 1) / (allWordsInClass + total);
String classAndWord = iterator.getKey() + "\t" + temp1[0];
className.set(classAndWord);
number.set(p);
LOG.info("------>p = " + p);
// context.write(className, number);
mos.write(iterator.getKey(), temp1[0], p);
} }
}

protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, DoubleWritable>.Context context)
throws IOException, InterruptedException {
Configuration conf = context.getConfiguration();
int tot = Integer.parseInt(conf.get("TOTALWORDS")); System.out.println("total === " + total);
System.out.println("tot = " + tot); // 输入的格式如下:
// ALB weekend 1
// ALB weeks 3
Map<String, Map<String, Integer>> baseMap = new HashMap<String, Map<String, Integer>>(); // 保存基础数据
Map<String, Map<String, Double>> priorMap = new HashMap<String, Map<String, Double>>(); // 保存每个单词出现的概率 String[] temp = value.toString().split("\t");
// 先将数据存到baseMap中
if (temp.length == 3) {
// 文件夹名类别名
if (baseMap.containsKey(temp[0])) {
baseMap.get(temp[0]).put(temp[1], Integer.parseInt(temp[2]));
} else {
Map<String, Integer> oneMap = new HashMap<String, Integer>();
oneMap.put(temp[1], Integer.parseInt(temp[2]));
baseMap.put(temp[0], oneMap);
} } // 读取数据完毕,全部保存在baseMap中 // 两层循环计算出每个类别中每个单词的概率
Iterator<Map.Entry<String, Map<String, Integer>>> iterators = baseMap.entrySet().iterator();
while (iterators.hasNext()) {// 遍历类别
Map.Entry<String, Map<String, Integer>> iterator = iterators.next();
int allWordsInClass = 0; for (Map.Entry<String, Integer> entry : iterator.getValue().entrySet()) {// 遍历类别中的单词,先求出类别中的单词总数
allWordsInClass += entry.getValue();
}
System.out.println(allWordsInClass);//这个数据没有计算成功
//
Map<String, Double> pMap = new HashMap<String, Double>();
for (Map.Entry<String, Integer> entry : iterator.getValue().entrySet()) {// 在遍历每个单词的个数计算单词出现的概率
double p = (entry.getValue()+ 1.0) / (allWordsInClass + tot);//
pMap.put(entry.getKey(), p);
priorMap.put(iterator.getKey(), pMap);
className.set(iterator.getKey() + "\t" + entry.getKey());
number.set(p);
LOG.info("------>p = " + p); context.write(className, number);
// mos.write(iterator.getKey(), entry.getKey(), p);
} } /*
* value.set(temp[1]); number.set(Integer.parseInt(temp[2]));
* mos.write(value, number, dirName);
*/
}

map map的更多相关文章

  1. Map map=new HashMap(); 为什么是这样

    Map是接口,hashMap是Map的一种实现.接口不能被实例化. Map map=new HashMap(); 就是将map实例化成一个hashMap.这样做的好处是调用者不需要知道map具体的实现 ...

  2. 笔记 freemark list标签迭代Map<Map<String,Object>集合排序问题

    本博客是自己在学习和工作途中的积累与总结,仅供自己参考,也欢迎大家转载,转载时请注明出处. 工作中出现一个比较特殊的问题,在模板ftl文件中,一般用list迭代map 举例: 后台: // 传入的参数 ...

  3. Map map=new HashMap()

    Map是接口,hashMap是Map的一种实现.接口不能被实例化.Map map=new HashMap(); 就是将map实例化成一个hashMap.这样做的好处是调用者不需要知道map具体的实现, ...

  4. mybatia的mypper.xml文件,参数类型为map,map里有一个键值对的值为数组,如何解析,例子可供参考,接上文,发现更简便的方法,不必传数组,只需传字符串用逗号隔开即可

    是这样的 先看参数 map.put("orgId", "1818"); map.put("childDeps", "1000,10 ...

  5. java将对象转map,map转对象工具类

    /** * 将map转换为一个对象 * * @param map * @param beanClass * @return * @throws Exception */ public static O ...

  6. Collections.unmodifiableMap(Map map)

    public static <K,V> Map<K,V> unmodifiableMap(Map<? extends K,? extends V> m)返回指定映射 ...

  7. go语言笔记——map map 默认是无序的,不管是按照 key 还是按照 value 默认都不排序

    示例 8.1 make_maps.go package main import "fmt" func main() { var mapLit map[string]int //va ...

  8. 为什么常用 Map<> map = new HashMap()

    在初学Java的时候,经常能看到教材上的写法,使用了接口Map来引用一个map,而不是它的具体实现,那么这样做的好处是什么呢? <Effective Java>第52条:通过接口引用对象 ...

  9. jsp循环map map的key值不固定

    <c:if test="${not empty parammap}"> <c:forEach items="${parammap }" var ...

随机推荐

  1. Load PE from memory(反取证)(未完)

      Article 1:Loading Win32/64 DLLs "manually" without LoadLibrary() The most important step ...

  2. C# var 隐式类型 var 用法 特点

    var 关键字是C# 3.0 开始,在方法范围中声明的变量: var有以下特点: * 1.var在编译器编译的时候根据初始值推断出其的类型          * 2.不能赋值除了初始值类型之外的其他类 ...

  3. apache 不执行PHP,显示代码

    首先检查是否安装PHP,已经安装过的话,先执行 locate libphp5.so 查看APACHE是否有SO文件,如果没有,那就要重装PHP了,先执行php -i | grep configure ...

  4. 第十四节,基本数据类型,列表list

    创建列表  #!/usr/bin/env python # -*- coding:utf-8 -*- a = ['alex', 'seven', 'eric'] #或 a = list(['alex' ...

  5. Linux文件系统的目录结构

    Linux下的文件系统为树形结构,入口为/ 树形结构下的文件目录: 无论哪个版本的Linux系统,都有这些目录,这些目录应该是标准的.各个Linux发行版本会存在一些小小的差异,但总体来说,还是大体差 ...

  6. 安装阿里云的php+mysql+nginx+vsftpd

    百度云search   sh-1.3.0-centos.zip

  7. 【Machine Learning in Action --1】机器学习入门指南

    摘自:http://www.jianshu.com/p/c3634a7f2320 机器学习算法 Coursera 上面 Stanford 的 机器学习 课程是优质的算法相关入门课程.Andrew Ng ...

  8. Spotlights

    Spotlights time limit per test 1 second memory limit per test 256 megabytes input standard input out ...

  9. HDU 1698 <线段树,区间set>

    题目连接 题意: 一条长为N的铜链子,每个结点的价值为1.有两种修改,l,r,z; z=2:表示把[l,r]区间内链子改为银质,价值为2. z=3:表示把[l,r]区间内链子改为金质,价值为3. 思路 ...

  10. Android 开发——如何显示 GIF 动画

    gif 图动画在 android 中还是比较常用的,比如像新浪微博中,有很多 gif 图片,而且展示非常好,所以我也想弄一个.经过我多方的搜索资料和整理,终于弄出来了,其实 github 上有很多开源 ...