com.graphaware.reco.generic.post.BasePostProcessor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of recommendation-engine Show documentation
Show all versions of recommendation-engine Show documentation
Skeleton for a Recommendation Engine
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.post;
import com.graphaware.reco.generic.context.Context;
import com.graphaware.reco.generic.result.Recommendations;
/**
* Base class for {@link PostProcessor} implementation that collects timing statistics about the process.
*
* @param type of the post-processed recommendations.
* @param type of the item recommendations are for / based on.
*/
public abstract class BasePostProcessor implements PostProcessor {
/**
* Get the name of this post processor. This name should be unique within the overall recommendation engine structure and
* will be used for naming scores produced by the post processor, as well as for collecting {@link com.graphaware.reco.generic.stats.Statistics}.
*
* @return name.
*/
protected abstract String name();
/**
* {@inheritDoc}
*/
@Override
public final void postProcess(Recommendations recommendations, IN input, Context context) {
context.statistics().startTiming(name());
doPostProcess(recommendations, input, context);
context.statistics().stopTiming(name());
}
/**
* Post-process results.
*
* @param recommendations scored recommendations.
* @param input for whom the recommendation have been produced, must not be null
.
* @param context for the recommendation computing process.
*/
protected abstract void doPostProcess(Recommendations recommendations, IN input, Context context);
/**
* {@inheritDoc}
*/
@Override
public float maxPositiveScore(IN input, Context context) {
return Float.POSITIVE_INFINITY;
}
/**
* {@inheritDoc}
*/
@Override
public float maxNegativeScore(IN input, Context context) {
return Float.NEGATIVE_INFINITY;
}
}