Revision: 15263
          http://gate.svn.sourceforge.net/gate/?rev=15263&view=rev
Author:   valyt
Date:     2012-01-30 14:16:30 +0000 (Mon, 30 Jan 2012)
Log Message:
-----------
Preparing for reintegration into main codebase.

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

Removed Paths:
-------------
    futures/JAPE_PlusC/src/gate/jape/plus/SPTPhaseEG.java

Modified: futures/JAPE_PlusC/build.xml
===================================================================
--- futures/JAPE_PlusC/build.xml        2012-01-30 13:14:08 UTC (rev 15262)
+++ futures/JAPE_PlusC/build.xml        2012-01-30 14:16:30 UTC (rev 15263)
@@ -1,9 +1,5 @@
 <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-30 13:14:08 UTC 
(rev 15262)
+++ futures/JAPE_PlusC/src/gate/jape/plus/SPTBase.java  2012-01-30 14:16:30 UTC 
(rev 15263)
@@ -57,7 +57,15 @@
 
   protected ActionContext actionContext;
   
-  protected abstract void advanceInstance(FSMInstance instance);
+  /**
+   * Advances the provided instance according to the transition graph, 
+   * generating new active instances as required.
+   *  
+   * @param instance the instance to be processed 
+   * @return <code>true</code> if the process should be stopped (e.g. an 
+   * accepting instance has been found, and the matching mode is FIRST or 
ONCE). 
+   */
+  protected abstract boolean advanceInstance(FSMInstance instance);
   
   /**
    * Sets the action context to be used during execution of RHS actions.
@@ -1065,7 +1073,7 @@
       // start with state 0
       activeInstances.add(new FSMInstance(currentAnnotation, 0,
               new HashMap<String, IntArrayList>()));      
-      while(activeInstances.size() > 0) {
+      instances:while(activeInstances.size() > 0) {
         if(owner.isInterrupted()) throw new ExecutionInterruptedException(
                 "The execution of the \"" + getName() + 
                 "\" JAPE Plus transducer has been interrupted!");
@@ -1074,7 +1082,7 @@
         // advance the top instance, and queue all resulting instances.
         // get the first instance
         FSMInstance fsmInstance = activeInstances.removeFirst();
-        advanceInstance(fsmInstance);
+        if(advanceInstance(fsmInstance)) break instances;
       }// while activeInstances not empty
       // at this point, there are no more active instances (or we exited due to
       // matching mode being First or Once).

Modified: futures/JAPE_PlusC/src/gate/jape/plus/SPTBuilder.java
===================================================================
--- futures/JAPE_PlusC/src/gate/jape/plus/SPTBuilder.java       2012-01-30 
13:14:08 UTC (rev 15262)
+++ futures/JAPE_PlusC/src/gate/jape/plus/SPTBuilder.java       2012-01-30 
14:16:30 UTC (rev 15263)
@@ -109,8 +109,8 @@
     optimisePredicates();
 
     StringBuilder sptCode = new StringBuilder();
-    String className = "Phase" + oldSpt.getName() + 
-        Long.toString(System.currentTimeMillis(), Character.MAX_RADIX);
+    String className = "Phase" + oldSpt.getName() +  Long.toString(
+        System.currentTimeMillis(), Character.MAX_RADIX).toUpperCase();
 
     writeClassHeader(className, sptCode);
     writeConstructor(className, oldSpt, 1, sptCode);
@@ -119,18 +119,6 @@
       writeStateMethod(stateId, 1, sptCode);
     }
     writeClassFooter(sptCode);
-    
-try {
-  FileWriter outWriter = new FileWriter(
-    "/home/valyt.plain/vcs/gate-top/externals/JAPE_PlusC/test/src/japephases/" 
+ 
-    className + ".java");
-  outWriter.write(sptCode.toString());
-  outWriter.close();
-} catch(IOException e1) {
-  // TODO Auto-generated catch block
-  e1.printStackTrace();
-}
-
     //prepare the parameters for calling the constructor
     //predicates
     Predicate[][] predicatesByTypeArray = new Predicate[
@@ -277,25 +265,26 @@
   
   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");
+    out.append(TABS[tabs]).append("protected final boolean 
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("if(state").append(stateId).append("(instance)) 
return true;\n");
       out.append(TABS[tabs]).append("break;\n");
       tabs--;
     }
     tabs--;
     out.append(TABS[tabs]).append("}\n");
+    out.append(TABS[tabs]).append("return false;\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(
+    out.append(TABS[tabs]).append("private final boolean state").append(
       stateId).append('(').append("FSMInstance instance").append("){\n");
     tabs++;
     State state = newStates.get(stateId);
@@ -313,7 +302,7 @@
         "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");
+      out.append(TABS[tabs]).append("return true;\n");
       tabs--;
       out.append(TABS[tabs]).append("}\n");
     }
@@ -361,11 +350,8 @@
         out.append(TABS[tabs]).append(
           "} while (false); // end transition block\n\n");
       }
-      
-
     }
-    
-    
+    out.append(TABS[tabs]).append("return false;\n");
     tabs--;
     out.append(TABS[tabs]).append("}\n\n");
   }

Deleted: futures/JAPE_PlusC/src/gate/jape/plus/SPTPhaseEG.java
===================================================================
--- futures/JAPE_PlusC/src/gate/jape/plus/SPTPhaseEG.java       2012-01-30 
13:14:08 UTC (rev 15262)
+++ futures/JAPE_PlusC/src/gate/jape/plus/SPTPhaseEG.java       2012-01-30 
14:16:30 UTC (rev 15263)
@@ -1,191 +0,0 @@
-package gate.jape.plus;
-
-import gate.jape.Rule;
-
-import java.util.List;
-
-import static gate.jape.plus.SPTBase.MatchMode.*;
-
-import cern.colt.list.IntArrayList;
-
-public class SPTPhaseEG extends SPTBase {
-  
-  public SPTPhaseEG(Rule[] rules, Predicate[][] predicatesByType) {
-    super("$phaseName", 
-      new String[] {"$bindingNames"},
-      new String[] {"$annotationTypes"},
-      false, 
-      false, 
-      APPELT, 
-      rules, predicatesByType);
-  }
-
-
-  @Override
-  protected final void advanceInstance(FSMInstance instance) {
-    //TODO
-    switch(instance.state) {
-      case 0: 
-        state0(instance);
-        break;
-      case 1: 
-        state1(instance);
-        break;
-      case 2: 
-        state2(instance);
-        break;
-      case 3: 
-        state3(instance);
-        break;
-    }
-  }
-  
-  
-  private final void state0(FSMInstance instance) {
-    if(instance.rule >= 0) {
-      // current instance is in a final state
-      acceptingInstances.add(instance.clone());
-      if (matchMode == MatchMode.FIRST || matchMode == MatchMode.ONCE) {
-        // we're done!
-        //TODO?
-        return;
-      }
-    }
-    // advance
-    // for each transition
-    
-    // example opening-round-bracket transition    
-    {
-      int nextState  = 23; //TODO
-      FSMInstance nextInstance = instance.clone();
-      nextInstance.pushNewEmptyBindingSet();
-      nextInstance.state = nextState;
-      activeInstances.addLast(nextInstance);
-    }
-    
-    // example closing-round-bracket transition
-    {
-      int nextState  = 23; //TODO
-      int transitionType = 2; //TODO
-      FSMInstance nextInstance = instance.clone();
-      nextInstance.popBindingSet(bindingNames[transitionType]);
-      nextInstance.state = nextState;
-      activeInstances.addLast(nextInstance);
-      // we do not advance the annotation index,
-      // since closing-round-bracket
-      // transitions are treated like epsilon transitions
-    }
-    
-    
-    // constrained transition;
-    {
-      // for each constraint, for each annotation, see if they match
-      // this stores a list of candidate annotations for each constraint
-      final int constraintsLength = 3; //TODO
-      final int nextState  = 23; //TODO
-      IntArrayList[] annotsForConstraints =
-              new IntArrayList[constraintsLength];
-      // TODO: unloop 
-//      for(int constraintIdx = 0; 
-//          constraintIdx < constraintsLength; 
-//          constraintIdx++) {
-//        int[] constraint = aTransition.constraints[constraintIdx];
-      blklbl0001:do{  // example for each constraint loop 
-        int constraintIdx = 0; // TODO
-        int[] constraint = new int[] {1, 2, 3}; //TODO
-        annotations: for(int annIdx = instance.annotationIndex; 
-            annIdx < annotation.length &&
-            annIdx < annotationNextOffset[instance.annotationIndex]; 
-            annIdx++) {
-          if(constraint[0] == annotationType[annIdx]) {
-            // type matched, now check predicates;
-            for(int predIdx = 2; predIdx < constraint.length; predIdx++) {
-              if(!checkPredicate(annIdx, constraint[predIdx])) {
-                // one predicate failed -> move to next annotation
-                continue annotations;
-              }
-            }
-            // if we got this far, all predicates succeeded, so this
-            // annotation matches -> add it to the list for the current
-            // constraint
-            if(annotsForConstraints[constraintIdx] == null) {
-              annotsForConstraints[constraintIdx] = new IntArrayList();
-            }
-            annotsForConstraints[constraintIdx].add(annIdx);
-          }
-        }
-        // we just finished checking one constraint
-        if(constraint[1] < 0){
-          //constraint is negated
-          if(annotsForConstraints[constraintIdx] == null){
-            //no annotations matched -> constraint succeeds!
-            annotsForConstraints[constraintIdx] = new IntArrayList();
-            // no annotation is bound though!
-            annotsForConstraints[constraintIdx].add(-1);
-          }else{
-            //annotation were matched -> so the negated constraint fails!
-            // continue transitions; TODO?
-            break blklbl0001;
-          }
-        }else{
-          if(annotsForConstraints[constraintIdx] == null) {
-            // current constraint matched nothing -> transition failed.
-            // continue transitions; TODO?
-            break blklbl0001;
-          }
-        }
-      } 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
-      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);
-      }
-      
-    }
-  }
-  
-  private final void state1(FSMInstance instance) {
-    
-  }
-  
-  private final void state2(FSMInstance instance) {
-    
-  }
-  
-  private final void state3(FSMInstance instance) {
-    
-  }
-}

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