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

org.codelibs.elasticsearch.taste.similarity.EuclideanDistanceSimilarityFactory 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 EuclideanDistanceSimilarityFactory 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 EuclideanDistanceSimilarity(dataModel,
                    weighting);
            return t;
        } catch (final Exception e) {
            throw new TasteException("Failed to create an instance.", e);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy