LanguageModel.java 文件源码

java
阅读 17 收藏 0 点赞 0 评论 0

项目:mapreduce-samples 作者:
public void reduce(Text key, Iterable<Text> values, Context context) throws IOException, InterruptedException {

            //this -> <is=1000, is book=10>

            TreeMap<Integer, List<String>> tm = new TreeMap<Integer, List<String>>(Collections.reverseOrder());
            for (Text val : values) {
                String cur_val = val.toString().trim();
                String word = cur_val.split("=")[0].trim();
                int count = Integer.parseInt(cur_val.split("=")[1].trim());
                if(tm.containsKey(count)) {
                    tm.get(count).add(word);
                }
                else {
                    List<String> list = new ArrayList<>();
                    list.add(word);
                    tm.put(count, list);
                }
            }

            Iterator<Integer> iter = tm.keySet().iterator();

            for(int j=0 ; iter.hasNext() && j < n; j++) {
                int keyCount = iter.next();
                List<String> words = tm.get(keyCount);
                for(String curWord: words) {
                    context.write(new DBOutputWritable(key.toString(), curWord, keyCount), NullWritable.get());
                    j++;
                }
            }
        }
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号