Preference object: a single user ID, item ID, and preference value for genericpreference
Preferencearray, which is an array of all preference values of a single user, implements genericpreferencearray
Sample Code:
Package mahout; import Org. apache. mahout. cf. taste. impl. model. genericuserpreferencearray; import Org. apache. mahout. cf. taste. model. preference; import Org. apache. mahout. cf. taste. model. preferencearray; public class testdata {public static void main (string [] ARGs) {// a set of user preferences, indicating all preferences associated with a user, it contains a single user ID, an item ID array, and a preference value array // The item ID array corresponds to the preference value array one by one. // Array size: 2 preferencearray user1prefs = new genericuserpreferencearray (2); // The associated user iduser1prefs. setuserid (0, 1l); // The first preference user1prefs. setitemid (0, 101l); user1prefs. setvalue (0, 2.0f); // The second preference user1prefs. setitemid (1, 102l); user1prefs. setvalue (1, 3.0f); // try to put the third/* user1prefs. setitemid (2, 103l); user1prefs. setvalue (2, 3.0f); */preference Pref = user1prefs. get (1); system. out. println (Pref. getuserid (); system. out. println (Pref. getitemid (); system. out. println (Pref. getvalue ());}}
Output:
1
102
3.0
Let's take a third look: It's abnormal.
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2at org.apache.mahout.cf.taste.impl.model.GenericUserPreferenceArray.setItemID(GenericUserPreferenceArray.java:129)at mahout.TestData.main(TestData.java:23)
In addition, fastmap, fastbyidmap, and fastidset are embedded in the internal classes of mahout. If you want to use them, you can view the source code.