@Override public HybridRecommendationModel buildRecommendationModel( DatasetLoader<? extends Rating> datasetLoader) throws CannotLoadRatingsDataset, CannotLoadContentDataset, CannotLoadUsersDataset { ContentBasedRecommender<Object, Object> contentBasedAlgorithm = (ContentBasedRecommender<Object, Object>) getParameterValue(CONTENT_BASED_TECHNIQUE); RecommendationModelBuildingProgressListener contentBasedListener = (String actualJob, int percent, long remainingSeconds) -> { ContentWeightCollaborative.this.fireBuildingProgressChangedEvent( actualJob, percent / 2, -1); }; contentBasedAlgorithm.addRecommendationModelBuildingProgressListener(contentBasedListener); Object contentBasedModel = contentBasedAlgorithm.buildRecommendationModel(datasetLoader); CollaborativeRecommender collaborativeFilteringTechnique = (CollaborativeRecommender) getParameterValue(COLLABORATIVE_TECHNIQUE); RecommendationModelBuildingProgressListener collaborativeListener = (String actualJob, int percent, long remainingSeconds) -> { ContentWeightCollaborative.this.fireBuildingProgressChangedEvent( actualJob, percent / 2 + 50, -1); }; collaborativeFilteringTechnique.addRecommendationModelBuildingProgressListener( collaborativeListener); Object collaborativeModel = collaborativeFilteringTechnique.buildRecommendationModel(datasetLoader); return new HybridRecommendationModel(contentBasedModel, collaborativeModel); }
@Override public Collection<Recommendation> recommendToUser( DatasetLoader<? extends Rating> datasetLoader, HybridRecommendationModel model, Integer idUser, java.util.Set<Integer> candidateItems) throws UserNotFound, CannotLoadRatingsDataset, CannotLoadContentDataset, ItemNotFound, NotEnoughtUserInformation { ContentBasedRecommender<Object, Object> contentBasedAlgorithm = (ContentBasedRecommender<Object, Object>) getParameterValue(CONTENT_BASED_TECHNIQUE); CollaborativeRecommender<Object> collaborativeFilteringTechnique = (CollaborativeRecommender<Object>) getParameterValue(COLLABORATIVE_TECHNIQUE); Collection<Recommendation> content = contentBasedAlgorithm.recommendToUser( datasetLoader, model.getModel(0), idUser, candidateItems); Collection<Recommendation> collaborative = collaborativeFilteringTechnique.recommendToUser( datasetLoader, model.getModel(1), idUser, candidateItems); return joinRecommendationLists(content, collaborative); }