uk.ac.shef.dcs.sti.util.CollectionUtils Maven / Gradle / Ivy
The newest version!
package uk.ac.shef.dcs.sti.util;
import javafx.util.Pair;
import java.util.*;
/**
* Author: Ziqi Zhang ([email protected])
* Date: 07/05/13
* Time: 16:38
*/
public class CollectionUtils {
public static double computeDice(Collection c1, Collection c2) {
Set intersection = new HashSet<>(c1);
intersection.retainAll(c1);
intersection.retainAll(c2);
if (intersection.size() == 0)
return 0.0;
double score = 2 * (double) intersection.size() / (c1.size() + c2.size());
return score;
}
//entity //context
/**
* how much of b does a cover
* @param a
* @param b
* @return
*/
public static double computeCoverage(Collection a, Collection b) {
List c = new ArrayList<>(b);
c.retainAll(a);
if(c.size()==0)
return 0.0;
double score = (double) c.size() / b.size();
return score;
}
public static double computeFrequencyWeightedDice(Collection c1, Collection c2) {
List union = new ArrayList<>();
union.addAll(c1);
union.addAll(c2);
List intersection = new ArrayList<>(union);
intersection.retainAll(c1);
intersection.retainAll(c2);
if (intersection.size() == 0)
return 0.0;
double score = 2 * (double) intersection.size() / (c1.size() + c2.size());
return score;
}
}