List of usage examples for org.apache.mahout.cf.taste.impl.common RefreshHelper RefreshHelper
public RefreshHelper(Callable<?> refreshRunnable)
From source file:recommender.MyRecommender.java
/** * Create a custom SVDRecommender using a persistent store to cache * factorizations. A factorization is loaded from the store if present, * otherwise a new factorization is computed and saved in the store. * * The {@link #refresh(java.util.Collection) refresh} method recomputes the * factorization and overwrites the store. * * @param dataModel/*from w ww. java2s . c o m*/ * @param factorizer * @param candidateItemsStrategy * @param persistenceStrategy * * @throws TasteException */ public MyRecommender(DataModel dataModel, Factorizer factorizer, CandidateItemsStrategy candidateItemsStrategy, PersistenceStrategy persistenceStrategy) throws TasteException { super(dataModel, candidateItemsStrategy); this.factorizer = Preconditions.checkNotNull(factorizer); this.persistenceStrategy = Preconditions.checkNotNull(persistenceStrategy); try { factorization = persistenceStrategy.load(); } catch (IOException e) { throw new TasteException("Error loading factorization", e); } if (factorization == null) { train(); } refreshHelper = new RefreshHelper(new Callable<Object>() { @Override public Object call() throws TasteException { train(); return null; } }); refreshHelper.addDependency(getDataModel()); refreshHelper.addDependency(factorizer); refreshHelper.addDependency(candidateItemsStrategy); }
From source file:recommender.ReloadFromJDBCDataModelCustom.java
License:Apache License
public ReloadFromJDBCDataModelCustom(JDBCDataModel delegate) throws TasteException { this.delegate = Preconditions.checkNotNull(delegate); refreshHelper = new RefreshHelper(new Callable<Void>() { @Override/* w ww.j a va2s.c o m*/ public Void call() { reload(); return null; //To change body of implemented methods use File | Settings | File Templates. } }); refreshHelper.addDependency(delegate); reload(); if (delegateInMemory == null) { throw new TasteException("Failed to load data into memory"); } }