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 @@
</nameValuePair>
</configurationParameterSettings>
<typeSystemDescription>
+ <imports>
+ <import location="baseAlchemyTypeSystemDescriptor.xml"/>
+ </imports>
<types>
<typeDescription>
<name>org.apache.uima.alchemy.ts.entity.Anniversary</name>
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 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+
+-->
+<typeSystemDescription xmlns="http://uima.apache.org/resourceSpecifier">
+ <name>baseAlchemyTypeSystemDescriptor</name>
+ <description/>
+ <version>1.0</version>
+ <vendor/>
+ <types>
+ <typeDescription>
+ <name>org.apache.uima.alchemy.ts.entity.AlchemyAnnotation</name>
+ <description/>
+ <supertypeName>uima.tcas.Annotation</supertypeName>
+ <features>
+ <featureDescription>
+ <name>alchemyType</name>
+ <description>alchemyAPI type</description>
+ <rangeTypeName>uima.cas.String</rangeTypeName>
+ </featureDescription>
+ </features>
+ </typeDescription>
+ </types>
+</typeSystemDescription>
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<Class<? extends Results>, AlchemyOutputProcessor>
processors = new HashMap<Class<? extends Results>, 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);