Package mekano :: Package atoms :: Module atomfactory :: Class AtomFactory
[hide private]
[frames] | no frames]

Class AtomFactory

source code

A single AtomFactory makes unique atoms for the given objects. By atoms, we just mean numbers. Objects just have to be hashable.

To get the Pipeline's (type, object) atoms, just use tuples!

>>> af = AtomFactory("mytokens")
>>> a1 = af["apples"]
>>> a2 = af["oranges"]
>>> assert(a1 == 1)
>>> assert(a2 == 2)
>>> assert(af(1) == "apples")
>>> a.lock()                        # Do not allow changes.

Loading/saving:

>>> a = AtomFactory.fromfile(filename)
>>> a.save(filename)

Note: af(1) is candy for af.get_object(1)

Instance Methods [hide private]
 
__init__(self, name='noname') source code
 
__repr__(self) source code
 
__getitem__(self, obj) source code
 
get_object(self, a) source code
 
__call__(self, a) source code
 
__len__(self) source code
 
__contains__(self, obj) source code
 
lock(self)
Lock the AtomFactory.
source code
 
remove(self, objects)
Returns a new AtomFactory with the given objects removed.
source code
 
save(self, filename) source code
 
savetxt(self, filename)
Save each object on a line.
source code
Static Methods [hide private]
 
fromfile(filename) source code
Method Details [hide private]

lock(self)

source code 

Lock the AtomFactory.

No new atoms can be added; Only old ones can be retrieved.

savetxt(self, filename)

source code 

Save each object on a line.

This should be enough to reconstruct the AtomFactory, and is also useful for things like LDA's vocabulary file.