|
From: <joh...@us...> - 2011-06-29 19:37:23
|
Revision: 14100
http://gate.svn.sourceforge.net/gate/?rev=14100&view=rev
Author: johann_p
Date: 2011-06-29 19:37:17 +0000 (Wed, 29 Jun 2011)
Log Message:
-----------
Add isPREnabled() to the ActionContext and implement the behavior for
JAPE and JAPE_Plus.
Modified Paths:
--------------
gate/trunk/plugins/JAPE_Plus/src/gate/jape/plus/Transducer.java
gate/trunk/src/gate/creole/Transducer.java
gate/trunk/src/gate/jape/ActionContext.java
gate/trunk/src/gate/jape/DefaultActionContext.java
Modified: gate/trunk/plugins/JAPE_Plus/src/gate/jape/plus/Transducer.java
===================================================================
--- gate/trunk/plugins/JAPE_Plus/src/gate/jape/plus/Transducer.java 2011-06-29 19:07:53 UTC (rev 14099)
+++ gate/trunk/plugins/JAPE_Plus/src/gate/jape/plus/Transducer.java 2011-06-29 19:37:17 UTC (rev 14100)
@@ -253,6 +253,7 @@
aSpt.setOutputASName(outputASName);
aSpt.setOwner(this);
actionContext.setCorpus(corpus);
+ actionContext.setPR(this);
actionContext.setPRFeatures(features);
aSpt.setActionContext(actionContext);
aSpt.setOntology(ontology);
@@ -365,6 +366,7 @@
actionContext.setCorpus(corpus);
actionContext.setPRFeatures(features);
actionContext.setPRName(this.getName());
+ actionContext.setPR(this);
for(SPTBase aSpt : singlePhaseTransducers){
aSpt.runControllerExecutionStartedBlock(actionContext,c,ontology);
}
@@ -380,6 +382,7 @@
}
actionContext.setCorpus(null);
actionContext.setController(null);
+ actionContext.setPR(null);
}
@Override
@@ -392,6 +395,7 @@
}
actionContext.setCorpus(null);
actionContext.setController(null);
+ actionContext.setPR(null);
}
Modified: gate/trunk/src/gate/creole/Transducer.java
===================================================================
--- gate/trunk/src/gate/creole/Transducer.java 2011-06-29 19:07:53 UTC (rev 14099)
+++ gate/trunk/src/gate/creole/Transducer.java 2011-06-29 19:37:17 UTC (rev 14100)
@@ -144,6 +144,7 @@
// the current PR features and the corpus, if present
actionContext.setCorpus(corpus);
actionContext.setPRFeatures(features);
+ actionContext.setPR(this);
try {
batch.transduce(document, inputASName == null
? document.getAnnotations()
@@ -560,6 +561,7 @@
actionContext.setCorpus(corpus);
actionContext.setPRFeatures(features);
actionContext.setPRName(this.getName());
+ actionContext.setPR(this);
batch.runControllerExecutionStartedBlock(actionContext,c,ontology);
}
@@ -568,6 +570,7 @@
batch.runControllerExecutionFinishedBlock(actionContext,c,ontology);
actionContext.setCorpus(null);
actionContext.setController(null);
+ actionContext.setPR(null);
}
public void controllerExecutionAborted(Controller c, Throwable t)
@@ -575,6 +578,7 @@
batch.runControllerExecutionAbortedBlock(actionContext,c,t,ontology);
actionContext.setCorpus(null);
actionContext.setController(null);
+ actionContext.setPR(null);
}
Modified: gate/trunk/src/gate/jape/ActionContext.java
===================================================================
--- gate/trunk/src/gate/jape/ActionContext.java 2011-06-29 19:07:53 UTC (rev 14099)
+++ gate/trunk/src/gate/jape/ActionContext.java 2011-06-29 19:37:17 UTC (rev 14100)
@@ -53,6 +53,18 @@
*/
public String getPRName();
+ /**
+ * Returns true if the PR this transducer is running in has a chance to
+ * be run at all in its controller. This can be false if the PR is set
+ * to never run in a conditional controller. In such a case any controllerStarted,
+ * and controllerFinished blocks of the JAPE grammer are still run when
+ * the controller is starting or finishing. This method can be used in the
+ * controllerStarted or controllerFinished blocks to prevent any unwanted
+ * processing if the PR is disabled.
+ *
+ * @return
+ */
+ public boolean isPREnabled();
public Controller getController();
/**
Modified: gate/trunk/src/gate/jape/DefaultActionContext.java
===================================================================
--- gate/trunk/src/gate/jape/DefaultActionContext.java 2011-06-29 19:07:53 UTC (rev 14099)
+++ gate/trunk/src/gate/jape/DefaultActionContext.java 2011-06-29 19:37:17 UTC (rev 14100)
@@ -18,6 +18,7 @@
import gate.Controller;
import gate.Corpus;
import gate.FeatureMap;
+import gate.ProcessingResource;
/**
* Default implementation for an action context.<br>
@@ -34,6 +35,7 @@
protected Controller controller;
protected boolean endPhaseSupported;
protected boolean phaseEnded = false;
+ protected ProcessingResource pr;
public DefaultActionContext() {}
@@ -48,6 +50,10 @@
this.prname = name;
}
+ public void setPR(ProcessingResource pr) {
+ this.pr = pr;
+ }
+
public Corpus getCorpus() {
return corpus;
}
@@ -85,5 +91,9 @@
public void setPhaseEnded(boolean isended) {
phaseEnded = isended;
}
+
+ public boolean isPREnabled() {
+ return gate.Utils.isEnabled(controller, pr);
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|