use of legato.utils.ValueComparator in project legato by DOREMUS-ANR.
the class SupportMergedKeys method rank.
public static HashSet<String> rank(KeyList mKeys, File srcFile, File tgtFile) throws IOException {
LEGATO legato = LEGATO.getInstance();
/**
****
* Get All Merged Keys
*****
*/
// will contain all merged keys
HashSet<HashSet<String>> keys = new HashSet<>();
Iterator iter = mKeys.iterator();
while (// For each merged key
iter.hasNext()) {
HashSet<String> properties = new HashSet<>();
Key key = (Key) iter.next();
Iterator iterProp = key.iterator();
while (// For each property
iterProp.hasNext()) {
String property = (String) iterProp.next();
properties.add(property);
}
keys.add(properties);
}
/**
****
* Support computing
*****
*/
HashMap<String, HashSet<String>> srcResources = fileParsing(srcFile.toString());
computeSupport(keys, srcResources);
NBs = 100;
allInstances.clear();
cib = true;
HashMap<String, HashSet<String>> tgtResources = fileParsing(tgtFile.toString());
computeSupport(keys, tgtResources);
NBt = 100;
ValueComparator<HashSet<String>> compSource = new ValueComparator<HashSet<String>>(keysSource);
TreeMap<HashSet<String>, String> mapTrieeSource = new TreeMap<HashSet<String>, String>(compSource);
mapTrieeSource.putAll(keysSource);
ValueComparator<HashSet<String>> compTarget = new ValueComparator<HashSet<String>>(keysTarget);
TreeMap<HashSet<String>, String> mapTrieeTarget = new TreeMap<HashSet<String>, String>(compTarget);
mapTrieeTarget.putAll(keysTarget);
/**
****
* Keys Ranking
*****
*/
HashMap<HashSet<String>, String> mergedKeys = new HashMap<HashSet<String>, String>();
Iterator iterSource = mapTrieeSource.entrySet().iterator();
while (iterSource.hasNext()) {
Map.Entry keySource = (Map.Entry) iterSource.next();
Iterator iterTarget = mapTrieeTarget.entrySet().iterator();
while (iterTarget.hasNext()) {
Map.Entry keyTarget = (Map.Entry) iterTarget.next();
if (keySource.getKey().equals(keyTarget.getKey())) {
float s = Float.valueOf((String) keySource.getValue());
float t = Float.valueOf((String) keyTarget.getValue());
float rankValue = s * t;
mergedKeys.put((HashSet<String>) keySource.getKey(), String.valueOf(rankValue));
}
}
}
ValueComparator<HashSet<String>> compMerg = new ValueComparator<HashSet<String>>(mergedKeys);
TreeMap<HashSet<String>, String> mapTrieeMerg = new TreeMap<HashSet<String>, String>(compMerg);
mapTrieeMerg.putAll(mergedKeys);
/**
****
* Return the first key (with the highest score)
*****
*/
HashSet<String> res;
if (mapTrieeMerg.isEmpty())
res = null;
else
res = mapTrieeMerg.firstEntry().getKey();
return res;
}
Aggregations