Revision: 15237
          http://gate.svn.sourceforge.net/gate/?rev=15237&view=rev
Author:   valyt
Date:     2012-01-27 12:57:23 +0000 (Fri, 27 Jan 2012)
Log Message:
-----------
Generated code compiles.

Modified Paths:
--------------
    futures/JAPE_PlusC/build.xml
    futures/JAPE_PlusC/src/gate/jape/plus/SPTBase.java
    futures/JAPE_PlusC/src/gate/jape/plus/SPTBuilder.java
    futures/JAPE_PlusC/src/gate/jape/plus/SPTPhaseEG.java

Modified: futures/JAPE_PlusC/build.xml
===================================================================
--- futures/JAPE_PlusC/build.xml        2012-01-27 11:30:16 UTC (rev 15236)
+++ futures/JAPE_PlusC/build.xml        2012-01-27 12:57:23 UTC (rev 15237)
@@ -1,4 +1,9 @@
 <project name="JAPE-Plus" basedir="." default="build" >
+       
+       <!-- TODO: remove this! -->
+       <property name="gate.home" location="../gate" />
+       
+       
   <property file="build.properties" />
 
   <!-- Make environment variables available -->

Modified: futures/JAPE_PlusC/src/gate/jape/plus/SPTBase.java
===================================================================
--- futures/JAPE_PlusC/src/gate/jape/plus/SPTBase.java  2012-01-27 11:30:16 UTC 
(rev 15236)
+++ futures/JAPE_PlusC/src/gate/jape/plus/SPTBase.java  2012-01-27 12:57:23 UTC 
(rev 15237)
@@ -196,12 +196,12 @@
     /**
      * The current annotation this instance will be applied on
      */
-    protected int annotationIndex;
+    public int annotationIndex;
 
     /**
      * The current state for this instance.
      */
-    protected int state;
+    public int state;
 
     /**
      * Store the currently bound annotations. Keys are binding labels, values
@@ -209,72 +209,73 @@
      */
     protected Map<String, IntArrayList> bindings;
 
-  /**
-   * A stack of bindings. It maps a number i to bindingStack[i]. A string
-   * label L corresponds to each i. This label L becomes clear when a
-   * transition '):L' (of type closing-round-bracket) is consumed. When L
-   * becomes clear, we add the pair <L, bindingStack[i]> into the hash map
-   * bindings.
-   */
-  private IntArrayList[] bindingStack;
-
-  /**
-   * The number of the annotation sets stored in the stack. If
-   * bindingStackStored > 0, then the top set of the stack is
-   * bindingStack[bindingStackStored - 1].
-   */
-  private int bindingStackStored;
-
-  /**
-   * Pushes a new empty annotation set in the binding stack. This method is
-   * invoked for each opening-round-bracket transition that is consumed during
-   * the traversal.
-   */
-  public void pushNewEmptyBindingSet() {
-    if (bindingStack.length == bindingStackStored) {
-      bindingStack = Arrays.copyOf(bindingStack, 2 * bindingStackStored);
+    /**
+     * A stack of bindings. It maps a number i to bindingStack[i]. A string
+     * label L corresponds to each i. This label L becomes clear when a
+     * transition '):L' (of type closing-round-bracket) is consumed. When L
+     * becomes clear, we add the pair <L, bindingStack[i]> into the hash map
+     * bindings.
+     */
+    private IntArrayList[] bindingStack;
+  
+    /**
+     * The number of the annotation sets stored in the stack. If
+     * bindingStackStored > 0, then the top set of the stack is
+     * bindingStack[bindingStackStored - 1].
+     */
+    private int bindingStackStored;
+  
+    /**
+     * Pushes a new empty annotation set in the binding stack. This method is
+     * invoked for each opening-round-bracket transition that is consumed 
during
+     * the traversal.
+     */
+    public void pushNewEmptyBindingSet() {
+      if (bindingStack.length == bindingStackStored) {
+        bindingStack = Arrays.copyOf(bindingStack, 2 * bindingStackStored);
+      }
+      bindingStack[bindingStackStored] = null;
+      bindingStackStored++;
     }
-    bindingStack[bindingStackStored] = null;
-    bindingStackStored++;
-  }
 
-  /**
-   * Pops annotation set from the binding stack and puts it in the hash map
-   * bindings. This method is invoked when a closing-round-bracket transition
-   * '):label' is consumed during the traversal.
-   */
-  public void popBindingSet(String label) {
-    // Here bindingStackStored is always > 0.
-    bindingStackStored--;
-    IntArrayList annotList = bindingStack[bindingStackStored];
-    if (annotList != null && !annotList.isEmpty()) {
-      IntArrayList annotSet = bindings.get(label);
-      if (annotSet == null) {
-        annotSet = new IntArrayList();
+    /**
+     * Pops annotation set from the binding stack and puts it in the hash map
+     * bindings. This method is invoked when a closing-round-bracket transition
+     * '):label' is consumed during the traversal.
+     */
+    public void popBindingSet(String label) {
+      // Here bindingStackStored is always > 0.
+      bindingStackStored--;
+      IntArrayList annotList = bindingStack[bindingStackStored];
+      if (annotList != null && !annotList.isEmpty()) {
+        IntArrayList annotSet = bindings.get(label);
+        if (annotSet == null) {
+          annotSet = new IntArrayList();
+        }
+        int length = annotList.size();
+        for (int i = 0; i < length; i++) {
+          annotSet.add(annotList.get(i));
+        }
+        bindings.put(label, annotSet);
       }
-      int length = annotList.size();
-      for (int i = 0; i < length; i++) {
-        annotSet.add(annotList.get(i));
-      }
-      bindings.put(label, annotSet);
     }
-  }
 
-  /**
-   * Adds all input annotations to every annotation set stored in the binding 
stack.
-   */
-  public void bindAnnotations(int[] aStep) {
-    int j;
-    for (int i = 0; i < bindingStackStored; i++) {
-      for (j = 0; j < aStep.length; j++) {
-        if (bindingStack[i] == null) {
-          bindingStack[i] = new IntArrayList();
+    /**
+     * Adds all input annotations to every annotation set stored in the 
binding stack.
+     */
+    public void bindAnnotations(int[] aStep) {
+      int j;
+      for (int i = 0; i < bindingStackStored; i++) {
+        for (j = 0; j < aStep.length; j++) {
+          if (bindingStack[i] == null) {
+            bindingStack[i] = new IntArrayList();
+          }
+          if(aStep[j] >= 0) bindingStack[i].add(aStep[j]);
         }
-        if(aStep[j] >= 0) bindingStack[i].add(aStep[j]);
       }
     }
+
   }
-  }
 
   /**
    * The Ontology used during matching.
@@ -1168,7 +1169,45 @@
 //            ((double)predicateHits / (predicateHits + predicateMisses))));
   }
 
+  protected void generateAllNewInstances(FSMInstance instance,
+                                         int nextState,
+                                         IntArrayList[] annotsForConstraints) {
+    List<int[]> nextSteps = enumerateCombinations(annotsForConstraints);
+    for(int[] aStep : nextSteps) {
+      FSMInstance nextInstance = instance.clone();
+      // update the data in the next instance            
+      nextInstance.state = nextState;
+      // Calculate the next annotation to look at: find the one starting
+      // after the longest matched annotation.
+      int nextAnnotationForInstance = instance.annotationIndex;
+      int maxNextStep = -1;
+      for(int i = 0; i < aStep.length; i++) {
+        if(aStep[i]>= 0){
+          if(maxNextStep < aStep[i]) maxNextStep = aStep[i];
+          if(nextAnnotationForInstance < followingAnnotation(aStep[i])) {
+            nextAnnotationForInstance = followingAnnotation(aStep[i]);
+          }
+        }
+      }
+      // When zero-length annotations are used, followingAnnotation(annIDx)
+      // may not actually advance. To avoid infinite looping, we need to 
+      // make sure that next annotation is greater than all the ones
+      // already matched. 
+      if(nextAnnotationForInstance <= maxNextStep) {
+        if(maxNextStep < annotation.length -2) {
+          nextAnnotationForInstance = maxNextStep + 1;
+        } else {
+          // no more annotations
+          nextAnnotationForInstance = Integer.MAX_VALUE;
+        }
+      }
+      nextInstance.annotationIndex = nextAnnotationForInstance;
+      nextInstance.bindAnnotations(aStep);
+      activeInstances.addLast(nextInstance);
+    }
+  }
   
+  
   protected void applyRule(FSMInstance instance) throws JapeException {
     // convert bindings to correct type
     Map<String, AnnotationSet> newBindings =
@@ -1194,7 +1233,7 @@
    * @return a list of N-uples, representing all possible combinations of the
    *         input candidates.
    */
-  protected static List<int[]> enumerateCombinations(IntArrayList[] 
candidates) {
+  protected final static List<int[]> enumerateCombinations(IntArrayList[] 
candidates) {
     List<int[]> combinations = new ArrayList<int[]>();
     int[] indexes = new int[candidates.length];
     int currentIndex = indexes.length;

Modified: futures/JAPE_PlusC/src/gate/jape/plus/SPTBuilder.java
===================================================================
--- futures/JAPE_PlusC/src/gate/jape/plus/SPTBuilder.java       2012-01-27 
11:30:16 UTC (rev 15236)
+++ futures/JAPE_PlusC/src/gate/jape/plus/SPTBuilder.java       2012-01-27 
12:57:23 UTC (rev 15237)
@@ -15,6 +15,8 @@
 
 package gate.jape.plus;
 
+import java.io.FileWriter;
+import java.io.IOException;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
 import java.text.NumberFormat;
@@ -35,24 +37,29 @@
 import cern.colt.map.OpenIntIntHashMap;
 
 import gate.creole.ResourceInstantiationException;
-import gate.fsm.Transition;
+import gate.jape.plus.SPTBase.Transition;
 import gate.jape.Constraint;
 import gate.jape.JapeConstants;
 import gate.jape.RightHandSide;
 import gate.jape.Rule;
-import gate.jape.constraint.AnnotationFeatureAccessor;
 import gate.jape.constraint.ConstraintPredicate;
 import gate.jape.constraint.ContainsPredicate;
 import gate.jape.constraint.WithinPredicate;
 import gate.jape.plus.Predicate.PredicateType;
 import gate.jape.plus.SPTBase.FSMInstance;
 import gate.jape.plus.SPTBase.MatchMode;
+import gate.jape.plus.SPTBase.State;
 
 /**
  * An utility class for converting a default JAPE transducer into a JAPE-Plus 
transducer. 
  */
 public class SPTBuilder {
 
+  
+  private static final String[] TABS = new String[]{"", "\t", "\t\t", "\t\t\t",
+      "\t\t\t\t", "\t\t\t\t\t", "\t\t\t\t\t\t", "\t\t\t\t\t\t\t", 
+      "\t\t\t\t\t\t\t\t"};
+  
   /**
    * Stores the states for the optimised transducer.
    */
@@ -89,76 +96,34 @@
     rules = ((List<Rule>) oldSpt.getRules()).toArray(rules);
     
     oldSpt.finish();
-//    FSM fsm = new FSM(oldSpt);
+    // FSM fsm = new FSM(oldSpt);
     FSMPDA fsm = (FSMPDA) oldSpt.getFSM();
-    
     createNewStates(fsm);
     createNewTransitions(fsm);
     optimisePredicates();
 
-    //TODO: generate code, compile class, load instance
-    
     StringBuilder sptCode = new StringBuilder();
-    String className = oldSpt.getName();
-    // append preamble
-    
-    // write constructor
-    sptCode.append("public void ");
-    sptCode.append(className);
-    sptCode.append(" (Rule[] rules, Predicate[][] predicatesByType) {\n");
-    sptCode.append("super (");
-    // phaseName
-    sptCode.append(oldSpt.getName());
-    sptCode.append(",\n");
-    // binding names
-    sptCode.append("// binding names");
-    sptCode.append("new String[]{");
-    boolean first = true;
-    for(String str : fsm.getBindingNames()) {
-      if(first) {
-        first = false;
-      } else {
-        sptCode.append(", ");
-      }
-      sptCode.append("\"" + str +"\"");
+    String className = "Phase" + oldSpt.getName();
+
+    writeClassHeader(className, sptCode);
+    writeConstructor(className, oldSpt, 1, sptCode);
+    writeAdvanceInstanceMethod(1, sptCode);
+    for(int stateId = 0; stateId < newStates.size(); stateId++) {
+      writeStateMethod(stateId, 1, sptCode);
     }
-    sptCode.append("},\n");
-    // annotationTypes
-    sptCode.append("// annotationTypes");
-    sptCode.append("new String[]{");
-    first = true;
-    for(String str : annotationTypes) {
-      if(first) {
-        first = false;
-      } else {
-        sptCode.append(", ");
-      }
-      sptCode.append("\"" + str +"\"");
-    }
-    sptCode.append("},\n");
-    // debugMode
-    sptCode.append(oldSpt.isDebugMode());
-    sptCode.append(",\n");
-    // groupMatchingMode
-    sptCode.append(oldSpt.isMatchGroupMode());
-    sptCode.append(",\n");
-    // match style
-    String matchStyle = MatchMode.APPELT.name(); // default is APPELT
-    if(oldSpt.getRuleApplicationStyle() == JapeConstants.ALL_STYLE){
-      matchStyle = MatchMode.ALL.name();
-    } else if(oldSpt.getRuleApplicationStyle() == JapeConstants.BRILL_STYLE){
-      matchStyle =  MatchMode.BRILL.name();
-    }else if(oldSpt.getRuleApplicationStyle() == JapeConstants.FIRST_STYLE){
-      matchStyle =  MatchMode.FIRST.name();
-    }else if(oldSpt.getRuleApplicationStyle() == JapeConstants.ONCE_STYLE){
-      matchStyle =  MatchMode.ONCE.name();
-    }
-    sptCode.append(matchStyle);
-    sptCode.append(",\n");
-    sptCode.append("rules, predicatesByType\n");
+    writeClassFooter(sptCode);
     
-    sptCode.append(")\n"); // end super()
-    sptCode.append("}\n"); // end constructor
+try {
+  FileWriter outWriter = new FileWriter(
+    
"/home/valyt.plain/vcs/gate-top/externals/JAPE_PlusC/src/gate/jape/plus/phases/"
 + 
+    className + ".java");
+  outWriter.write(sptCode.toString());
+  outWriter.close();
+} catch(IOException e1) {
+  // TODO Auto-generated catch block
+  e1.printStackTrace();
+}
+
     // compile the class
     Class<? extends SPTBase> sptClass = null; //TODO
 
@@ -207,11 +172,6 @@
               optimisedTransducer.inputAnnotationTypes);
     }
     
-    
-    //states
-    optimisedTransducer.states = new SPTBase.State[newStates.size()];
-    optimisedTransducer.states = newStates.toArray(optimisedTransducer.states);
-
     optimisedTransducer.
       
setControllerEventBlocksAction(oldSpt.getControllerEventBlocksActionClass());
 
@@ -225,6 +185,281 @@
     return optimisedTransducer;
   }
   
+  protected void writeClassHeader(String className,
+                                  StringBuilder out) {
+    out.append("package gate.jape.plus.phases;\n");
+    out.append("import gate.jape.Rule;\n");
+    out.append("import gate.jape.plus.Predicate;\n");
+      out.append("import gate.jape.plus.SPTBase;\n");
+    out.append("import java.util.List;\n");
+    out.append("import static gate.jape.plus.SPTBase.MatchMode.*;\n");
+    out.append("import cern.colt.list.IntArrayList;\n\n");
+    out.append("public class ").append(className).append(" extends SPTBase 
{\n");
+  }
+  
+  protected void writeConstructor(String className,
+                                  SinglePhaseTransducerPDA spt,
+                                  int tabs,
+                                  StringBuilder out) {
+    out.append(TABS[tabs]).append("public ").append(className).append(" ("
+        ).append("Rule[] rules, Predicate[][] predicatesByType) {\n");
+    tabs++;
+    out.append(TABS[tabs]).append("super (\n");
+    tabs++;
+    // phaseName
+    out.append(TABS[tabs]).append('"').append(className).append('"').append(", 
// phase name\n");
+    // binding names
+    out.append(TABS[tabs]).append("// binding names\n");
+    out.append(TABS[tabs]).append("new String[]{");
+    boolean first = true;
+    for(String str : ((FSMPDA)spt.getFSM()).getBindingNames()) {
+      if(first) {
+        first = false;
+      } else {
+        out.append(", ");
+      }
+      out.append("\"").append(str).append("\"");
+    }
+    out.append("},\n");
+    // annotationTypes
+    out.append(TABS[tabs]).append("// annotationTypes\n");
+    out.append(TABS[tabs]).append("new String[]{");
+    first = true;
+    for(String str : annotationTypes) {
+      if(first) {
+        first = false;
+      } else {
+        out.append(", ");
+      }
+      out.append("\"").append(str).append("\"");
+    }
+    out.append("},\n");
+    // debugMode
+    out.append(TABS[tabs]).append(spt.isDebugMode()).append(",").append(" // 
debugMode\n");
+    // groupMatchingMode
+    out.append(TABS[tabs]).append(spt.isMatchGroupMode()).append(",").append(" 
// groupMatchingMode\n");
+    // match style
+    String matchStyle = MatchMode.APPELT.name(); // default is APPELT
+    if(spt.getRuleApplicationStyle() == JapeConstants.ALL_STYLE){
+      matchStyle = MatchMode.ALL.name();
+    } else if(spt.getRuleApplicationStyle() == JapeConstants.BRILL_STYLE){
+      matchStyle =  MatchMode.BRILL.name();
+    }else if(spt.getRuleApplicationStyle() == JapeConstants.FIRST_STYLE){
+      matchStyle =  MatchMode.FIRST.name();
+    }else if(spt.getRuleApplicationStyle() == JapeConstants.ONCE_STYLE){
+      matchStyle =  MatchMode.ONCE.name();
+    }
+    out.append(TABS[tabs]).append(matchStyle).append(",").append(" // matching 
style\n");
+    out.append(TABS[tabs]).append("rules, predicatesByType\n");
+    tabs--;
+    out.append(TABS[tabs]).append(");\n"); // end super()
+    tabs--;
+    out.append(TABS[tabs]).append("}\n\n"); // end constructor
+  }
+  
+  protected void writeAdvanceInstanceMethod(int tabs, StringBuilder out) {
+    out.append(TABS[tabs]).append("@Override\n");
+    out.append(TABS[tabs]).append("protected final void 
advanceInstance(FSMInstance instance) {\n");
+    tabs++;
+    out.append(TABS[tabs]).append("switch(instance.state) {\n");
+    tabs++;
+    for(int stateId = 0; stateId < newStates.size(); stateId++) {
+      out.append(TABS[tabs]).append("case ").append(stateId).append(":\n");
+      tabs++;
+      
out.append(TABS[tabs]).append("state").append(stateId).append("(instance);\n");
+      out.append(TABS[tabs]).append("break;\n");
+      tabs--;
+    }
+    tabs--;
+    out.append(TABS[tabs]).append("}\n");
+    tabs--;
+    out.append(TABS[tabs]).append("}\n\n");
+  }
+  
+  protected void writeStateMethod(int stateId, int tabs, StringBuilder out) {
+    out.append(TABS[tabs]).append("private final void state").append(
+      stateId).append('(').append("FSMInstance instance").append("){\n");
+    tabs++;
+    State state = newStates.get(stateId);
+    // if final state
+    if(state.rule >= 0) {
+      out.append(TABS[tabs]).append(
+        "// current instance is in a final state\n");
+      out.append(TABS[tabs]).append(
+        "acceptingInstances.add(instance.clone());\n");
+      out.append(TABS[tabs]).append(
+        "if (matchMode == MatchMode.FIRST || matchMode == MatchMode.ONCE) 
{\n");
+      tabs++;
+      out.append(TABS[tabs]).append("// we're done!\n");
+      out.append(TABS[tabs]).append("return;\n");
+      tabs--;
+      out.append(TABS[tabs]).append("}\n");
+    }
+    // for each transition
+    for(int transId = 0; transId < state.transitions.length; transId++) {
+      Transition transition = state.transitions[transId];
+      out.append(TABS[tabs]).append("s").append(stateId).append("t").append(
+        transId).append(": ").append("do { // transition block: ");
+      if(transition.type == TransitionPDA.TYPE_OPENING_ROUND_BRACKET){
+        // opening-round-bracket transition
+        out.append("opening-round-bracket transition\n");
+        tabs++;
+        out.append(TABS[tabs]).append(
+          "FSMInstance nextInstance = instance.clone();\n");
+        out.append(TABS[tabs]).append(
+          "nextInstance.pushNewEmptyBindingSet();\n");
+        out.append(TABS[tabs]).append(
+          "nextInstance.state = ").append(transition.nextState).append(";\n"); 
+        out.append(TABS[tabs]).append(
+          "activeInstances.addLast(nextInstance);\n");
+      } else if(transition.type != TransitionPDA.TYPE_CONSTRAINT){
+        // closing-round-bracket transition
+        out.append("closing-round-bracket transition\n");
+        tabs++;
+        out.append(TABS[tabs]).append(
+          "FSMInstance nextInstance = instance.clone();\n");
+        out.append(TABS[tabs]).append(
+          
"nextInstance.popBindingSet(bindingNames[").append(transition.type).append("]);\n");
+        out.append(TABS[tabs]).append(
+            "nextInstance.state = 
").append(transition.nextState).append(";\n"); 
+        out.append(TABS[tabs]).append(
+            "activeInstances.addLast(nextInstance);\n");
+      } else {
+        // constrained transition
+        out.append("constrained transition\n");
+        tabs++;
+        writeConstrainedTransitionBlock(stateId, transId, tabs, out);
+      }
+      
+      tabs--;
+      out.append(TABS[tabs]).append("} while (false); // end transition 
block\n");
+    }
+    
+    
+    tabs--;
+    out.append(TABS[tabs]).append("}\n\n");
+  }
+  
+  protected void writeConstrainedTransitionBlock(int stateId, int transId, 
+                                                 int tabs, StringBuilder out) {
+    State state = newStates.get(stateId);
+    Transition transition = state.transitions[transId];
+    out.append(TABS[tabs]).append(
+        "IntArrayList[] annotsForConstraints = new IntArrayList[").append(
+        transition.constraints.length).append("];\n");
+    for(int constrId = 0; constrId < transition.constraints.length; 
constrId++) {
+      String blockLabel = "s" + stateId + "t" + transId + "c" + constrId;
+      out.append(TABS[tabs]).append(blockLabel).append(
+        ": do{ // constraint block\n");
+      tabs++;
+      out.append(TABS[tabs]).append("final int[] constraint = new int[] {");
+      boolean first = true;
+      for(int elem : transition.constraints[constrId]) {
+        if(first) first = false; else out.append(", ");
+        out.append(elem);
+      }
+      out.append("};\n");
+      out.append(TABS[tabs]).append(
+        "annotations: for(int annIdx = instance.annotationIndex;\n");
+      tabs++;
+      tabs++;
+      out.append(TABS[tabs]).append("annIdx < annotation.length &&\n");
+      out.append(TABS[tabs]).append("annIdx < 
annotationNextOffset[instance.annotationIndex];\n"); 
+      out.append(TABS[tabs]).append("annIdx++) {\n");
+      tabs--;
+      out.append(TABS[tabs]).append(
+        "if(constraint[0] == annotationType[annIdx]) {\n");
+      tabs++;
+      out.append(TABS[tabs]).append("// type matched, now check 
predicates;\n");
+      out.append(TABS[tabs]).append(
+        "for(int predIdx = 2; predIdx < constraint.length; predIdx++) {\n");
+      tabs++;
+      out.append(TABS[tabs]).append(
+        "if(!checkPredicate(annIdx, constraint[predIdx])) {\n");
+      tabs++;
+      out.append(TABS[tabs]).append(
+        "// one predicate failed -> move to next annotation\n");
+      out.append(TABS[tabs]).append("continue annotations;\n");
+      tabs--;
+      out.append(TABS[tabs]).append("}\n");
+      tabs--;
+      out.append(TABS[tabs]).append("}\n");
+      out.append(TABS[tabs]).append(
+        "// if we got this far, all predicates succeeded, so this\n");
+      out.append(TABS[tabs]).append(
+        "// annotation matches -> add it to the list for the current\n");
+      out.append(TABS[tabs]).append("// constraint\n");
+      out.append(TABS[tabs]).append("if(annotsForConstraints[").append(
+        constrId).append("] == null) {\n");
+      tabs++;
+      out.append(TABS[tabs]).append("annotsForConstraints[").append(
+        constrId).append("] = new IntArrayList();\n");
+      tabs--;
+      out.append(TABS[tabs]).append("}\n");
+      out.append(TABS[tabs]).append("annotsForConstraints[").append(
+        constrId).append("].add(annIdx);\n");
+      tabs--;
+      out.append(TABS[tabs]).append("}\n");
+      tabs--;
+      out.append(TABS[tabs]).append("}\n");
+      out.append(TABS[tabs]).append("// we just finished checking one 
constraint\n");
+      out.append(TABS[tabs]).append("if(constraint[1] < 0){\n");
+      tabs++;
+      out.append(TABS[tabs]).append("// constraint is negated\n");
+      out.append(TABS[tabs]).append("if(annotsForConstraints[").append(
+        constrId).append("] == null){\n");
+      tabs++;
+      out.append(TABS[tabs]).append(
+        "//no annotations matched -> constraint succeeds!\n");
+      out.append(TABS[tabs]).append("annotsForConstraints[").append(
+        constrId).append("] = new IntArrayList();\n");
+      out.append(TABS[tabs]).append(
+        "// no annotation is bound though!\n");
+      out.append(TABS[tabs]).append("annotsForConstraints[").append(
+        constrId).append("].add(-1);\n");
+      tabs--;
+      out.append(TABS[tabs]).append("}else{\n");
+      tabs++;
+      out.append(TABS[tabs]).append(
+        "// annotation were matched -> so the negated constraint fails!\n");
+      out.append(TABS[tabs]).append("break ").append("s").append(
+        stateId).append("t").append(transId).append(";\n");
+      tabs--;
+      out.append(TABS[tabs]).append("}\n");
+      tabs--;
+      out.append(TABS[tabs]).append("}else{\n");
+      tabs++;
+      out.append(TABS[tabs]).append("if(annotsForConstraints[").append(
+        constrId).append("] == null) {\n");
+      tabs++;
+      out.append(TABS[tabs]).append("// current constraint matched nothing -> 
transition failed.\n");
+      out.append(TABS[tabs]).append("break ").append("s").append(
+        stateId).append("t").append(transId).append(";\n");
+      tabs--;
+      out.append(TABS[tabs]).append("}\n");
+      tabs--;
+      out.append(TABS[tabs]).append("}\n");
+      tabs--;
+      out.append(TABS[tabs]).append("} while (false); // end constraint 
block\n");
+      
+      out.append(TABS[tabs]).append(
+        "// we finished checking all constraints, and they all succeeded\n");
+      out.append(TABS[tabs]).append(
+        "// -> apply the transition with all possible bindings 
combinations\n");
+      out.append(TABS[tabs]).append(
+        "// a next step is a set of bound annotations, one for each 
constraint\n");
+      out.append(TABS[tabs]).append(
+        "generateAllNewInstances(instance, ").append(
+          transition.nextState).append(", annotsForConstraints);\n");
+    }
+
+
+  }
+  
+  protected void writeClassFooter(StringBuilder out) {
+    out.append("}\n");
+  }
+  
   /**
    * Generates new states for all the old states in the provided FSM. Stores 
the newly 
    * created states into the {@link #newStates} list, and populates the 
mapping 
@@ -244,7 +479,7 @@
         newStates.add(newState);
         oldToNewStates.put(anOldState.getIndex(), newStates.size() -1);
         //queue all old states reachable from this state
-        for(Transition anOldTransition : anOldState.getTransitions()){
+        for(gate.fsm.Transition anOldTransition : anOldState.getTransitions()){
           oldStatesQueue.add((StatePDA) anOldTransition.getTarget());
         }
         //if state is final, set the rule value
@@ -289,7 +524,7 @@
         //now process all transitions
         List<SPTBase.Transition> newTransitions = 
             new LinkedList<SPTBase.Transition>();
-        for(Transition t : anOldState.getTransitions()){
+        for(gate.fsm.Transition t : anOldState.getTransitions()){
           TransitionPDA anOldTransition = (TransitionPDA) t;
           
if(!visitedOldStates.contains(anOldTransition.getTarget().getIndex())){
             oldStatesQueue.add((StatePDA) anOldTransition.getTarget());

Modified: futures/JAPE_PlusC/src/gate/jape/plus/SPTPhaseEG.java
===================================================================
--- futures/JAPE_PlusC/src/gate/jape/plus/SPTPhaseEG.java       2012-01-27 
11:30:16 UTC (rev 15236)
+++ futures/JAPE_PlusC/src/gate/jape/plus/SPTPhaseEG.java       2012-01-27 
12:57:23 UTC (rev 15237)
@@ -81,8 +81,8 @@
     {
       // for each constraint, for each annotation, see if they match
       // this stores a list of candidate annotations for each constraint
-      int constraintsLength = 3; //TODO
-      int nextState  = 23; //TODO
+      final int constraintsLength = 3; //TODO
+      final int nextState  = 23; //TODO
       IntArrayList[] annotsForConstraints =
               new IntArrayList[constraintsLength];
       // TODO: unloop 
@@ -136,6 +136,7 @@
         }
       } while (false);
 //      }// for: constraints
+      
       // we finished checking all constraints, and they all succeeded
       // -> apply the transition with all possible bindings combinations
       // a next step is a set of bound annotations, one for each constraint
@@ -172,6 +173,7 @@
         nextInstance.bindAnnotations(aStep);
         activeInstances.addLast(nextInstance);
       }
+      
     }
   }
   

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


------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs

Reply via email to