List of usage examples for org.apache.mahout.cf.taste.impl.model.mongodb MongoDBDataModel getUserIDs
@Override
public LongPrimitiveIterator getUserIDs() throws TasteException
From source file:com.aguin.stock.recommender.StockRecommender.java
License:Apache License
public static void run(DataModel model, Recommender rec) throws TasteException { if (!(model instanceof MongoDBDataModel)) { throw new ClassCastException("Data Model must be a-Mongo!"); }/*from www . j a va 2 s .c o m*/ MongoDBDataModel mgmodel = (MongoDBDataModel) model; System.out.println("Start recommender\n"); LongPrimitiveIterator it = mgmodel.getUserIDs(); while (it.hasNext()) { long userId = it.nextLong(); // get the recommendations for the user List<RecommendedItem> recommendations = rec.recommend(userId, 10); // if empty write something if (recommendations.size() == 0) { System.out.print("User "); System.out.print(mgmodel.fromLongToId(userId)); System.out.println(": no recommendations"); } // print the list of recommendations for each for (RecommendedItem recommendedItem : recommendations) { System.out.print("User "); System.out.print(mgmodel.fromLongToId(userId)); System.out.print(": "); System.out.println(recommendedItem); } } }