Author: pkluegl
Date: Thu Jan 12 13:45:58 2012
New Revision: 1230537

URL: http://svn.apache.org/viewvc?rev=1230537&view=rev
Log:
UIMA-2233
only add inference annotations if there are none yet. They will be initialized 
anyway. Let seeder return their seeding type in order to be able to remove the 
seeding annotations with the inference annotations if needed.

Modified:
    
uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/TextMarkerStream.java
    
uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/engine/TextMarkerEngine.java
    
uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/seed/DefaultSeeder.java
    
uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/seed/TextMarkerAnnotationSeeder.java

Modified: 
uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/TextMarkerStream.java
URL: 
http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/TextMarkerStream.java?rev=1230537&r1=1230536&r2=1230537&view=diff
==============================================================================
--- 
uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/TextMarkerStream.java
 (original)
+++ 
uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/TextMarkerStream.java
 Thu Jan 12 13:45:58 2012
@@ -132,20 +132,23 @@ public class TextMarkerStream extends FS
   }
 
   public void initalizeBasics() {
+    AnnotationIndex<AnnotationFS> basicIndex = 
cas.getAnnotationIndex(basicType);
     AnnotationIndex<AnnotationFS> annotationIndex = cas.getAnnotationIndex();
-    TreeSet<Integer> anchors = new TreeSet<Integer>();
-    for (AnnotationFS a : annotationIndex) {
-      anchors.add(a.getBegin());
-      anchors.add(a.getEnd());
-    }
-    while (anchors.size() >= 2) {
-      Integer first = anchors.pollFirst();
-      Integer second = anchors.first();
-      TextMarkerBasic newTMB = new TextMarkerBasic(getJCas(), first, second);
-      beginAnchors.put(first, newTMB);
-      endAnchors.put(second, newTMB);
-      basics.add(newTMB);
-      cas.addFsToIndexes(newTMB);
+    if (basicIndex.size() == 0) {
+      TreeSet<Integer> anchors = new TreeSet<Integer>();
+      for (AnnotationFS a : annotationIndex) {
+        anchors.add(a.getBegin());
+        anchors.add(a.getEnd());
+      }
+      while (anchors.size() >= 2) {
+        Integer first = anchors.pollFirst();
+        Integer second = anchors.first();
+        TextMarkerBasic newTMB = new TextMarkerBasic(getJCas(), first, second);
+        beginAnchors.put(first, newTMB);
+        endAnchors.put(second, newTMB);
+        basics.add(newTMB);
+        cas.addFsToIndexes(newTMB);
+      }
     }
     for (AnnotationFS a : annotationIndex) {
       if (!a.getType().equals(basicType)) {

Modified: 
uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/engine/TextMarkerEngine.java
URL: 
http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/engine/TextMarkerEngine.java?rev=1230537&r1=1230536&r2=1230537&view=diff
==============================================================================
--- 
uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/engine/TextMarkerEngine.java
 (original)
+++ 
uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/engine/TextMarkerEngine.java
 Thu Jan 12 13:45:58 2012
@@ -39,7 +39,6 @@ import org.apache.uima.analysis_componen
 import org.apache.uima.analysis_engine.AnalysisEngine;
 import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
 import org.apache.uima.cas.CAS;
-import org.apache.uima.cas.FSIterator;
 import org.apache.uima.cas.Feature;
 import org.apache.uima.cas.Type;
 import org.apache.uima.cas.TypeSystem;
@@ -168,7 +167,7 @@ public class TextMarkerEngine extends JC
 
   private boolean initialized = false;
 
-
+  private List<Type> seedTypes;
 
   @Override
   public void initialize(UimaContext aContext) throws 
ResourceInitializationException {
@@ -259,12 +258,16 @@ public class TextMarkerEngine extends JC
 
     if (removeBasics) {
       List<AnnotationFS> toRemove = new ArrayList<AnnotationFS>();
-      Type type = cas.getTypeSystem().getType(BASIC_TYPE);
-      FSIterator<AnnotationFS> iterator = 
cas.getAnnotationIndex(type).iterator();
-      while (iterator.isValid()) {
-        AnnotationFS fs = iterator.get();
+      Type basicType = cas.getTypeSystem().getType(BASIC_TYPE);
+      AnnotationIndex<AnnotationFS> basicIndex = 
cas.getAnnotationIndex(basicType);
+      for (AnnotationFS fs : basicIndex) {
         toRemove.add(fs);
-        iterator.moveToNext();
+      }
+      for (Type seedType : seedTypes) {
+        AnnotationIndex<AnnotationFS> seedIndex = 
cas.getAnnotationIndex(seedType);
+        for (AnnotationFS fs : seedIndex) {
+          toRemove.add(fs);
+        }
       }
       for (AnnotationFS annotationFS : toRemove) {
         cas.removeFsFromIndexes(annotationFS);
@@ -374,37 +377,39 @@ public class TextMarkerEngine extends JC
     }
     FilterManager filter = new FilterManager(filterTypes, cas);
     Type basicType = typeSystem.getType(BASIC_TYPE);
-    seedAnnotations(cas);
+    seedTypes = seedAnnotations(cas);
     TextMarkerStream stream = new TextMarkerStream(cas, basicType, filter);
     stream.initalizeBasics();
     return stream;
   }
 
-  private void seedAnnotations(CAS cas) throws AnalysisEngineProcessException {
+  private List<Type> seedAnnotations(CAS cas) throws 
AnalysisEngineProcessException {
+    List<Type> result = new ArrayList<Type>();
     if (seeders != null) {
-        for (String seederClass : seeders) {
-          Class<?> loadClass = null;
-          try {
-            loadClass = Class.forName(seederClass);
-          } catch (ClassNotFoundException e) {
-            throw new AnalysisEngineProcessException(e);
-          }
-          Object newInstance = null;
-          try {
-            newInstance = loadClass.newInstance();
-          } catch (Exception e) {
-            throw new AnalysisEngineProcessException(e);
-          }
-          try {
-            TextMarkerAnnotationSeeder seeder = (TextMarkerAnnotationSeeder) 
newInstance;
-            seeder.seed(cas.getDocumentText(), cas);
-          } catch (Exception e) {
-            throw new AnalysisEngineProcessException(e);
-          }
+      for (String seederClass : seeders) {
+        Class<?> loadClass = null;
+        try {
+          loadClass = Class.forName(seederClass);
+        } catch (ClassNotFoundException e) {
+          throw new AnalysisEngineProcessException(e);
         }
+        Object newInstance = null;
+        try {
+          newInstance = loadClass.newInstance();
+        } catch (Exception e) {
+          throw new AnalysisEngineProcessException(e);
+        }
+        try {
+          TextMarkerAnnotationSeeder seeder = (TextMarkerAnnotationSeeder) 
newInstance;
+          result.add(seeder.seed(cas.getDocumentText(), cas));
+        } catch (Exception e) {
+          throw new AnalysisEngineProcessException(e);
+        }
+      }
     }
+    return result;
   }
-  
+
   private void initializeScript() throws AnalysisEngineProcessException {
     String scriptLocation = locate(mainScript, scriptPaths, ".tm");
     if (scriptLocation == null) {

Modified: 
uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/seed/DefaultSeeder.java
URL: 
http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/seed/DefaultSeeder.java?rev=1230537&r1=1230536&r2=1230537&view=diff
==============================================================================
--- 
uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/seed/DefaultSeeder.java
 (original)
+++ 
uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/seed/DefaultSeeder.java
 Thu Jan 12 13:45:58 2012
@@ -24,23 +24,28 @@ import java.io.StringReader;
 
 import org.apache.uima.cas.CAS;
 import org.apache.uima.cas.CASException;
+import org.apache.uima.cas.Type;
 import org.apache.uima.cas.text.AnnotationFS;
 import org.apache.uima.jcas.JCas;
 import org.apache.uima.textmarker.type.TokenSeed;
 
 public class DefaultSeeder implements TextMarkerAnnotationSeeder {
 
-  public void seed(String text, CAS cas) {
+  public static final String seedType =  
"org.apache.uima.textmarker.type.TokenSeed";
+  
+  public Type seed(String text, CAS cas) {
+    Type result = null;
     JCas jCas = null;
     int size = 0;
     try {
       jCas = cas.getJCas();
       size = jCas.getAnnotationIndex(TokenSeed.type).size();
+      result =  jCas.getTypeSystem().getType(seedType);
     } catch (CASException e1) {
     }
     // do not apply seeding if there are already annotations of this seed type
     if (jCas == null || size != 0) {
-      return;
+      return result;
     }
     BufferedReader reader = new BufferedReader(new StringReader(text));
     final SeedLexer sourceLexer = new SeedLexer(reader);
@@ -58,5 +63,6 @@ public class DefaultSeeder implements Te
       } catch (Exception e) {
       }
     }
+    return result;
   }
 }

Modified: 
uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/seed/TextMarkerAnnotationSeeder.java
URL: 
http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/seed/TextMarkerAnnotationSeeder.java?rev=1230537&r1=1230536&r2=1230537&view=diff
==============================================================================
--- 
uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/seed/TextMarkerAnnotationSeeder.java
 (original)
+++ 
uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/seed/TextMarkerAnnotationSeeder.java
 Thu Jan 12 13:45:58 2012
@@ -20,10 +20,11 @@
 package org.apache.uima.textmarker.seed;
 
 import org.apache.uima.cas.CAS;
+import org.apache.uima.cas.Type;
 
 
 public interface TextMarkerAnnotationSeeder {
 
-  void seed(String text, CAS cas);
+  Type seed(String text, CAS cas);
 
 }


Reply via email to