下面的无法运行。
@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. Windows Access Token

    security descriptor A structure and associated data that contains the security information for a sec ...

  2. MFC消息机制

    何谓消息.消息处理函数.消息映射?消息简单的说就是指通过输入设备向程序发出指令要执行某个操作.具体的某个操作是你的一系列代码.称为消息处理函数. 在SDK中消息其实非常容易理解,当窗口建立后便会有一个 ...

  3. 多选出差同事id,拼接,去掉最后逗号

    ===========方法1 substr() ,永远都是.(第一个参数)开始位置.(第二个参数)截取个数 ,负数表示都后面开始数 substr($data['members'],0,strlen($ ...

  4. php数据排序---array_multisort

    PHP代码 <?php $ar1 = array(10, 100, 100, 0); $ar2 = array(1, 3, 2, 4); array_multisort($ar1, $ar2); ...

  5. nopcommerce插件相关

    注意Description.txt中,以下字段必须配置当前可用.我抄人家代码的时候,人家是3.4   我也配成3.4,结果我的nop是3.7的,后台半天显示不出来插件,浪费了一下午.

  6. repeat帮定删除按钮事件,并且生成去人删除提示

    前台 <ItemTemplate> <tr> <td> <asp:LinkButton ID="LinkButton_cancel" On ...

  7. 其它网页可以上网,IE浏览器打不开网页的解决办法

    下面是自己引用别人的,作为自己的备注 昨天由于安装了多款软件,今天开机发现IE浏览器打不开了,废了些周折终于,修复了IE浏览器,现将ie浏览器打不开网页的经验分享给大家,希望此经验对于出现过此类情况的 ...

  8. asp.net 基础

    前台HTML,javascript,后台C# 代码能不在后台写,就不在后台写 WebSite和WebApplication的区别 1)当改变后台代码时,WebApplication需重启浏览器或者重新 ...

  9. Mybatis 一对一,一对多,多对一,多对多的理解

    First (一对一) 首先我来说下一对一的理解,就是一个班主任只属于一个班级,一个班级也只能有一个班主任.好吧这就是对于一对一的理解 怎么来实现呢? 这里我介绍了两种方式: 一种是:使用嵌套结果映射 ...

  10. HDU 2802 F(N)(简单题,找循环解)

    题目链接 F(N) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...