Return-Path: Delivered-To: apmail-uima-commits-archive@www.apache.org Received: (qmail 86552 invoked from network); 11 Sep 2010 14:36:55 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 11 Sep 2010 14:36:55 -0000 Received: (qmail 72064 invoked by uid 500); 11 Sep 2010 14:36:55 -0000 Delivered-To: apmail-uima-commits-archive@uima.apache.org Received: (qmail 72033 invoked by uid 500); 11 Sep 2010 14:36:53 -0000 Mailing-List: contact commits-help@uima.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@uima.apache.org Delivered-To: mailing list commits@uima.apache.org Received: (qmail 72023 invoked by uid 99); 11 Sep 2010 14:36:51 -0000 Received: from Unknown (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 11 Sep 2010 14:36:51 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 11 Sep 2010 14:36:33 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 657C723888FE; Sat, 11 Sep 2010 14:36:12 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r996150 - in /uima/sandbox/trunk/AlchemyAPIAnnotator: desc/ src/main/java/org/apache/uima/alchemy/mapper/ src/main/java/org/apache/uima/alchemy/mapper/processor/ Date: Sat, 11 Sep 2010 14:36:12 -0000 To: commits@uima.apache.org From: tommaso@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100911143612.657C723888FE@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: tommaso Date: Sat Sep 11 14:36:11 2010 New Revision: 996150 URL: http://svn.apache.org/viewvc?rev=996150&view=rev Log: [UIMA-1863] - added reverse building of annotations in RankedEntitiesProcessor Added: uima/sandbox/trunk/AlchemyAPIAnnotator/desc/baseAlchemyTypeSystemDescriptor.xml Modified: uima/sandbox/trunk/AlchemyAPIAnnotator/desc/TextRankedEntityExtractionAEDescriptor.xml uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/mapper/Alchemy2TypeSystemMapper.java uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/mapper/processor/RankedEntitiesProcessor.java Modified: uima/sandbox/trunk/AlchemyAPIAnnotator/desc/TextRankedEntityExtractionAEDescriptor.xml URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/AlchemyAPIAnnotator/desc/TextRankedEntityExtractionAEDescriptor.xml?rev=996150&r1=996149&r2=996150&view=diff ============================================================================== --- uima/sandbox/trunk/AlchemyAPIAnnotator/desc/TextRankedEntityExtractionAEDescriptor.xml (original) +++ uima/sandbox/trunk/AlchemyAPIAnnotator/desc/TextRankedEntityExtractionAEDescriptor.xml Sat Sep 11 14:36:11 2010 @@ -129,6 +129,9 @@ + + + org.apache.uima.alchemy.ts.entity.Anniversary Added: uima/sandbox/trunk/AlchemyAPIAnnotator/desc/baseAlchemyTypeSystemDescriptor.xml URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/AlchemyAPIAnnotator/desc/baseAlchemyTypeSystemDescriptor.xml?rev=996150&view=auto ============================================================================== --- uima/sandbox/trunk/AlchemyAPIAnnotator/desc/baseAlchemyTypeSystemDescriptor.xml (added) +++ uima/sandbox/trunk/AlchemyAPIAnnotator/desc/baseAlchemyTypeSystemDescriptor.xml Sat Sep 11 14:36:11 2010 @@ -0,0 +1,41 @@ + + + + baseAlchemyTypeSystemDescriptor + + 1.0 + + + + org.apache.uima.alchemy.ts.entity.AlchemyAnnotation + + uima.tcas.Annotation + + + alchemyType + alchemyAPI type + uima.cas.String + + + + + Modified: uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/mapper/Alchemy2TypeSystemMapper.java URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/mapper/Alchemy2TypeSystemMapper.java?rev=996150&r1=996149&r2=996150&view=diff ============================================================================== --- uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/mapper/Alchemy2TypeSystemMapper.java (original) +++ uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/mapper/Alchemy2TypeSystemMapper.java Sat Sep 11 14:36:11 2010 @@ -45,8 +45,8 @@ public class Alchemy2TypeSystemMapper { private static Map, AlchemyOutputProcessor> processors = new HashMap, AlchemyOutputProcessor>(); public static void mapResultsToTypeSystem(Results results, JCas aJCas) throws MappingException { - setLanaguage(results, aJCas); try { + setLanaguage(results, aJCas); if (processors.isEmpty()) initializeProcessors(); processors.get(results.getClass()).process(aJCas, results); Modified: uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/mapper/processor/RankedEntitiesProcessor.java URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/mapper/processor/RankedEntitiesProcessor.java?rev=996150&r1=996149&r2=996150&view=diff ============================================================================== --- uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/mapper/processor/RankedEntitiesProcessor.java (original) +++ uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/mapper/processor/RankedEntitiesProcessor.java Sat Sep 11 14:36:11 2010 @@ -21,9 +21,12 @@ package org.apache.uima.alchemy.mapper.p import org.apache.uima.alchemy.digester.domain.EntitiesResults; import org.apache.uima.alchemy.digester.domain.Entity; import org.apache.uima.alchemy.digester.domain.Results; +import org.apache.uima.alchemy.ts.entity.AlchemyAnnotation; +import org.apache.uima.alchemy.ts.entity.BaseEntity; import org.apache.uima.cas.FeatureStructure; import org.apache.uima.cas.Type; import org.apache.uima.jcas.JCas; +import org.apache.uima.jcas.cas.NonEmptyFSList; import org.apache.uima.jcas.cas.StringArray; public class RankedEntitiesProcessor implements AlchemyOutputProcessor { @@ -86,22 +89,50 @@ public class RankedEntitiesProcessor imp fs.setFeatureValue(type.getFeatureByBaseName("quotations"), quotationsFeatureStructure); } cas.addFsToIndexes(fs); + /* build annotations on this fs */ + buildAnnotations(cas, (BaseEntity) fs); } } } - private static FeatureStructure getFeatureStructure(String type, JCas aJCas) { - FeatureStructure fsObject = null; + /* reverse build annotations from entities */ + private void buildAnnotations(JCas cas, BaseEntity fs) { + Type type = fs.getType(); + String entityText = fs.getStringValue(type.getFeatureByBaseName("text")); + int annotationStart = cas.getDocumentText().indexOf(entityText); + if (annotationStart > 0) { + // create annotation + AlchemyAnnotation alchemyAnnotation = new AlchemyAnnotation(cas, annotationStart, entityText + .length()); + alchemyAnnotation.setAlchemyType(fs.getType().toString()); + alchemyAnnotation.addToIndexes(); + // update entity occurrences + NonEmptyFSList list = (NonEmptyFSList) fs.getOccurrences(); + if (list!=null) { + NonEmptyFSList newTail = new NonEmptyFSList(cas); + newTail.setHead(list.getHead()); + newTail.setTail(list.getTail()); + } + else { + list = new NonEmptyFSList(cas); + } + list.setHead(alchemyAnnotation); + } + + } + + private BaseEntity getFeatureStructure(String type, JCas aJCas) { + BaseEntity fsObject = null; String typeName = new StringBuilder(ENTITY_PACKAGE_NAME).append(type).toString(); Class typeClass = getClassFromName(typeName); if (typeClass != null) { try { /* usually jcas gen creates the constructor with jcas argument as the second one */ - fsObject = (FeatureStructure) typeClass.getConstructors()[1].newInstance(aJCas); + fsObject = (BaseEntity) typeClass.getConstructors()[1].newInstance(aJCas); } catch (Exception e) { /* for exceptional cases in which jcas parameter constructor is the first */ try { - fsObject = (FeatureStructure) typeClass.getConstructors()[0].newInstance(aJCas); + fsObject = (BaseEntity) typeClass.getConstructors()[0].newInstance(aJCas); } catch (Exception inner) { /* could not instantiate a FS via reflection */ inner.printStackTrace(); @@ -111,7 +142,7 @@ public class RankedEntitiesProcessor imp return fsObject; } - private static Class getClassFromName(String typeName) { + private Class getClassFromName(String typeName) { Class toReturn = null; try { toReturn = Class.forName(typeName);