map map
下面的无法运行。
@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的更多相关文章
- Map map=new HashMap(); 为什么是这样
Map是接口,hashMap是Map的一种实现.接口不能被实例化. Map map=new HashMap(); 就是将map实例化成一个hashMap.这样做的好处是调用者不需要知道map具体的实现 ...
- 笔记 freemark list标签迭代Map<Map<String,Object>集合排序问题
本博客是自己在学习和工作途中的积累与总结,仅供自己参考,也欢迎大家转载,转载时请注明出处. 工作中出现一个比较特殊的问题,在模板ftl文件中,一般用list迭代map 举例: 后台: // 传入的参数 ...
- Map map=new HashMap()
Map是接口,hashMap是Map的一种实现.接口不能被实例化.Map map=new HashMap(); 就是将map实例化成一个hashMap.这样做的好处是调用者不需要知道map具体的实现, ...
- mybatia的mypper.xml文件,参数类型为map,map里有一个键值对的值为数组,如何解析,例子可供参考,接上文,发现更简便的方法,不必传数组,只需传字符串用逗号隔开即可
是这样的 先看参数 map.put("orgId", "1818"); map.put("childDeps", "1000,10 ...
- java将对象转map,map转对象工具类
/** * 将map转换为一个对象 * * @param map * @param beanClass * @return * @throws Exception */ public static O ...
- Collections.unmodifiableMap(Map map)
public static <K,V> Map<K,V> unmodifiableMap(Map<? extends K,? extends V> m)返回指定映射 ...
- go语言笔记——map map 默认是无序的,不管是按照 key 还是按照 value 默认都不排序
示例 8.1 make_maps.go package main import "fmt" func main() { var mapLit map[string]int //va ...
- 为什么常用 Map<> map = new HashMap()
在初学Java的时候,经常能看到教材上的写法,使用了接口Map来引用一个map,而不是它的具体实现,那么这样做的好处是什么呢? <Effective Java>第52条:通过接口引用对象 ...
- jsp循环map map的key值不固定
<c:if test="${not empty parammap}"> <c:forEach items="${parammap }" var ...
随机推荐
- 算法入门(C++)
iostream,这个头文件里有很多常用的函数,比如swap交换两个变量的值,max求两个值的最大值等. cstdio头文件,这个头文件里包含C风格的输入输出.如果你之前学习过C++语言应该知道cin ...
- python解决接口测试获取手机验证码问题
最近在做接口测试的时候遇到一个问题,就是有个很重要的接口要用到手机短信验证码,而其他接口都依赖于这个验证码,如果没有短信验证码就不能进行下面接口的测试,所以为了定时的验证线上的接口是否正常,而且又不修 ...
- jfreechart 实例
http://blog.csdn.net/ami121/article/category/394379 jfreechart实例(三)股价K线波动图 package com.ami;/** *@ Em ...
- POJ2524:Ubiquitous Religions (并查集模板)
Description There are so many different religions in the world today that it is difficult to keep tr ...
- 使用SQLCMD在SQLServer执行多个脚本 转载
出处不明 概述: 作为DBA,经常要用开发人员提供的SQL脚本来更新正式数据库,但是一个比较合理的开发流程,当提交脚本给DBA执行的时候,可能已经有几百个sql文件,并且有执行顺序,如我现在工作的公司 ...
- Ansible3:ansible.cfg配置说明【转】
Ansible默认安装好后有一个配置文件/etc/ansible/ansible.cfg,该配置文件中定义了ansible的主机的默认配置部分,如默认是否需要输入密码.是否开启sudo认证.actio ...
- jquery datatable 参数api
jQuery 的插件 dataTables 是一个优秀的表格插件,提供了针对表格的排序.浏览器分页.服务器分页.筛选.格式化等功能.dataTables 的网站上也提供了大量的演示和详细的文档进行说明 ...
- Nginx配置IP白名单和黑名单
白名单设置,访问根目录 location / { allow 123.34.22.155; allow ; deny all; } 黑名单设置,访问根目录 location / { deny 123. ...
- Inno Setup入门(四)——为程序创建桌面快捷方式
Icons这一可选段定义所有创建在开始菜单和\或其它位置 (比如桌面) 的快捷方式.一个例子如下: [setup] ;全局设置,本段必须 AppName=Test AppVerName=TEST De ...
- C++虚函数的新用法
1.今天在segmentfault上看到了一个C++虚函数的新用法,先上代码 #include <iostream> using namespace std; class B { publ ...