Revision: 17800
          http://sourceforge.net/p/gate/code/17800
Author:   markagreenwood
Date:     2014-04-10 14:01:51 +0000 (Thu, 10 Apr 2014)
Log Message:
-----------
added a debug option to jape, via the ActionContext, which adds features 
addedByPR, addedByPhase, and addedByRule to every annotation instance created 
within that grammar

Modified Paths:
--------------
    gate/trunk/plugins/JAPE_Plus/src/gate/jape/plus/Transducer.java
    gate/trunk/src/main/gate/creole/Transducer.java
    gate/trunk/src/main/gate/jape/ActionContext.java
    gate/trunk/src/main/gate/jape/DefaultActionContext.java
    gate/trunk/src/main/gate/jape/RightHandSide.java

Modified: gate/trunk/plugins/JAPE_Plus/src/gate/jape/plus/Transducer.java
===================================================================
--- gate/trunk/plugins/JAPE_Plus/src/gate/jape/plus/Transducer.java     
2014-04-10 12:58:35 UTC (rev 17799)
+++ gate/trunk/plugins/JAPE_Plus/src/gate/jape/plus/Transducer.java     
2014-04-10 14:01:51 UTC (rev 17800)
@@ -352,8 +352,8 @@
    */
   protected List<String> annotationAccessors = null;
   
+  protected Boolean enableDebugging;
   
-  
   protected String encoding;
   
   protected String inputASName;
@@ -495,6 +495,16 @@
     this.annotationAccessors = annotationAccessors;
   }  
   
+  public Boolean getEnableDebugging() {
+    return enableDebugging;
+  }
+
+  @RunTime
+  @CreoleParameter(defaultValue = "false")
+  public void setEnableDebugging(Boolean enableDebugging) {
+    this.enableDebugging = enableDebugging;
+  }
+  
   public String getEncoding() {
     return encoding;
   }
@@ -920,6 +930,7 @@
     actionContext.setPRFeatures(features);
     actionContext.setPRName(this.getName());
     actionContext.setPR(this);
+    actionContext.setDebuggingEnabled(enableDebugging);
     for(SPTBase aSpt : singlePhaseTransducers){
       aSpt.runControllerExecutionStartedBlock(actionContext,c,ontology);
     }

Modified: gate/trunk/src/main/gate/creole/Transducer.java
===================================================================
--- gate/trunk/src/main/gate/creole/Transducer.java     2014-04-10 12:58:35 UTC 
(rev 17799)
+++ gate/trunk/src/main/gate/creole/Transducer.java     2014-04-10 14:01:51 UTC 
(rev 17800)
@@ -434,6 +434,8 @@
     return enableDebugging;
   }
 
+  @RunTime
+  @CreoleParameter(defaultValue = "false")
   public void setEnableDebugging(Boolean enableDebugging) {
     this.enableDebugging = enableDebugging;
   }
@@ -597,6 +599,7 @@
     actionContext.setPRFeatures(features);
     actionContext.setPRName(this.getName());
     actionContext.setPR(this);
+    actionContext.setDebuggingEnabled(enableDebugging);
     batch.runControllerExecutionStartedBlock(actionContext,c,ontology);
   }
 

Modified: gate/trunk/src/main/gate/jape/ActionContext.java
===================================================================
--- gate/trunk/src/main/gate/jape/ActionContext.java    2014-04-10 12:58:35 UTC 
(rev 17799)
+++ gate/trunk/src/main/gate/jape/ActionContext.java    2014-04-10 14:01:51 UTC 
(rev 17800)
@@ -62,6 +62,12 @@
    */
   public boolean isPREnabled();
   
+  /**
+   * Returns true if debugging of this transducer has been enabled.
+   * @return true if debugging of this transducer has been enabled, false 
otherwise
+   */
+  public boolean isDebuggingEnabled();
+  
   public Controller getController();
   /**
    * Request the current JAPE phase to be ended as soon as possible.

Modified: gate/trunk/src/main/gate/jape/DefaultActionContext.java
===================================================================
--- gate/trunk/src/main/gate/jape/DefaultActionContext.java     2014-04-10 
12:58:35 UTC (rev 17799)
+++ gate/trunk/src/main/gate/jape/DefaultActionContext.java     2014-04-10 
14:01:51 UTC (rev 17800)
@@ -38,6 +38,7 @@
   protected Controller controller;
   protected boolean phaseEnded = false;
   protected ProcessingResource pr;
+  protected boolean debug = false;
 
   public DefaultActionContext() {}
 
@@ -79,6 +80,15 @@
   public Controller getController() {
     return controller;
   }
+  
+  @Override
+  public boolean isDebuggingEnabled() {
+    return debug;
+  }
+  
+  public void setDebuggingEnabled(boolean debug) {
+    this.debug = debug;
+  }
 
   @Override
   public boolean endPhase() {

Modified: gate/trunk/src/main/gate/jape/RightHandSide.java
===================================================================
--- gate/trunk/src/main/gate/jape/RightHandSide.java    2014-04-10 12:58:35 UTC 
(rev 17799)
+++ gate/trunk/src/main/gate/jape/RightHandSide.java    2014-04-10 14:01:51 UTC 
(rev 17800)
@@ -19,6 +19,8 @@
 
 import gate.AnnotationSet;
 import gate.Document;
+import gate.Factory;
+import gate.FeatureMap;
 import gate.Gate;
 import gate.creole.ontology.Ontology;
 import gate.util.Err;
@@ -28,6 +30,9 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -295,16 +300,47 @@
   public void transduce(Document doc, java.util.Map<String, AnnotationSet> 
bindings,
                         AnnotationSet inputAS, final AnnotationSet outputAS,
                         Ontology ontology,
-                        ActionContext actionContext)
+                        final ActionContext actionContext)
                         throws JapeException {
     if(theActionObject == null) {
       instantiateActionClass();
     }
-        
+      
     // run the action class
     try {
       ((RhsAction) theActionObject).setActionContext(actionContext);
-      ((RhsAction) theActionObject).doit(doc, bindings, inputAS, outputAS, 
ontology);
+      
+      if (actionContext.isDebuggingEnabled()) {
+        AnnotationSet outputASproxy =
+                (AnnotationSet)Proxy.newProxyInstance(Gate.getClassLoader(), 
new Class[] {AnnotationSet.class},
+                        new InvocationHandler() {
+                          public Object invoke(Object proxy, Method method,
+                                  Object[] args) throws Throwable {
+                            
+                            if (method.getName().equals("add")) {
+                              int index = args.length - 1;
+                              Class<?> lastArgType = 
method.getParameterTypes()[index];
+                              if (lastArgType.equals(FeatureMap.class)) {
+                                FeatureMap features = (FeatureMap)args[index];
+                                if (features == null) {
+                                  features = Factory.newFeatureMap();
+                                  args[index] = features;
+                                }
+                                
+                                features.put("addedByPR", 
actionContext.getPRName());
+                                features.put("addedByPhase", getPhaseName());
+                                features.put("addedByRule",getRuleName());
+                              }
+                            }
+                            
+                            return method.invoke(outputAS, args);
+                          }
+                        });
+        ((RhsAction)theActionObject).doit(doc, bindings, inputAS, 
outputASproxy,
+                ontology);
+      } else {
+        ((RhsAction)theActionObject).doit(doc, bindings, inputAS, outputAS, 
ontology);
+      }
     } catch (NonFatalJapeException e) {
       // if the action class throws a non-fatal exception then respond by
       // dumping a whole bunch of useful debug information but then allow

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


------------------------------------------------------------------------------
Put Bad Developers to Shame
Dominate Development with Jenkins Continuous Integration
Continuously Automate Build, Test & Deployment 
Start a new project now. Try Jenkins in the cloud.
http://p.sf.net/sfu/13600_Cloudbees
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs

Reply via email to