All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.aliasi.test.unit.features.SerializableMockFeatureExtractor Maven / Gradle / Ivy

Go to download

This is the original Lingpipe: http://alias-i.com/lingpipe/web/download.html There were not made any changes to the source code.

There is a newer version: 4.1.2-JL1.0
Show newest version
package com.aliasi.test.unit.features;

import com.aliasi.util.FeatureExtractor;

import java.io.Serializable;

import java.util.Map;
import java.util.HashMap;

public class SerializableMockFeatureExtractor
    implements FeatureExtractor, Serializable {

    final Map> mMap = new HashMap>();

    public Map features(Integer in) {
        Map feats = mMap.get(in);
        return feats == null
            ? new HashMap()
            : feats;
    }

    public void put(int e, Map features) {
        mMap.put(e,features);
    }

    public void put(int e, String[] feats, double[] vals) {
        if (feats.length != vals.length) 
            throw new IllegalArgumentException();
        put(e,toMap(feats,vals));
    }

    static Map toMap(String[] feats, double[] vals) {
        Map result = new HashMap();
        for (int i = 0; i < feats.length; ++i)
            result.put(feats[i],vals[i]);
        return result;
    }

}
    





© 2015 - 2025 Weber Informatics LLC | Privacy Policy