Package TEES :: Package Core :: Module Model :: Class Model
[hide private]

Class Model

source code

The Model object is an interface to a model file on the disk. The model file itself is simply a directory or zip-archive storing all the files that result from TEES being trained. In addition, it can store named string values for saved settings etc.

When a member of a model is accessed, it is copied to a temporary cache directory. When a model is saved, files that have changed in the cache are copied to the model directory/archive. Note that for both files and strings that are added to the model, are saved to it only when Model.save is called.

Instance Methods [hide private]
 
__init__(self, path, mode='r', verbose=True, compression=8)
Make a new model or open an existing one
source code
 
__del__(self) source code
 
close(self) source code
 
add(self, name) source code
 
insert(self, filepath, name)
Adds a new file to the model.
source code
 
importFrom(self, model, members, strings=None)
Copy several members from another model
source code
 
addStrings(self, dict)
Add multiple name/value pairs
source code
 
addStr(self, name, value)
Add a named string to the model
source code
 
getStr(self, name, defaultIfNotExist=NOTHING, asType=None)
Get a named string from the model
source code
 
save(self)
Save a model.
source code
 
saveAs(self, outPath)
Save a model with a different name.
source code
 
hasMember(self, name) source code
 
get(self, name, addIfNotExist=False)
Return a file member from the model.
source code
 
open(self, path, mode='r') source code
 
_openDir(self, path, mode) source code
 
_openPackage(self, path, mode) source code
 
_getValues(self) source code
 
_setValues(self, values) source code
Method Details [hide private]

__init__(self, path, mode='r', verbose=True, compression=8)
(Constructor)

source code 

Make a new model or open an existing one

Parameters:
  • path - The model file or directory. If making a new model, a path ending in ".zip" results in a compressed archive.
  • mode - r, w or a for read, write or append
  • verbose - Model reports what is happening
  • compression - The compression method if a the model is a zip-archive.

insert(self, filepath, name)

source code 

Adds a new file to the model.

Parameters:
  • filepath - Path to the file being added
  • name - Path of the file inside the model

addStr(self, name, value)

source code 

Add a named string to the model

@param : the name of the string @param : the string

getStr(self, name, defaultIfNotExist=NOTHING, asType=None)

source code 

Get a named string from the model

Parameters:
  • name - the name of the string
  • defaultIfNotExist - if set to a value != NOTHING, will be returned if a name does not exist. Otherwise an exception is raised.
  • asType - if set, cast the return value to this type

save(self)

source code 

Save a model.

When saving a model, files that have changed in the cache are written to the model.

get(self, name, addIfNotExist=False)

source code 

Return a file member from the model. The member is extracted to a cached directory and returned as a path name. If this file is modified, when the model is saved, it will be copied back to the model.

Parameters:
  • name - the path to the file inside the model
  • addIfNotExist - Return a file name which can be created for adding the file