Return-Path: X-Original-To: apmail-uima-user-archive@www.apache.org Delivered-To: apmail-uima-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 23560100D5 for ; Fri, 12 Jul 2013 21:41:58 +0000 (UTC) Received: (qmail 52719 invoked by uid 500); 12 Jul 2013 21:41:57 -0000 Delivered-To: apmail-uima-user-archive@uima.apache.org Received: (qmail 52690 invoked by uid 500); 12 Jul 2013 21:41:57 -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 52682 invoked by uid 99); 12 Jul 2013 21:41:57 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 12 Jul 2013 21:41:57 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of cngo.textanalytics@gmail.com designates 209.85.220.194 as permitted sender) Received: from [209.85.220.194] (HELO mail-vc0-f194.google.com) (209.85.220.194) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 12 Jul 2013 21:41:52 +0000 Received: by mail-vc0-f194.google.com with SMTP id gf11so1689081vcb.5 for ; Fri, 12 Jul 2013 14:41:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=0QLb0zaNnz2LE4tlnEDBBSkg5X9vmgqz30a87nCQR1w=; b=lemfExFXQ+xMbQ/FJpn4PDXgfbexfWhjw9SXi71RwhugwGqYmSXIKg6z00Wm9lklk5 ufcmDLdpVd1+ULCSldEazSRBYUADHiKchDLW9kSwPn7bng7eqOhsWh2SY7wxrzz9ePsH VtA58nGPrvfNZFpKuHlilx89mbccRreimGInEydQLIMxpiYSERj/C3iRlIlPTnIEk0wV qETD/q79dNt4RqAf+cQBXUZoTcWBxTXvEOSeveE7YG9c9lEyOiETYTrDQbswgJhfUbK3 L99cG529UyBTNgMXK5zP2HQJHqQnjCwtTBSOe+L9UvLGpoHoT9TuOPs9WucVhxG7rF+D k3sA== MIME-Version: 1.0 X-Received: by 10.58.123.37 with SMTP id lx5mr24949055veb.67.1373665291886; Fri, 12 Jul 2013 14:41:31 -0700 (PDT) Received: by 10.220.49.210 with HTTP; Fri, 12 Jul 2013 14:41:31 -0700 (PDT) In-Reply-To: <0F926B8D-EEC1-4726-9217-6F13121E8DA9@gmail.com> References: <0F926B8D-EEC1-4726-9217-6F13121E8DA9@gmail.com> Date: Fri, 12 Jul 2013 17:41:31 -0400 Message-ID: Subject: Re: Getting all Features for any Annotator From: Chuong Ngo To: Uima Users Mailing List Content-Type: multipart/alternative; boundary=089e01184c3ec3686304e1575ff8 X-Virus-Checked: Checked by ClamAV on apache.org --089e01184c3ec3686304e1575ff8 Content-Type: text/plain; charset=ISO-8859-1 Alright, so if I understand correctly, what I need to do is something along the following: 1) Get the TypeSystem from the cas: TypeSystem typeSystem = cas.getTypeSystem 2) Get an iterator and iterate over the TypeSystem: Iterator itr = ts.getTypeIterator(); while(itr.hasNext()) { Type type = itr.next(); ... 3) For each type, retrieve the qualified name of the type and use it to retrieve all annotations of that type. Also grab the list of features for the type: List featureList = type.getFeatures(); AnnotationIndex indexAnn = cas.getAnnotationIndex(type); Iterator itrAnn = indexAnn.iterator(); while(itr.hasNext()) { FeatureStructure fs = (FeatureStructure) itrAnn.next(); ... 4) Iterate though the list of freatures extracted and pull out the feature name and values: for(Feature feature : featureList) { String featureName = feature.getShortName(); String featureValue = fs.getFeatureValueAsString(feature); ... On Fri, Jul 12, 2013 at 2:58 PM, Richard Eckart de Castilho < richard.eckart@gmail.com> wrote: > People tend to fall back to using Java Reflections on the JCas wrappers, > before using the lower-level UIMA interfaces (CAS and AnnotationFS/ > FeatureStructure). > > Every UIMA annotation implements the interface FeatureStructure. This > interface in conjunction with the type system information you can obtain > from the CAS, provides all you need to extract all information. > > There is no need to resort to reflection. > > You may want to have a look at the source code of the CasCopier class too. > > -- Richard > > Am 12.07.2013 um 20:16 schrieb Chuong Ngo : > > > Is there a way to get all the features for an annotator, no matter which > > one it is? > > > > For example, I want to convert all annotators I get back into a JSON > > respresenting that annotator. My annotators have different number and > > types of features. For example, a person may have firstName, lastName > > while an organization may have type, health, etc... Is there another way > > to do that besides casting each one to a predetermined type and then > using > > the getters to extract the feature values? Thanks in advance. > > > > Chuong Ngo > > --089e01184c3ec3686304e1575ff8--