package gr.iti.mklab.method;
import gr.iti.mklab.data.ImageMetadata;
import gr.iti.mklab.util.MyHashMap;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.HashSet;


public class SimilaritySearch extends AbstractSimilaritySearch{

	public SimilaritySearch(int k, int a, double threshold){
		super(k,a,threshold);
	}


	public Double[] computeSimilarity(String imageTags, 
			List<ImageMetadata> images){

		Map<Integer,Double> mapSim = new HashMap<Integer,Double>();

		String [] testImageTags = imageTags.split(",");

		for (int i=0; i<images.size(); i++){

			double counter = 0.0;
			
			Set<String> trainImageTags = new HashSet<String>(Arrays.asList(images.get(i).getTags().split(",")));

			for (int j=0; j<testImageTags.length; j++){

				if (trainImageTags.contains(testImageTags[j])){
					counter += 1.0;
				}
			}

			double sjacc = counter / (testImageTags.length 
					+ trainImageTags.size() - counter);

			mapSim.put(i,sjacc);

		}

		int t = 0, size = k;
		Double[] coord = null;

		MyHashMap.sortByValues(mapSim);

		if(mapSim.size()<k){
			size = mapSim.size();
		}

		for (int i=0; i<size; i++){
			if (mapSim.get(i)>threshold){
				t++;
			}
		}

		if (t!=0){
			coord = computeCoordination(images, mapSim, t);
		}
		else{
			if (!mapSim.isEmpty()){
				coord = computeCoordination(images, mapSim, 1);
			}
		}
		
		return coord;
	}
}

@@ -22,16 +22,17 @@
 method;%0A
+%0A
 import g
@@ -245,16 +245,183 @@
 shSet;%0A%0A
+/**%0A * Class that implements similarity search for a query image in a list of images calculating the similarity between the corresponding tags%0A * @author gkordo%0A *%0A */
 %0Apublic 
@@ -477,16 +477,79 @@
 Search%7B%0A
+%09%0A%09// Constractor initializes the required values of the method
 %0A%09public
@@ -627,17 +627,16 @@
 d);%0A%09%7D%0A%0A
-%0A
 %09public 
@@ -828,16 +828,75 @@
 (%22,%22);%0A%0A
+%09%09// calculate similarity for every image of the given set%0A
 %09%09for (i
@@ -1401,16 +1401,65 @@
 pSim);%0A%0A
+%09%09// check if the silimar images are less than k%0A
 %09%09if(map
@@ -1503,16 +1503,76 @@
 );%0A%09%09%7D%0A%0A
+%09%09// check how many images are above the provided threshold%0A
 %09%09for (i

Add comments to SimilaritySearch.java