@Override
	public void map(LongWritable id, Text line,
			OutputCollector<IntWritable, Text> out, Reporter reporter)
			throws IOException {

		
		
		// Get Name and Text of document
		contents = line.toString().split("\\|",2);
		words = contents[1].split("\\s+");

		// Process for document names and contents that are not empty (or just a space)
		if (contents[0].length() > 1 && contents[1].length() > 1){

			wordCounts = new HashMap<String, Double>();
			double tf = 0;
			double idf = 0;
			maxWordCount = 0;
			tfidf = new HashMap<String, Double>();
			int count;
			double documentCount = (double) docFrequency.getDocumentCount();
			// Process each word to get totals
			for (int i = 0; i < words.length; i++){

				word = words[i];
				
				if (wordCounts.containsKey(word)){
					wordCounts.put(word, wordCounts.get(word) + 1.0);
				} else {
					wordCounts.put(word, 1.0);
				}
			}

			// Get highest word count in the document
			for (double value : wordCounts.values()){
				maxWordCount = Math.max(maxWordCount, value);
			}
						
			// Process each unique word to get tfidf			
			for (int i = 0; i < words.length; i++){

				word = words[i];
				
				if (word.trim().length() > 1){
					
					count =  docFrequency.getCount(word);
					
					if (count == 0){
						count = 1;
					}
					
					idf = Math.log(documentCount / (double) count);
					tf = 0.5 + (0.5 * wordCounts.get(word) / maxWordCount);
										
					tfidf.put(word, tf * idf);
				
				}
				
			}

			// Optional Steps:			
			// Sort tfidf
			// Cut to top K (maybe)
			
			// Get reducer key based on title
 			key = new IntWritable();
			key.set(contents[0].toLowerCase().trim().charAt(0));

			// Create tfidf string
			sb = new StringBuilder(wordCounts.size());
			sb.append(contents[0].toLowerCase().trim());
			sb.append("|");
			
			for (String key : tfidf.keySet()){
				
				sb.append(key);
				sb.append(":");
				sb.append(tfidf.get(key));
				sb.append(",");
				
			}
			
			tfidfString = sb.toString();

			// Emit title + tfidf string
			//System.out.println(tfidfString);
			out.collect(key, new Text(tfidfString));
				
				
		}

	}