## org.apache.mahout.cf.taste.impl.model
Class GenericBooleanPrefDataModel

    java.lang.Object
      org.apache.mahout.cf.taste.impl.model.AbstractDataModel
          org.apache.mahout.cf.taste.impl.model.GenericBooleanPrefDataModel

All Implemented Interfaces:
  java.io.Serializable, Refreshable, DataModel

    public final class GenericBooleanPrefDataModel

extends AbstractDataModel

A simple `DataModel` which uses given user data as its data source. This implementation is mostly useful for small experiments and is not recommended for contexts where performance is important.

See Also:
  Serialized Form

Constructor Summary
`GenericBooleanPrefDataModel(DataModel dataModel)` Deprecated. without direct replacement. Consider `toDataMap(DataModel)` with `GenericBooleanPrefDataModel(FastByIDMap)`
`GenericBooleanPrefDataModel(FastByIDMap<FastIDSet> userData)` Creates a new `GenericDataModel` from the given users (and their preferences).
`GenericBooleanPrefDataModel(FastByIDMap<FastIDSet> userData, FastByIDMap<FastByIDMap<java.lang.Long>> timestamps)` Creates a new `GenericDataModel` from the given users (and their preferences).

Method Summary
`LongPrimitiveArrayIterator` `getItemIDs()`
`FastIDSet` `getItemIDsFromUser(long userID)`
`int` `getNumItems()`
`int` `getNumUsers()`
`int` `getNumUsersWithPreferenceFor(long... itemIDs)`
`PreferenceArray` `getPreferencesForItem(long itemID)`
`PreferenceArray` `getPreferencesFromUser(long userID)`
`java.lang.Long` `getPreferenceTime(long userID, long itemID)` Retrieves the time at which a preference value from a user and item was set, if known.
`java.lang.Float` `getPreferenceValue(long userID, long itemID)` Retrieves the preference value for a single user and item.
`FastByIDMap<FastIDSet>` `getRawUserData()` This is used mostly internally to the framework, and shouldn't be relied upon otherwise.
`LongPrimitiveArrayIterator` `getUserIDs()`
`boolean` `hasPreferenceValues()`
`void` `refresh(java.util.Collection<Refreshable> alreadyRefreshed)` Triggers "refresh" -- whatever that means -- of the implementation.
`void` `removePreference(long userID, long itemID)` Removes a particular preference for a user.
`void` `setPreference(long userID, long itemID, float value)` Sets a particular preference (item plus rating) for a user.
`static FastByIDMap<FastIDSet>` `toDataMap(DataModel dataModel)` Exports the simple user IDs and associated item IDs in the data model.
`static FastByIDMap<FastIDSet>` `toDataMap(FastByIDMap<PreferenceArray> data)`
`java.lang.String` `toString()`

Methods inherited from class org.apache.mahout.cf.taste.impl.model.AbstractDataModel
`getMaxPreference, getMinPreference, setMaxPreference, setMinPreference`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Constructor Detail

### GenericBooleanPrefDataModel

    public GenericBooleanPrefDataModel(FastByIDMap<FastIDSet> userData)

  Creates a new `GenericDataModel` from the given users (and their preferences). This `DataModel` retains all this information in memory and is effectively immutable.

  Parameters:
    `userData` - users to include

### GenericBooleanPrefDataModel

    public GenericBooleanPrefDataModel(FastByIDMap<FastIDSet> userData,
                                       FastByIDMap<FastByIDMap<java.lang.Long>> timestamps)

  Creates a new `GenericDataModel` from the given users (and their preferences). This `DataModel` retains all this information in memory and is effectively immutable.

  Parameters:
    `userData` - users to include
    `timestamps` - optionally, provided timestamps of preferences as milliseconds since the epoch. User IDs are mapped to maps of item IDs to Long timestamps.

### GenericBooleanPrefDataModel

    @Deprecated
    public GenericBooleanPrefDataModel(DataModel dataModel)
                                throws TasteException

  Deprecated. without direct replacement. Consider `toDataMap(DataModel)` with `GenericBooleanPrefDataModel(FastByIDMap)`

  Creates a new `GenericDataModel` containing an immutable copy of the data from another given `DataModel`.

  Parameters:
    `dataModel` - `DataModel` to copy
  Throws:
    `TasteException` - if an error occurs while retrieving the other `DataModel`'s users

Method Detail

### toDataMap

    public static FastByIDMap<FastIDSet> toDataMap(DataModel dataModel)
                                            throws TasteException

  Exports the simple user IDs and associated item IDs in the data model.

  Returns:
    a `FastByIDMap` mapping user IDs to `FastIDSet`s representing that user's associated items
  Throws:
    `TasteException`

### toDataMap

    public static FastByIDMap<FastIDSet> toDataMap(FastByIDMap<PreferenceArray> data)

### getRawUserData

    public FastByIDMap<FastIDSet> getRawUserData()

  This is used mostly internally to the framework, and shouldn't be relied upon otherwise.

### getUserIDs

    public LongPrimitiveArrayIterator getUserIDs()

  Returns:
    all user IDs in the model, in order

### getPreferencesFromUser

    public PreferenceArray getPreferencesFromUser(long userID)
                                           throws NoSuchUserException

  Parameters:
    `userID` - ID of user to get prefs for
  Returns:
    user's preferences, ordered by item ID
  Throws:
    `NoSuchUserException` - if there is no such user

### getItemIDsFromUser

    public FastIDSet getItemIDsFromUser(long userID)
                                 throws TasteException

  Parameters:
    `userID` - ID of user to get prefs for
  Returns:
    IDs of items user expresses a preference for
  Throws:
    `NoSuchUserException` - if the user does not exist
    `TasteException` - if an error occurs while accessing the data

### getItemIDs

    public LongPrimitiveArrayIterator getItemIDs()

  Returns:
    a `LongPrimitiveIterator` of all item IDs in the model, in order

### getPreferencesForItem

    public PreferenceArray getPreferencesForItem(long itemID)
                                          throws NoSuchItemException

  Parameters:
    `itemID` - item ID
  Returns:
    all existing `Preference`s expressed for that item, ordered by user ID, as an array
  Throws:
    `NoSuchItemException` - if the item does not exist

### getPreferenceValue

    public java.lang.Float getPreferenceValue(long userID,
                                              long itemID)
                                       throws NoSuchUserException

  Description copied from interface: `DataModel`
  Retrieves the preference value for a single user and item.

  Parameters:
    `userID` - user ID to get pref value from
    `itemID` - item ID to get pref value for
  Returns:
    preference value from the given user for the given item or null if none exists
  Throws:
    `NoSuchUserException` - if the user does not exist

### getPreferenceTime

    public java.lang.Long getPreferenceTime(long userID,
                                            long itemID)
                                     throws TasteException

  Description copied from interface: `DataModel`
  Retrieves the time at which a preference value from a user and item was set, if known. Time is expressed in the usual way, as a number of milliseconds since the epoch.

  Parameters:
    `userID` - user ID for preference in question
    `itemID` - item ID for preference in question
  Returns:
    time at which preference was set or null if no preference exists or its time is not known
  Throws:
    `NoSuchUserException` - if the user does not exist
    `TasteException` - if an error occurs while accessing the data

### getNumItems

    public int getNumItems()

  Returns:
    total number of items known to the model. This is generally the union of all items preferred by at least one user but could include more.

### getNumUsers

    public int getNumUsers()

  Returns:
    total number of users known to the model.

### getNumUsersWithPreferenceFor

    public int getNumUsersWithPreferenceFor(long... itemIDs)

  Parameters:
    `itemIDs` - item IDs to check for
  Returns:
    the number of users who have expressed a preference for all of the items

### removePreference

    public void removePreference(long userID,
                                 long itemID)

  Description copied from interface: `DataModel`

  Removes a particular preference for a user.

  Parameters:
    `userID` - user from which to remove preference
    `itemID` - item to remove preference for

### setPreference

    public void setPreference(long userID,
                              long itemID,
                              float value)

  Description copied from interface: `DataModel`

  Sets a particular preference (item plus rating) for a user.

  Parameters:
    `userID` - user to set preference for
    `itemID` - item to set preference for
    `value` - preference value

### refresh

    public void refresh(java.util.Collection<Refreshable> alreadyRefreshed)

  Description copied from interface: `Refreshable`

  Triggers "refresh" -- whatever that means -- of the implementation. The general contract is that any should always leave itself in a consistent, operational state, and that the refresh atomically updates internal state from old to new.

  Parameters:
    `alreadyRefreshed` - s that are known to have already been refreshed as a result of an initial call to a method on some object. This ensure that objects in a refresh dependency graph aren't refreshed twice needlessly.

### hasPreferenceValues

    public boolean hasPreferenceValues()

  Returns:
    true iff this implementation actually stores and returns distinct preference values; that is, if it is not a 'boolean' DataModel

### toString

    public java.lang.String toString()

  Overrides:
    `toString` in class `java.lang.Object`

Copyright © 2008-2010 The Apache Software Foundation. All Rights Reserved.