Revision: 17591
http://sourceforge.net/p/gate/code/17591
Author: markagreenwood
Date: 2014-03-08 08:39:58 +0000 (Sat, 08 Mar 2014)
Log Message:
-----------
fixed a resource leak in the coreferencer which never cleaned up the two JAPE
transducers it creates for doing pronominal coref
Modified Paths:
--------------
gate/trunk/src/main/gate/creole/coref/Coreferencer.java
gate/trunk/src/main/gate/creole/coref/PronominalCoref.java
Modified: gate/trunk/src/main/gate/creole/coref/Coreferencer.java
===================================================================
--- gate/trunk/src/main/gate/creole/coref/Coreferencer.java 2014-03-08
08:17:28 UTC (rev 17590)
+++ gate/trunk/src/main/gate/creole/coref/Coreferencer.java 2014-03-08
08:39:58 UTC (rev 17591)
@@ -71,12 +71,10 @@
@Override
public Resource init() throws ResourceInstantiationException {
- Resource result = super.init();
-
// load all submodules
- this.pronominalModule.init();
+ pronominalModule.init();
- return result;
+ return this;
} // init()
/**
@@ -101,6 +99,12 @@
this.pronominalModule.setDocument(newDocument);
super.setDocument(newDocument);
}
+
+ @Override
+ public void cleanup() {
+ super.cleanup();
+ pronominalModule.cleanup();
+ }
/** --- */
@RunTime
Modified: gate/trunk/src/main/gate/creole/coref/PronominalCoref.java
===================================================================
--- gate/trunk/src/main/gate/creole/coref/PronominalCoref.java 2014-03-08
08:17:28 UTC (rev 17590)
+++ gate/trunk/src/main/gate/creole/coref/PronominalCoref.java 2014-03-08
08:39:58 UTC (rev 17591)
@@ -19,9 +19,10 @@
import gate.Annotation;
import gate.AnnotationSet;
import gate.Document;
+import gate.Factory;
import gate.FeatureMap;
+import gate.Gate;
import gate.Node;
-import gate.ProcessingResource;
import gate.Resource;
import gate.creole.ANNIEConstants;
import gate.creole.AbstractLanguageAnalyser;
@@ -47,7 +48,7 @@
import java.util.Set;
public class PronominalCoref extends AbstractLanguageAnalyser
- implements ProcessingResource, ANNIEConstants,
+ implements ANNIEConstants,
Benchmarkable {
private static final long serialVersionUID = 3860815557386683264L;
@@ -114,36 +115,36 @@
PRP_RESTRICTION.put(TOKEN_CATEGORY_FEATURE_NAME,PRP_CATEGORY);
}
- /** --- */
- public PronominalCoref() {
-
- this.personGender = new HashMap<Annotation,String>();
- this.anaphor2antecedent = new HashMap<Annotation,Annotation>();
- this.inanimatedSet = new HashSet<String>();
-
- //TODO fix to do this properly
- this.qtTransducer = new gate.creole.Transducer();
- this.pleonTransducer = new gate.creole.Transducer();
- }
-
/** Initialise this resource, and return it. */
@Override
public Resource init() throws ResourceInstantiationException {
- //0. preconditions
- assert (null != this.qtTransducer);
-
+ personGender = new HashMap<Annotation,String>();
+ anaphor2antecedent = new HashMap<Annotation,Annotation>();
+ inanimatedSet = new HashSet<String>();
+
//1. initialise quoted text transducer
URL qtGrammarURL = null;
try {
qtGrammarURL = new URL(QT_GRAMMAR_URL);
- }
- catch(MalformedURLException mue) {
+ } catch(MalformedURLException mue) {
throw new ResourceInstantiationException(mue);
}
- this.qtTransducer.setGrammarURL(qtGrammarURL);
- this.qtTransducer.setEncoding("UTF-8");
- this.qtTransducer.init();
+ FeatureMap params = Factory.newFeatureMap();
+ params.put(Transducer.TRANSD_GRAMMAR_URL_PARAMETER_NAME, qtGrammarURL);
+ params.put(Transducer.TRANSD_ENCODING_PARAMETER_NAME, "UTF-8");
+ if (qtTransducer == null) {
+ features = Factory.newFeatureMap();
+ Gate.setHiddenAttribute(features, true);
+ qtTransducer =
(Transducer)Factory.createResource("gate.creole.Transducer",
+ params, features);
+ qtTransducer.setName("PronominalCoref-QT " + System.currentTimeMillis());
+ }
+ else {
+ qtTransducer.setParameterValues(params);
+ qtTransducer.reInit();
+ }
+
//2. initialise pleonastic transducer
URL pleonGrammarURL = null;
@@ -153,36 +154,31 @@
catch(MalformedURLException mue) {
throw new ResourceInstantiationException(mue);
}
- this.pleonTransducer.setGrammarURL(pleonGrammarURL);
- this.pleonTransducer.setEncoding("UTF-8");
- this.pleonTransducer.init();
-
+ params = Factory.newFeatureMap();
+ params.put(Transducer.TRANSD_GRAMMAR_URL_PARAMETER_NAME, pleonGrammarURL);
+ params.put(Transducer.TRANSD_ENCODING_PARAMETER_NAME, "UTF-8");
+ if (pleonTransducer == null) {
+ features = Factory.newFeatureMap();
+ Gate.setHiddenAttribute(features, true);
+ pleonTransducer =
(Transducer)Factory.createResource("gate.creole.Transducer",
+ params, features);
+ pleonTransducer.setName("PronominalCoref-Pleon " +
System.currentTimeMillis());
+ }
+ else {
+ pleonTransducer.setParameterValues(params);
+ pleonTransducer.reInit();
+ }
+
return this;
} // init()
- /**
- * Reinitialises the processing resource. After calling this method the
- * resource should be in the state it is after calling init.
- * If the resource depends on external resources (such as rules files) then
- * the resource will re-read those resources. If the data used to create
- * the resource has changed since the resource has been created then the
- * resource will change too after calling reInit().
- */
@Override
- public void reInit() throws ResourceInstantiationException {
+ public void cleanup() {
+ super.cleanup();
+ Factory.deleteResource(qtTransducer);
+ Factory.deleteResource(pleonTransducer);
+ }
- if (null != this.qtTransducer) {
- this.qtTransducer.reInit();
- }
-
- if (null != this.pleonTransducer) {
- this.pleonTransducer.reInit();
- }
-
- init();
- } // reInit()
-
-
/** Set the document to run on. */
@Override
public void setDocument(Document newDocument) {
@@ -191,8 +187,8 @@
// assert (null != newDocument);
//1. set doc for aggregated components
- this.qtTransducer.setDocument(newDocument);
- this.pleonTransducer.setDocument(newDocument);
+ qtTransducer.setDocument(newDocument);
+ pleonTransducer.setDocument(newDocument);
//3. delegate
super.setDocument(newDocument);
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Subversion Kills Productivity. Get off Subversion & Make the Move to Perforce.
With Perforce, you get hassle-free workflows. Merge that actually works.
Faster operations. Version large binaries. Built-in WAN optimization and the
freedom to use Git, Perforce or both. Make the move to Perforce.
http://pubads.g.doubleclick.net/gampad/clk?id=122218951&iu=/4140/ostg.clktrk
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs