Ha it is really funny that you ask. Yes, this *was* intended behavior. FileDataModel and GenericDataModel were read-only, so the behavior you saw was intended. It is mostly for performance, and because FileDataModel gets updates from the file, not from the caller.
But just yesterday I changed these methods to work. You can call setPreference() and removePreference() now. Be warned though that the methods are not thread-safe -- you need to synchronize. They may be slow. And, FileDataModel does not update the underlying file with your change. It only remains temporarily in memory. If you get the latest version from Subversion you will see this. Sean On Wed, Apr 22, 2009 at 9:59 AM, Mirko Gontek <[email protected]> wrote: > Hi, > I experiment with Taste's FileDataModel to get a simple file-based example > running. Getter methods are working, but getPreference() and > removePreference() throw java.lang.UnsupportedOperationExceptions. Do I get > something wrong here? Here is my test code: > > File f = new File("input/data.csv"); > logger.debug(f.canWrite()); // true > DataModel model = new FileDataModel(f); > logger.debug("items "+ model.getNumItems()); // 3 > logger.debug("users "+ model.getNumUsers()); // 3 > Object[] prefs = model.getPreferencesForItemAsArray("evolution"); > logger.debug("prefs for evolution: "+prefs.length); // 1 > > model.setPreference("tom", "physics", new Double(0.1)); // THROWS EXCEPTION > // model.removePreference("tom","evolution"); // THROWS EXCEPTION > > java.lang.UnsupportedOperationException > at > org.apache.mahout.cf.taste.impl.model.file.FileDataModel.setPreference(FileDataModel.java:322) > > The content of input/data.csv is: > > tom,evolution,1 > anna,human,0 > tim,biology,1 > > Thanks for your help! Mirko > >
