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

org.codelibs.elasticsearch.taste.similarity.UncenteredCosineSimilarityFactory Maven / Gradle / Ivy

package org.codelibs.elasticsearch.taste.similarity;

import java.util.Map;

import org.codelibs.elasticsearch.taste.common.Weighting;
import org.codelibs.elasticsearch.taste.exception.TasteException;
import org.codelibs.elasticsearch.util.settings.SettingsUtils;

public class UncenteredCosineSimilarityFactory extends
        AbstractUserSimilarityFactory {

    protected Weighting weighting;

    @Override
    public void init(final Map settings) {
        super.init(settings);
        final String value = SettingsUtils.get(settings, "weighting");
        if ("WEIGHTED".equalsIgnoreCase(value)) {
            weighting = Weighting.WEIGHTED;
        } else {
            weighting = Weighting.UNWEIGHTED;
        }
    }

    @Override
    public T create() {
        try {
            @SuppressWarnings("unchecked")
            final T t = (T) new UncenteredCosineSimilarity(dataModel, weighting);
            return t;
        } catch (final Exception e) {
            throw new TasteException("Failed to create an instance.", e);
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy