Hello Ofer,

the CAS cannot be serialized immediately, but there is a helper class which is 
serializable.

To write:

ObjectOutputStream docOS = ...
CASCompleteSerializer serializer = 
Serialization.serializeCASComplete(aJCas.getCasImpl());
docOS.writeObject(serializer);

To read:

ObjectInputStream is = ...
CASCompleteSerializer serializer = (CASCompleteSerializer) is.readObject();
Serialization.deserializeCASComplete(serializer, (CASImpl) aCAS);

However, there are newer and more efficient binary formats that you might want 
to use [1]. 

If you want to dig into the topic or if you want to use a ready-made pair of
readers/writers for the binary formats, you could consider taking a look at
the BinaryCasReader/Writer in the DKPro Core [2,3] (non-ASF).

Cheers,

-- Richard

[1] 
http://uima.apache.org/d/uimaj-2.6.0/tutorials_and_users_guides.html#ugr.tug.type_filtering.compressed_file
[2] 
https://code.google.com/p/dkpro-core-asl/source/browse/de.tudarmstadt.ukp.dkpro.core-asl/trunk/de.tudarmstadt.ukp.dkpro.core.io.bincas-asl/src/main/java/de/tudarmstadt/ukp/dkpro/core/io/bincas/BinaryCasReader.java
[3] 
https://code.google.com/p/dkpro-core-asl/source/browse/de.tudarmstadt.ukp.dkpro.core-asl/trunk/de.tudarmstadt.ukp.dkpro.core.io.bincas-asl/src/main/java/de/tudarmstadt/ukp/dkpro/core/io/bincas/BinaryCasWriter.java

On 19.05.2014, at 11:03, Ofer Bronstein <[email protected]> wrote:

> Hi Guys,
> 
> I am an Israeli Master's Student, and have been happily working with UIMA
> for the past two years.
> I hope this is the right place for my question -
> 
> I have a Document object I created, which has a JCas member with
> annotations over a document.
> I also have a Sentence object, with a member referencing its Sentence
> Annotation in the corresponding JCas. Each Document object references all
> of its Sentence objects.
> I would like to dump each Document object as a file on disk, using the
> default Java serialization. Later they would also be deserialized back into
> the Java objects. I understand I would need some special treatment for the
> JCases and the Sentence Annotations as they are not serializable (now I get
> NotSerializableException). Hopefully the treatment could be as minimal as
> possible.
> 
> How do you suggest to do this, regarding serialization of JCas and
> combining it with Java serialization?
> 
> I am working on Windows, with Java 1.6 and UIMA 2.4.0. I am using the same
> type system and the same 3 views for all JCases and annotations.
> 
> Thank you,
> Ofer Bronstein

Reply via email to