edu.iu.iv.common.persistence.ivc
Class DelimitedSparseDoubleMatrixModelPersister

java.lang.Object
  |
  +--edu.iu.iv.common.persistence.ivc.DelimitedSparseDoubleMatrixModelPersister
All Implemented Interfaces:
Persister

public class DelimitedSparseDoubleMatrixModelPersister
extends java.lang.Object
implements Persister

This persister can persist to and restore from a delimited file using a sparse matrix format. The extension for such files is ".smf". The format for such a file is as follows: The first line should start with the delimiter, then the number of rows and columns. This delimiter is used as the delimiter throughout the file. The second line stores the row labels preceded by the string "RowLabels" (case-insensitive) and the delimiter The labels must be separated by the delimiter again. The third line stores the column labels preceded by the string "columnlabels" (case-insensitive) and the delimiter. The labels must be separated by the delimiter again. The fourth line has the string "Data" (case-insensitive) followed by a delimiter and a number that specifies the index offset. For example, if the line looks like this:
data,1
then a 1-based indexing is used. If it looks like this:
data,0
then 0-based indexing is used, etc. If nothing is specified, then the matrix is assumed to have 0-based indexing. Finally the data of the matrix is stored in file. The data is stored in coordinate-wise format with the first column containing the row indices the second column containing the column indices and the third column containing the values. Note that the first two columns must be integers else the persister will fail! An example of a complete file:

  ,5,5
  rowlabels,doc1,doc2,doc3,doc4,doc5
  columnlabels,term1,term2,term3,term4,term5
  data,1
  1,1,12.0
  1,2,15
  1,5,0
  2,3,-11.0
  2,1,94.5343   Note: The elements don't need to be ordered.

 
The labels are optional and you may provide only some of the labels if you wish. For example, the following line:

rowlabels,doc1,,doc3,,doc5

will assign labels only to rows 1, 3 and 5 and set the rest to an empty string "".

Version:
0.1
Author:
Team IVC

Constructor Summary
DelimitedSparseDoubleMatrixModelPersister()
           
 
Method Summary
 boolean canPersist(java.lang.Object model)
          Determines if this persister can persist the given data model.
 boolean canRestore(ResourceDescriptor resource)
           
 PropertyMap getPropertyMap()
          Gets a property map describing this persister and file format (if applicable).
 void persist(java.lang.Object model, ResourceDescriptor resource)
          Persists a data model to a resource such as a file or database.
 java.lang.Object restore(ResourceDescriptor resource)
          Restores a model from the specified resource.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DelimitedSparseDoubleMatrixModelPersister

public DelimitedSparseDoubleMatrixModelPersister()
Method Detail

getPropertyMap

public PropertyMap getPropertyMap()
Description copied from interface: Persister
Gets a property map describing this persister and file format (if applicable). If a persister does not wish to return a property map, it may return null. Returning a null value is highly discouraged. A persister must always provide enough information to let an application allow the user to make an informed choice.

Specified by:
getPropertyMap in interface Persister
Returns:
The property map of persister properties or null if the persister does not wish to return any map.
See Also:
Persister.getPropertyMap()

persist

public void persist(java.lang.Object model,
                    ResourceDescriptor resource)
             throws java.io.IOException,
                    PersistenceException
Description copied from interface: Persister
Persists a data model to a resource such as a file or database.

Specified by:
persist in interface Persister
Parameters:
model - The model to be persisted.
resource - The resource to persist the model to.
java.io.IOException
PersistenceException
See Also:
Persister.persist(java.lang.Object, edu.iu.iv.core.persistence.ResourceDescriptor)

restore

public java.lang.Object restore(ResourceDescriptor resource)
                         throws java.io.IOException,
                                PersistenceException
Description copied from interface: Persister
Restores a model from the specified resource. This method

Specified by:
restore in interface Persister
Returns:
The model to be restored from the data source.
java.io.IOException
PersistenceException
See Also:
Persister.restore(edu.iu.iv.core.persistence.ResourceDescriptor)

canPersist

public boolean canPersist(java.lang.Object model)
Description copied from interface: Persister
Determines if this persister can persist the given data model.

Specified by:
canPersist in interface Persister
Parameters:
model - The model for which persistence is desired.
Returns:
true if this persister can persist this object, false otherwise.
See Also:
Persister.canPersist(java.lang.Object)

canRestore

public boolean canRestore(ResourceDescriptor resource)
Specified by:
canRestore in interface Persister
Parameters:
resource - The resource from which restoration is desired. An example of a resource is a file on disk.
Returns:
true if this persister can persist to or restore from this resource, false otherwise.
See Also:
Persister.canRestore(ResourceDescriptor)