Search in sources :

Example 1 with StringHashKeyProvider

use of zemberek.core.hash.StringHashKeyProvider in project zemberek-nlp by ahmetaa.

the class LossyIntLookup method generate.

/**
 * Generates a LossyIntLookup from a String->Float lookup
 */
public static LossyIntLookup generate(FloatValueMap<String> lookup) {
    List<String> keyList = lookup.getKeyList();
    StringHashKeyProvider provider = new StringHashKeyProvider(keyList);
    MultiLevelMphf mphf = MultiLevelMphf.generate(provider);
    int[] data = new int[keyList.size() * 2];
    for (String s : keyList) {
        int index = mphf.get(s);
        // fingerprint
        data[index * 2] = getFingerprint(s);
        // data in int form
        data[index * 2 + 1] = Float.floatToIntBits(lookup.get(s));
    }
    return new LossyIntLookup(mphf, data);
}
Also used : StringHashKeyProvider(zemberek.core.hash.StringHashKeyProvider) MultiLevelMphf(zemberek.core.hash.MultiLevelMphf)

Aggregations

MultiLevelMphf (zemberek.core.hash.MultiLevelMphf)1 StringHashKeyProvider (zemberek.core.hash.StringHashKeyProvider)1