uima-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alain D├ęsilets <alaindesile...@gmail.com>
Subject Re: Is it possible to define dynamically typed annotations?
Date Sun, 16 Dec 2018 00:56:13 GMT
I am not sure I understand what you wrote. Although I have been using UIMA
for 2 years now, I am still baffled by it most of the time ;-).

It SOUNDS like you are saying that it's possible to add new types in the
XML typesystem file, and tell a RUNNING application to reload the XML file
without having to recompile that application. Is that correct?

If so, I don't see a need for Dynamically typed annotations after all.


On Sat, Dec 15, 2018 at 5:40 PM Richard Eckart de Castilho <rec@apache.org>
wrote:

> Hi folks
>
> > On 15. Dec 2018, at 13:41, Nicolas Paris <nicolas.paris@riseup.net>
> wrote:
> >
> > On Sat, Dec 15, 2018 at 07:20:33AM -0500, Alain D├ęsilets wrote:
> >> Is it possible to create dynamically typed annotations in UIMA? In other
> >> words, would it be possible for users of my system to create a new type
> of
> >> annotation without having to recompile the Java code?
>
> My take on the problem is to redefine the CAS in-place. The following
> code is used by the WebAnno annotation editor to handle the case where
> the user modifies the type system:
>
> ---
>
>     /**
>      * Load the contents from the source CAS, upgrade it to the target
> type system and write the
>      * results to the target CAS. An in-place upgrade can be achieved by
> using the same CAS as
>      * source and target.
>      */
>     private void upgradeCas(CAS aSourceCas, CAS aTargetCas,
> TypeSystemDescription aTargetTypeSystem)
>         throws UIMAException, IOException
>     {
>         // Save source CAS type system (do this early since we might do an
> in-place upgrade)
>         TypeSystem sourceTypeSystem = aSourceCas.getTypeSystem();
>
>         // Save source CAS contents
>         ByteArrayOutputStream serializedCasContents = new
> ByteArrayOutputStream();
>         Serialization.serializeWithCompression(aSourceCas,
> serializedCasContents, sourceTypeSystem);
>
>         // Re-initialize the target CAS with new type system
>         CAS tempCas = JCasFactory.createJCas(aTargetTypeSystem).getCas();
>         CASCompleteSerializer serializer =
> Serialization.serializeCASComplete((CASImpl) tempCas);
>         Serialization.deserializeCASComplete(serializer, (CASImpl)
> aTargetCas);
>
>         // Leniently load the source CAS contents into the target CAS
>         CasIOUtils.load(new
> ByteArrayInputStream(serializedCasContents.toByteArray()), aTargetCas,
>                 sourceTypeSystem);
>
>         // Make sure JCas is properly initialized too
>         aTargetCas.getJCas();
>     }
>
> ---
>
> This procedure takes a bit so it shouldn't be done often and also it
> discards any non-reachable
> feature structures - but it works. It also discards any information that
> is not compatible with
> the target type system - within any limits that lenient CAS loading may
> impose.
>
> Basically you call it with
>
>           upgradeCas(aCas, aCas, aTargetTypeSystem);
>
> in order to perform an in-place upgrade of a singla CAS to the given type
> system.
>
> Cheers,
>
> -- Richard

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message