private Distance<Contact> getdDistance(){
	return new Distance<Contact>(){
		@Override
		public double distance(Contact contact_1, Contact contact_2) {
			
			Map<String,Integer> c1 = contact_1.bag_of_words();
			Map<String,Integer> c2 = contact_2.bag_of_words();
			
		    double sum_c1 = 0.0;
		    for (Integer i : c1.values()) {
		        sum_c1 += i;  // tf =sqrt(count); sum += tf * tf
		    }
		    double sum_c2 = 0.0;
		    for (Integer i : c2.values()) {
		        sum_c2 += i;  // tf =sqrt(count); sum += tf * tf
		    }	    
		    
		    double product = 0.0;
		    
		    for (String token : c1.keySet()) {
		        Integer count = c2.get(token);
		        if (count == null || count==0) continue;
		        product += Math.sqrt(count * c1.get(token)); // tf = sqrt(count)
		    }
		    
		    double cosine = product / (sum_c1 * sum_c2);
		    
		    System.out.println(""+(1.0 - cosine));
		    
		    return 1.0 - cosine;
		}		
	};
}