Search in sources :

Example 1 with ValueComparator

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;
}
Also used : HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) ValueComparator(legato.utils.ValueComparator) LEGATO(legato.LEGATO) StmtIterator(org.apache.jena.rdf.model.StmtIterator) Iterator(java.util.Iterator) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map) Key(legato.keys.def.Key) HashSet(java.util.HashSet)

Aggregations

HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 LEGATO (legato.LEGATO)1 Key (legato.keys.def.Key)1 ValueComparator (legato.utils.ValueComparator)1 StmtIterator (org.apache.jena.rdf.model.StmtIterator)1