Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.codelibs.elasticsearch.taste.recommender;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.Callable;
import org.codelibs.elasticsearch.taste.common.Cache;
import org.codelibs.elasticsearch.taste.common.LongPair;
import org.codelibs.elasticsearch.taste.common.RefreshHelper;
import org.codelibs.elasticsearch.taste.common.Refreshable;
import org.codelibs.elasticsearch.taste.common.Retriever;
import org.codelibs.elasticsearch.taste.model.DataModel;
import org.codelibs.elasticsearch.taste.model.PlusAnonymousUserDataModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.Preconditions;
/**
*
* A {@link Recommender} which caches the results from another {@link Recommender} in memory.
*
*/
public final class CachingRecommender implements Recommender {
private static final Logger log = LoggerFactory
.getLogger(CachingRecommender.class);
private final Recommender recommender;
private final int[] maxHowMany;
private final Retriever recommendationsRetriever;
private final Cache recommendationCache;
private final Cache estimatedPrefCache;
private final RefreshHelper refreshHelper;
private IDRescorer currentRescorer;
public CachingRecommender(final Recommender recommender) {
Preconditions.checkArgument(recommender != null, "recommender is null");
this.recommender = recommender;
maxHowMany = new int[] { 1 };
// Use "num users" as an upper limit on cache size. Rough guess.
final int numUsers = recommender.getDataModel().getNumUsers();
recommendationsRetriever = new RecommendationRetriever();
recommendationCache = new Cache(
recommendationsRetriever, numUsers);
estimatedPrefCache = new Cache(
new EstimatedPrefRetriever(), numUsers);
refreshHelper = new RefreshHelper(new Callable