FileDataModel ClassNReco.Recommender Class Library
A IDataModel backed by a delimited file.
Inheritance Hierarchy

System Object
  NReco.CF.Taste.Impl.Model AbstractDataModel
    NReco.CF.Taste.Impl.Model.File FileDataModel

Namespace: NReco.CF.Taste.Impl.Model.File
Assembly: NReco.Recommender (in NReco.Recommender.dll) Version: 1.0.0.0 (1.0.0.0)
Syntax

public class FileDataModel : AbstractDataModel

The FileDataModel type exposes the following members.

Constructors

  NameDescription
Public methodFileDataModel(String)
Initializes a new instance of the FileDataModel class
Public methodFileDataModel(String, String)
Initializes a new instance of the FileDataModel class
Public methodFileDataModel(String, Boolean, Int64, Boolean, String)
Initializes a new instance of the FileDataModel class
Top
Methods

  NameDescription
Protected methodbuildModel
Public methodStatic memberDetermineDelimiter
Public methodEquals
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetDataFile
Public methodGetDelimiter
Public methodGetHashCode
Serves as a hash function for a particular type.
(Inherited from Object.)
Public methodGetItemIDs (Overrides AbstractDataModel GetItemIDs .)
Public methodGetItemIDsFromUser (Overrides AbstractDataModel GetItemIDsFromUser(Int64).)
Public methodGetLoadedDataModel
Public methodGetMaxPreference (Overrides AbstractDataModel GetMaxPreference .)
Public methodGetMinPreference (Overrides AbstractDataModel GetMinPreference .)
Public methodGetNumItems (Overrides AbstractDataModel GetNumItems .)
Public methodGetNumUsers (Overrides AbstractDataModel GetNumUsers .)
Public methodGetNumUsersWithPreferenceFor(Int64) (Overrides AbstractDataModel GetNumUsersWithPreferenceFor(Int64).)
Public methodGetNumUsersWithPreferenceFor(Int64, Int64) (Overrides AbstractDataModel GetNumUsersWithPreferenceFor(Int64, Int64).)
Public methodGetPreferencesForItem (Overrides AbstractDataModel GetPreferencesForItem(Int64).)
Public methodGetPreferencesFromUser (Overrides AbstractDataModel GetPreferencesFromUser(Int64).)
Public methodGetPreferenceTime (Overrides AbstractDataModel GetPreferenceTime(Int64, Int64).)
Public methodGetPreferenceValue (Overrides AbstractDataModel GetPreferenceValue(Int64, Int64).)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodGetUserIDs (Overrides AbstractDataModel GetUserIDs .)
Public methodHasPreferenceValues (Overrides AbstractDataModel HasPreferenceValues .)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Protected methodprocessFile T 
Protected methodprocessFileWithoutID
Protected methodprocessLine T 
Protected methodprocessLineWithoutID
Protected methodreadItemIDFromString
Protected methodreadTimestampFromString
Protected methodreadUserIDFromString
Public methodRefresh (Overrides AbstractDataModel Refresh(IList IRefreshable ).)
Protected methodreload
Public methodRemovePreference (Overrides AbstractDataModel RemovePreference(Int64, Int64).)
Protected methodsetMaxPreference (Inherited from AbstractDataModel.)
Protected methodsetMinPreference (Inherited from AbstractDataModel.)
Public methodSetPreference (Overrides AbstractDataModel SetPreference(Int64, Int64, Single).)
Public methodToString (Overrides Object ToString .)
Top
Fields

  NameDescription
Public fieldStatic memberDEFAULT_MIN_RELOAD_INTERVAL_MS
Top
Remarks

This class expects a file where each line contains a user ID, followed by item ID, followed by optional preference value, followed by optional timestamp. Commas or tabs delimit fields:

userID,itemID[,preference[,timestamp]]

Preference value is optional to accommodate applications that have no notion of a preference value (that is, the user simply expresses a preference for an item, but no degree of preference).

The preference value is assumed to be parseable as a

. The user IDs and item IDs are read parsed as s. The timestamp, if present, is assumed to be parseable as a , though this can be overridden via readTimestampFromString(String). The preference value may be empty, to indicate "no preference value", but cannot be empty. That is, this is legal:

123,456,,129050099059

But this isn't:

123,456,129050099059

It is also acceptable for the lines to contain additional fields. Fields beyond the third will be ignored. An empty line, or one that begins with '#' will be ignored as a comment.

This class will reload data from the data file when Refresh(IList IRefreshable ) is called, unless the file has been reloaded very recently already.

This class will also look for update "delta" files in the same directory, with file names that start the same way (up to the first period). These files have the same format, and provide updated data that supersedes what is in the main data file. This is a mechanism that allows an application to push updates to FileDataModel without re-copying the entire data file.

One small format difference exists. Update files must also be able to express deletes. This is done by ending with a blank preference value, as in "123,456,".

Note that it's all-or-nothing -- all of the items in the file must express no preference, or the all must. These cannot be mixed. Put another way there will always be the same number of delimiters on every line of the file!

This class is not intended for use with very large amounts of data (over, say, tens of millions of rows). For that, a JDBC-backed {@link DataModel} and a database are more appropriate.

It is possible and likely useful to subclass this class and customize its behavior to accommodate application-specific needs and input formats.

See Also