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()
Loading/saving:
>>> a = AtomFactory.fromfile(filename)
>>> a.save(filename)
Note:
af(1) is candy for af.get_object(1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
remove(self,
objects)
Returns a new AtomFactory with the given objects removed. |
source code
|
|
|
|
|
|
|
|
|
Lock the AtomFactory.
No new atoms can be added; Only old ones can be retrieved.
|
|
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.
|