From user-return-7996-archive-asf-public=cust-asf.ponee.io@uima.apache.org Tue Oct 16 09:45:43 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 3222A180649 for ; Tue, 16 Oct 2018 09:45:43 +0200 (CEST) Received: (qmail 97002 invoked by uid 500); 16 Oct 2018 07:45:42 -0000 Mailing-List: contact user-help@uima.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@uima.apache.org Delivered-To: mailing list user@uima.apache.org Received: (qmail 96985 invoked by uid 99); 16 Oct 2018 07:45:41 -0000 Received: from mail-relay.apache.org (HELO mailrelay2-lw-us.apache.org) (207.244.88.137) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 16 Oct 2018 07:45:41 +0000 Received: from [192.168.0.249] (ip-95-222-212-88.hsi15.unitymediagroup.de [95.222.212.88]) by mailrelay2-lw-us.apache.org (ASF Mail Server at mailrelay2-lw-us.apache.org) with ESMTPSA id 058E4A3C; Tue, 16 Oct 2018 07:45:40 +0000 (UTC) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 11.5 \(3445.9.1\)) Subject: Re: JCasGen like utility for generating POJO Classes in the type system From: Richard Eckart de Castilho In-Reply-To: Date: Tue, 16 Oct 2018 09:45:39 +0200 Content-Transfer-Encoding: quoted-printable Message-Id: <976FA33C-BC13-4E94-9D1C-1A76F3FD700A@apache.org> References: To: user@uima.apache.org X-Mailer: Apple Mail (2.3445.9.1) On 14. Oct 2018, at 00:31, Amit Paradkar wrote: >=20 > Thanks Marshall. > I would like to construct objects in the typesystem that I have = defined > without having to pass in a cas object in the constructor (after I = have > detected features for a particular class in the text) >=20 > e.g, I have a Database type defined in my UIMA type descriptor based = on > which JCasGen generates a JCas cover class called named Databaase. > But all the public constructors in this class take a JCas object as an > argument which precludes an independent construction of instances of = these > classes. > I need to be able to construct an instance of such classes independent = of > any cas objects - since I need them to persist even after the the = current > input text is being processed completely. So, almost a mirror = typesystem is > desired. Perhaps I am not using the notion of typesystem = appropriately... JCas cover classes are bound to a (J)CAS because. One simple reason is = that annotations do not contain the covered text themselves but need to query = the underlying (J)CAS to fetch a substring of the document text based on = their respective start/end positions. Also, (J)CAS objects are often re-used. So retaining a JCas cover class = instance or a FeatureStructure for a longer period of time is usually a bad idea. If you need to persist data, you could: * store the entire (J)CAS including the text an all annotations - e.g. = in XMI or binary format or even JSON. You can then later create an empty CAS and load the data = back in (except the=20 JSON format for which we do not yet have code to load the data back). * iterate only over those annotations in the CAS interesting to you, = create a generic POJO (e.g. a kind of Map), copy all relevant information from the = annotation over into the POJO and then persist that. In order to do this, you might want to use the = CAS API which allows=20 not only iterating over annotations, but also over their features. * you *could* also use the POJO approch with JCas, create one POJO class = for every JCas class that you have, and then copy the information from the = annotations over into your POJO classes. But I believe in this case you'd have to write a lot of = copy code and you'd have to adapt that code every time your type system changes. Of = course, you could use the Java reflection API to make the code more generic (e.g. by getting = a list of=20 getters/setters on the JCas classes), but then you could also just use = the CAS API and get the same effect with simpler and faster code. Cheers, -- Richard=