Hello, Question about NoSuchElementException usage in Taste:
I'm using Taste in an environment where lots of requests for recommended items are for users who are new to the system - users who have no previously consumed items. When I try to get recommendations for such users, the following is thrown: java.util.NoSuchElementException at org.apache.mahout.cf.taste.impl.model.BooleanUserGenericDataModel.getUser(BooleanUserGenericDataModel.java:81) at org.apache.mahout.cf.taste.impl.model.file.BooleanPrefUserFileDataModel.getUser(BooleanPrefUserFileDataModel.java:163) at org.apache.mahout.cf.taste.impl.recommender.BooleanUserGenericUserBasedRecommender.recommend(BooleanUserGenericUserBasedRecommender.java:86) This looks correct, and comes from this piece of code in BooleanUserGenericDataModel (the same happens in non-Boolean versions of the code): public User getUser(Object id) { User user = userMap.get(id); if (user == null) { throw new NoSuchElementException(); } return user; } I'm wondering if this is good/best thing to do here. Here is some reasoning: - it's not really an error to ask a RE to recommend items for a user the RE knows nothing about - it's the cold start issue - I believe throwing exceptions is expensive, and I'm wondering if it would be cheaper to do something else - one could say this falls in the "using exceptions for flow control" category (because that's what I'll have to do on the higher level) - I briefly looked at returning null, but it looks like this would require checks for null to avoid NPE in a number of places I'm not sure this needs to change, but it's been on my mind for a while now. On my end I can simply catch this ugly exception and eat it, although this "NoSuchElementException" is so non-specific that if I just catch NoSuchElementException the code may one day end up catching a NoSuchElementException from some other part of Taste. Thoughts? Otis -- Sematext -- http://sematext.com/ -- Lucene - Solr - Nutch