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

com.graphaware.reco.generic.engine.BaseRecommendationEngine Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 2013-2016 GraphAware
 *
 * This file is part of the GraphAware Framework.
 *
 * GraphAware Framework is free software: you can redistribute it and/or modify it under the terms of
 * the GNU General Public License as published by the Free Software Foundation, either
 * version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details. You should have received a copy of
 * the GNU General Public License along with this program.  If not, see
 * .
 */

package com.graphaware.reco.generic.engine;

import com.graphaware.reco.generic.context.Context;
import com.graphaware.reco.generic.policy.ParticipationPolicy;
import com.graphaware.reco.generic.result.Recommendations;
import com.graphaware.reco.generic.stats.Statistics;

/**
 * Abstract base class for {@link com.graphaware.reco.generic.engine.RecommendationEngine} implementations. Takes care
 * of collecting statistics.
 *
 * @param  type of the recommendations produced.
 * @param   type of the item recommendations are for / based on.
 */
public abstract class BaseRecommendationEngine implements RecommendationEngine {

    /**
     * {@inheritDoc}
     *
     * @return {@link com.graphaware.reco.generic.policy.ParticipationPolicy#ALWAYS} by default.
     */
    @Override
    public ParticipationPolicy participationPolicy(Context context) {
        //noinspection unchecked
        return ParticipationPolicy.ALWAYS;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public final Recommendations recommend(IN input, Context context) {
        context.statistics().startTiming(name());

        Recommendations result = doRecommend(input, context);

        context.statistics().stopTiming(name());
        context.statistics().addStatistic(name(), Statistics.TOTAL_ITEMS, result.size());

        return result;
    }

    /**
     * Produce recommendations.
     *
     * @param input   input to the recommendation engine. Typically the person or item recommendations are being
     *                computed for.
     * @param context additional information about the recommendation process useful to the engine.
     * @return recommendations.
     */
    protected abstract Recommendations doRecommend(IN input, Context context);
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy