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 ...
随机推荐
- [转]Publishing and Running ASP.NET Core Applications with IIS
本文转自:https://weblog.west-wind.com/posts/2016/Jun/06/Publishing-and-Running-ASPNET-Core-Applications- ...
- Centos更换yum源,安装ssh server
先连上网,然后更换yum源 1. 新建的用户没有sudo权限,所以首先切换到root用户su -输入密码 2. 备份之前的yum源mv /etc/yum.repos.d/CentOS-Base.rep ...
- spark 编程向导
http://spark.apache.org/docs/latest/programming-guide.html
- ASP.NET MVC Controller向View传值的几种方式
上几篇博文提到MVC和WebForm的区别,主要是MVC的Controller和View将传统的WebForm的窗体和后台代码做了解耦,这篇博文简单介绍一下在MVC中Controller向View是如 ...
- Failed to load c++ bson extension, using pure JS version
Failed to load c++ bson extension, using pure JS version npm install mongodbnpm install bson npm ins ...
- PHP数据库扩展mysqli的函数试题
1.mysqli链接数据库的方式是什么? 2.mysqli获取链接错误号的属性是什么? 3.mysqli获取链接错误信息的属性是什么? 4.mysqli执行sql语句的函数是什么? 5.mysqli获 ...
- Array.length vs Array.prototype.length
I found that both the Array Object and Array.prototype have the length property. I am confused on us ...
- Ztree当节点没有下级时不显示下拉图标
select o.*,(select count(*) from sys_org t where t.orgsupid=o.orgid) isLeaf from sys_org o where 1=1
- Spring Boot 系列教程9-swagger-前后端分离后的标准
前后端分离的必要 现在的趋势发展,需要把前后端开发和部署做到真正的分离 做前端的谁也不想用Maven或者Gradle作为构建工具 做后端的谁也不想要用Grunt或者Gulp作为构建工具 前后端需要通过 ...
- UVA106 - Fermat vs. Pythagoras
假设x为奇数,y为偶数,则z为奇数,2z与2x的最大公因数为2,2z和2x可分别写作 2z = (z + x) + (z - x) 2x = (z + x) - (z - x) 那么跟据最大公因数性质 ...