You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@uima.apache.org by Frank <fr...@gmail.com> on 2010/11/10 03:49:00 UTC

Opening a Cas.xmi file and using it to create a CAS object

Hi,

I am currently trying to load CAS xmi files and create CAS objects, but I
can't see how to do it.

I have looked at the CASCreationUtils methods, but these all require CAS
objects to be created first, and there is my problem. I am not able to
create an empty CAS object.

I have looked into doing
 "CAS cas = (CAS) mUimaContext.getEmptyCas(CAS.class);"
but I am not sure if I am setting up the UIMAContext properly, since I get
null pointer exceptions

I assume the end point would be to use the XMIDeserializer, once I have a
CAS object created. Like..
FileInputStream inputCasStream = new FileInputStream(inputCasFile);
XmiCasDeserializer.deserialize(inputCasStream, cas);

Can you point me in the right direction.....?

Thank you,
Frank,

P.S...
The UIMA annotation viewer ( org.apache.uima.tools.AnnotationViewerMain )
from the uimaj-examples project  is able to open these CAS files, along with
the TypeSystem description file, and we are able to view the annotations
there with no problem. So, I assume the cas files are ok.


Here is something else that I tried, that did not work for me....
         XMLInputSource xmlInput = new XMLInputSource(inputTypeSystemFile);
         //get the type system descriptor from the file
         TypeSystemDescription typeSystemDescriptor =
UIMAFramework.getXMLParser()
               .parseTypeSystemDescription(xmlInput);
         //create a cas manager
        CASMgr casMgr = CASFactory.createCAS();
         casMgr.initCASIndexes();
         //connect the casManager with the type system descriptor file
       CasCreationUtils.setupTypeSystem(casMgr, typeSystemDescriptor);
         //get the cas from the manager
        CAS aCas = casMgr.getCAS();

this also gives me null pointer exceptions....

Re: Opening a Cas.xmi file and using it to create a CAS object

Posted by Thilo Götz <tw...@gmx.de>.
Please check out the source code in the annotation
viewer or CVD.  For CVD, the relevant code is in
TypeSystemFileOpenEventHandler and MainFrame.loadXmiFile()
(in the uimaj-tools project).
You should have no trouble adapting this to your
case.

--Thilo

On 11/10/2010 03:49, Frank wrote:
> Hi,
> 
> I am currently trying to load CAS xmi files and create CAS objects, but I
> can't see how to do it.
> 
> I have looked at the CASCreationUtils methods, but these all require CAS
> objects to be created first, and there is my problem. I am not able to
> create an empty CAS object.
> 
> I have looked into doing
>  "CAS cas = (CAS) mUimaContext.getEmptyCas(CAS.class);"
> but I am not sure if I am setting up the UIMAContext properly, since I get
> null pointer exceptions
> 
> I assume the end point would be to use the XMIDeserializer, once I have a
> CAS object created. Like..
> FileInputStream inputCasStream = new FileInputStream(inputCasFile);
> XmiCasDeserializer.deserialize(inputCasStream, cas);
> 
> Can you point me in the right direction.....?
> 
> Thank you,
> Frank,
> 
> P.S...
> The UIMA annotation viewer ( org.apache.uima.tools.AnnotationViewerMain )
> from the uimaj-examples project  is able to open these CAS files, along with
> the TypeSystem description file, and we are able to view the annotations
> there with no problem. So, I assume the cas files are ok.
> 
> 
> Here is something else that I tried, that did not work for me....
>          XMLInputSource xmlInput = new XMLInputSource(inputTypeSystemFile);
>          //get the type system descriptor from the file
>          TypeSystemDescription typeSystemDescriptor =
> UIMAFramework.getXMLParser()
>                .parseTypeSystemDescription(xmlInput);
>          //create a cas manager
>         CASMgr casMgr = CASFactory.createCAS();
>          casMgr.initCASIndexes();
>          //connect the casManager with the type system descriptor file
>        CasCreationUtils.setupTypeSystem(casMgr, typeSystemDescriptor);
>          //get the cas from the manager
>         CAS aCas = casMgr.getCAS();
> 
> this also gives me null pointer exceptions....
> 

Re: Opening a Cas.xmi file and using it to create a CAS object

Posted by Frank <fr...@gmail.com>.
Timur,

Here is what I did to load an existing cas from its cas.xmi file, also using
its Type Description file.

         //get typeSystemDescription
         Object descriptor = UIMAFramework.getXMLParser().parse(new
XMLInputSource(inputTypeSystemFile));
         // instantiate CAS to get type system. Also build style. map file
if there is none.
         TypeSystemDescription tsDesc = (TypeSystemDescription) descriptor;
         tsDesc.resolveImports();
         CAS cas = CasCreationUtils.createCas(tsDesc, null, new
FsIndexDescription[0]);

         SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
         XmiCasDeserializer xmiCasDeserializer = new
XmiCasDeserializer(cas.getTypeSystem());
         parser.parse(inputCasFile, xmiCasDeserializer.getXmiCasHandler(cas,
true));

Frank,

On Sun, Dec 19, 2010 at 1:21 PM, Timur <ac...@gmail.com> wrote:

> Frank <fr...@...> writes:
>
> >
> > Hi,
> >
> > I am currently trying to load CAS xmi files and create CAS objects, but I
> > can't see how to do it.
>
>
>
> Have you managed to work it out?
>
> I am trying to do exact the same thing, and i dont have any luck neither.
>
>

Re: Opening a Cas.xmi file and using it to create a CAS object

Posted by Burn Lewis <bu...@gmail.com>.
This can be done with the XmiCollectionReader in the examples folder.  You
may just need to modify its descriptor to address your input files, or you
can copy the deserialization code from
examples/src/org/apache/uima/examples/xmi

~Burn

Re: Opening a Cas.xmi file and using it to create a CAS object

Posted by Timur <ac...@gmail.com>.
Frank <fr...@...> writes:

> 
> Hi,
> 
> I am currently trying to load CAS xmi files and create CAS objects, but I
> can't see how to do it.



Have you managed to work it out?

I am trying to do exact the same thing, and i dont have any luck neither.