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 ...
随机推荐
- php 项目简单分类
项目分为:客户需求和自行研发. 商城项目:------------------------商城分类:单商家:商家就是网站所有者.如京东.凡客. 多商家:如淘宝 网站所有者不是卖家. ...
- JavaScript高级程序设计:第一章
JavaScript简介: 1.JavaScript实现应该由以下三部分组成: (1)核心:ECMAScript (2)文档对象模型:DOM (3)浏览器对象模型:BOM 2.什么是ECMAScrip ...
- laravel 获取最后一条sql的小函数
function lastSql(){ $sql = DB::getQueryLog(); $query = end($sql); return $query; }
- elasticsearch快照和恢复
摘要:es可以通过简单的命令对索引或者整个集群进行快照和恢复 快照和恢复 Snapshot and restore 模块允许创建单个索引或者整个集群的快照到远程仓库. 在初始版本里只支持共享文件系统的 ...
- divide an integer into X parts (as even as possible)
the algorithm is like this: it evenly spreads an integer N over K cells. for i = 0 to K array[i] = N ...
- SSH登录很慢问题的解决方法
用ssh连其他linux机器,会等待10-30秒才有提示输入密码.严重影响工作效率. 关闭ssh的gssapi认证 用ssh -v user@server 可以看到登录时有如下信息: debug1: ...
- 访问nginx-php页面的时候 报access denied.
访问页面的时候出现这个时access denied 只需到/usr/local/php/etc/php.ini中修改一下 把这个注释掉 ;open_basedir = 把这个值赋值为1 cgi.f ...
- listview必须设置数据适配器才能显示出来
listview必须设置数据适配器才能显示出来,哪怕只设置一个空的数据适配器都行: lvTabDetail.setAdapter(new NewsListAdapter()); class NewsL ...
- docker容器和镜像区别
这篇文章希望能够帮助读者深入理解Docker的命令,还有容器(container)和镜像(image)之间的区别,并深入探讨容器和运行中的容器之间的区别. 当我对Docker技术还是一知半解的时候,我 ...
- 为什么要在onNewIntent的时候要显示的去调用setIntent
一.原因: 当调用到onNewIntent(intent)的时候,需要在onNewIntent() 中使用setIntent(intent)赋值给Activity的Intent.否则,后续的getIn ...