|
Re: [LingPipe] Persistent Classifier in RDBMS?
> Is it possible to serialize an instance of a classifier after it is
> trained and persist the object in a relation database for later use?
This will depend on which classifier you use.
All of them either implement java.io.Serializable,
or they implement com.aliasi.util.Compilable.
The Compilable interface has one method,
void compileTo(java.io.ObjectOutput);
For this to work, the components the classifier
uses (e.g. tokenizers, feature extractors, etc.)
will have to be either serializable or compilable.
All of our built-in ones are for just this reason.
That way, you don't lose synch between a classifier
and its component parts.
Serialization works as usual in Java. Compilation
usually means you get a compiled form of the classifier,
which for most of our classifiers is more compact
and more efficient.
I don't know how Daffodil lets you specify
blogs, but it's easy to create a byte array
with the bytes.
ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(bytesOut);
then for serialization:
out.writeObject(classifier);
or for compilation:
classifier.compileTo(out);
and then:
out.close();
byte[] bytes = bytesOut.toByteArray();
then store the bytes as a blob.
Those bytes are the classifier. Then to
read them back in:
byte[] classifierBytes = get bytes from blog
ByteArrayInputStream bytesIn
= new ByteArrayInputStream(classifierBytes);
ObjectInputStream objIn = new ObjectInputStream(bytesIn);
Classifier<E,C> classifier
= (Classifier<E,C>) objIn.readObject();
- Bob Carpenter
Alias-i
|