Revision: 18633
          http://sourceforge.net/p/gate/code/18633
Author:   markagreenwood
Date:     2015-04-13 12:23:47 +0000 (Mon, 13 Apr 2015)
Log Message:
-----------
rearranged the code slightly to make the use of embedded PRs cleaner, which 
includes making sure that in all cases, via finally blocks, the doc param of 
the PRs is set to null when we have finished otherwise we leak these references 
and the document can't be unloaded until the next document has been processed. 
for small docs this isn't an issue but for large ones it might be

Modified Paths:
--------------
    gate/trunk/src/main/gate/creole/splitter/SentenceSplitter.java

Modified: gate/trunk/src/main/gate/creole/splitter/SentenceSplitter.java
===================================================================
--- gate/trunk/src/main/gate/creole/splitter/SentenceSplitter.java      
2015-04-13 01:20:08 UTC (rev 18632)
+++ gate/trunk/src/main/gate/creole/splitter/SentenceSplitter.java      
2015-04-13 12:23:47 UTC (rev 18633)
@@ -139,55 +139,65 @@
     FeatureMap params;
     if(inputASName != null && inputASName.equals("")) inputASName = null;
     if(outputASName != null && outputASName.equals("")) outputASName = null;
-    try{
-      fireProgressChanged(0);
+    
+    ProgressListener pListener = null;
+    StatusListener sListener = null;
+
+    fireProgressChanged(5);
+    pListener = new IntervalProgressListener(5, 10);
+    sListener = new StatusListener() {
+      @Override
+      public void statusChanged(String text) {
+        fireStatusChanged(text);
+      }
+    };
+    try {
+      // run the gazetteer
       params = Factory.newFeatureMap();
       params.put(DefaultGazetteer.DEF_GAZ_DOCUMENT_PARAMETER_NAME, document);
       params.put(DefaultGazetteer.DEF_GAZ_ANNOT_SET_PARAMETER_NAME, 
inputASName);
       gazetteer.setParameterValues(params);
 
+      gazetteer.addProgressListener(pListener);
+      gazetteer.addStatusListener(sListener);
+      gazetteer.execute();
+
+    } catch(Exception e) {
+      throw new ExecutionException(e);
+    } finally {
+      gazetteer.setDocument(null);
+      gazetteer.removeProgressListener(pListener);
+      gazetteer.removeStatusListener(sListener);
+    }
+
+    if(isInterrupted())
+      throw new ExecutionInterruptedException("The execution of the \""
+              + getName()
+              + "\" sentence splitter has been abruptly interrupted!");
+
+    pListener = new IntervalProgressListener(11, 90);
+
+    try {
       params = Factory.newFeatureMap();
       params.put(Transducer.TRANSD_DOCUMENT_PARAMETER_NAME, document);
       params.put(Transducer.TRANSD_INPUT_AS_PARAMETER_NAME, inputASName);
       params.put(Transducer.TRANSD_OUTPUT_AS_PARAMETER_NAME, inputASName);
       transducer.setParameterValues(params);
-    }catch(Exception e){
+
+      transducer.addProgressListener(pListener);
+      transducer.addStatusListener(sListener);
+      Benchmark.executeWithBenchmarking(transducer,
+              Benchmark.createBenchmarkId("SentenceSplitterTransducer",
+                      getBenchmarkId()), this, null);
+
+    } catch(Exception e) {
       throw new ExecutionException(e);
+    } finally {
+      transducer.setDocument(null);
+      transducer.removeProgressListener(pListener);
+      transducer.removeStatusListener(sListener);
     }
-    ProgressListener pListener = null;
-    StatusListener sListener = null;
-    fireProgressChanged(5);
 
-    //run the gazetteer
-    if(isInterrupted()) throw new ExecutionInterruptedException(
-        "The execution of the \"" + getName() +
-        "\" sentence splitter has been abruptly interrupted!");
-    pListener = new IntervalProgressListener(5, 10);
-    sListener = new StatusListener(){
-      @Override
-      public void statusChanged(String text){
-        fireStatusChanged(text);
-      }
-    };
-    gazetteer.addProgressListener(pListener);
-    gazetteer.addStatusListener(sListener);
-    gazetteer.execute();
-    gazetteer.removeProgressListener(pListener);
-    gazetteer.removeStatusListener(sListener);
-
-    //run the transducer
-    if(isInterrupted()) throw new ExecutionInterruptedException(
-        "The execution of the \"" + getName() +
-        "\" sentence splitter has been abruptly interrupted!");
-    pListener = new IntervalProgressListener(11, 90);
-    transducer.addProgressListener(pListener);
-    transducer.addStatusListener(sListener);
-    Benchmark.executeWithBenchmarking(transducer,
-            Benchmark.createBenchmarkId("SentenceSplitterTransducer",
-                    getBenchmarkId()), this, null);
-    transducer.removeProgressListener(pListener);
-    transducer.removeStatusListener(sListener);
-
     //get pointers to the annotation sets
     AnnotationSet inputAS = (inputASName == null) ?
                             document.getAnnotations() :

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
BPM Camp - Free Virtual Workshop May 6th at 10am PDT/1PM EDT
Develop your own process in accordance with the BPMN 2 standard
Learn Process modeling best practices with Bonita BPM through live exercises
http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual- event?utm_
source=Sourceforge_BPM_Camp_5_6_15&utm_medium=email&utm_campaign=VA_SF
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs

Reply via email to