You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by sc...@apache.org on 2008/01/27 15:21:41 UTC

svn commit: r615608 [2/2] - in /incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima: analysis_engine/ analysis_engine/impl/ analysis_engine/impl/compatibility/ flow/impl/ uimacpp/

Modified: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/flow/impl/CapabilityLanguageFlowObject.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/flow/impl/CapabilityLanguageFlowObject.java?rev=615608&r1=615607&r2=615608&view=diff
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/flow/impl/CapabilityLanguageFlowObject.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/flow/impl/CapabilityLanguageFlowObject.java Sun Jan 27 06:21:40 2008
@@ -19,21 +19,17 @@
 
 package org.apache.uima.flow.impl;
 
-import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
-import org.apache.uima.UIMAFramework;
 import org.apache.uima.analysis_engine.ResultSpecification;
-import org.apache.uima.analysis_engine.TypeOrFeature;
 import org.apache.uima.cas.CAS;
 import org.apache.uima.cas.TypeSystem;
 import org.apache.uima.cas.text.Language;
 import org.apache.uima.flow.CasFlow_ImplBase;
 import org.apache.uima.flow.FinalStep;
-import org.apache.uima.flow.SimpleStep;
 import org.apache.uima.flow.SimpleStepWithResultSpec;
 import org.apache.uima.flow.Step;
 
@@ -56,26 +52,28 @@
    */
   private TypeSystem mLastTypeSystem;
 
-  /**
-   * The static list of nodes.
-   */
-  private List mNodeList;
+//  /**
+//   * The static list of nodes.
+//   */
+//  private List mNodeList;
 
+  private final CapabilityLanguageFlowController mParentController;
+  
   /**
    * Current index in the sequence list.
    */
   private int mIndex;
 
-  /**
-   * mResultSpec provides the current result specification which has to be processed. After every
-   * analysis run, the processed ouput result are removed from the mResultSpec.
-   */
-  private ResultSpecification mResultSpec;
+//  /**
+//   * mResultSpec provides the current result specification which has to be processed. After every
+//   * analysis run, the processed ouput result are removed from the mResultSpec.
+//   */
+//  private ResultSpecification mResultSpec;
 
   /**
    * flowTable includes all languages with their flow sequence
    */
-  private Map mFlowTable;
+  private Map<String, List<AnalysisSequenceCapabilityNode>> mFlowTable;
 
   /**
    * main language separator e.g 'en' and 'en-US'
@@ -84,24 +82,26 @@
 
   static final long serialVersionUID = -5879514955935785660L;
 
-  /**
-   * Creates a new CapabilityLanguageAnalysisSequence.
-   * 
-   * @param aNodeList
-   *          a List of {@link AnalysisSequenceNode} objects. These will be returned in order by
-   *          {@link #getNext(CAS)}.
-   * @param resultSpec
-   *          result specification of the top level aggregate AE
-   */
-  public CapabilityLanguageFlowObject(List aNodeList, ResultSpecification resultSpec) {
-    mNodeList = aNodeList;
-    mIndex = 0;
-    // clone result specification
-    mResultSpec = (ResultSpecification) resultSpec.clone();
-    mFlowTable = null;
-    mLastTypeSystem = null;
-
-  }
+  
+  // Next constructor is never referenced - try removing it :-)  MIS 1/2008
+//  /**
+//   * Creates a new CapabilityLanguageAnalysisSequence.
+//   * 
+//   * @param aNodeList
+//   *          a List of {@link AnalysisSequenceNode} objects. These will be returned in order by
+//   *          {@link #getNext(CAS)}.
+//   * @param resultSpec
+//   *          result specification of the top level aggregate AE
+//   */
+//  public CapabilityLanguageFlowObject(List aNodeList, ResultSpecification resultSpec) {
+//    mNodeList = aNodeList;
+//    mIndex = 0;
+//    // clone result specification
+//    mResultSpec = (ResultSpecification) resultSpec.clone();
+//    mFlowTable = null;
+//    mLastTypeSystem = null;
+//
+//  }
 
   /**
    * Create a new CapabilityLangaugeAnalysisSequence with the flowTable
@@ -109,12 +109,14 @@
    * @param aFlowTable
    *          a flow table
    */
-  public CapabilityLanguageFlowObject(Map aFlowTable) {
-    mNodeList = null;
+  public CapabilityLanguageFlowObject(Map<String, List<AnalysisSequenceCapabilityNode>> aFlowTable, 
+      CapabilityLanguageFlowController aParentController) {
+//    mNodeList = null;
     mIndex = 0;
-    mResultSpec = null;
+//    mResultSpec = null;
     mFlowTable = aFlowTable;
     mLastTypeSystem = null;
+    mParentController = aParentController;
   }
 
   public Step next() {
@@ -122,7 +124,8 @@
     CAS cas = getCas();
     assert cas != null; // CapabilityLanguageFlowController ensures this
 
-    // if type system has changed, recompile flow table
+    // if type system has changed, recompile flow table to pick up 
+    //   potentially different type system inheritances
     if (mLastTypeSystem != cas.getTypeSystem()) {
       // set new type system
       mLastTypeSystem = cas.getTypeSystem();
@@ -134,119 +137,119 @@
     // get current document language from the CAS
     String documentLanguage = Language.normalize(cas.getDocumentLanguage());
 
-    if (mNodeList != null) {
-      // check if another engine is available
-      if (mIndex >= mNodeList.size()) {
-        return new FinalStep();
-      } else {
-        // get array of ouput capabilities for the current languge from the current result spec
-        TypeOrFeature[] ouputCapabilities = mResultSpec.getResultTypesAndFeatures(documentLanguage);
-
-        // strip language extension if available
-        int index = documentLanguage.indexOf(LANGUAGE_SEPARATOR);
-
-        // if country extension was available
-        if (index >= 0) {
-          // create HashSet for outputSpec
-          HashSet outputSpec = new HashSet();
-
-          // add language with country extension output capabilities to the outputSpec
-          if (ouputCapabilities.length > 0) {
-            for (int i = 0; i < ouputCapabilities.length; i++) {
-              outputSpec.add(ouputCapabilities[i]);
-            }
-
-            // get array of output capabilities only for the language without country extension
-            ouputCapabilities = mResultSpec.getResultTypesAndFeatures(documentLanguage.substring(0,
-                    index));
-
-            // add language output capabilities to the outputSpec
-            for (int i = 0; i < ouputCapabilities.length; i++) {
-              outputSpec.add(ouputCapabilities[i]);
-            }
-
-            // convert all output capabilities to a outputCapabilities array
-            ouputCapabilities = new TypeOrFeature[outputSpec.size()];
-            outputSpec.toArray(ouputCapabilities);
-          } else // for language with country extension was noting found
-          {
-            // get array of output capabilities with the new main language without country extension
-            ouputCapabilities = mResultSpec.getResultTypesAndFeatures(documentLanguage.substring(0,
-                    index));
-          }
-        }
-
-        // current analysis node which contains the current analysis engine
-        AnalysisSequenceCapabilityNode node;
-
-        // result spec for the current analysis engine
-        ResultSpecification currentAnalysisResultSpec = null;
-
-        // flag if current analysis engine should be called or not
-        boolean shouldEngineBeCalled = false;
-
-        // check output capabilites from the current result spec
-        do {
-          // get next analysis engine from the sequence node
-          node = (AnalysisSequenceCapabilityNode) mNodeList.get(mIndex++);
-
-          // get capability container from the current analysis engine
-          CapabilityContainer capabilityContainer = node.getCapabilityContainer();
-
-          // create current analysis result spec without any language information
-          currentAnalysisResultSpec = UIMAFramework.getResourceSpecifierFactory()
-                  .createResultSpecification();
-
-          // check if engine should be called - loop over all ouput capabilities of the result spec
-          for (int i = 0; i < ouputCapabilities.length; i++) {
-            // check if current ToF can be produced by the current analysis engine
-            if (capabilityContainer.hasOutputTypeOrFeature(ouputCapabilities[i], documentLanguage,
-                    true)) {
-              currentAnalysisResultSpec.addResultTypeOrFeature(ouputCapabilities[i]);
-              shouldEngineBeCalled = true;
-
-              // remove current ToF from the result spec
-              mResultSpec.removeTypeOrFeature(ouputCapabilities[i]);
-            }
-
-          }
-          // skip engine if not output capability match
-        } while (shouldEngineBeCalled == false && mIndex < mNodeList.size());
-
-        // check if current engine should be called
-        if (shouldEngineBeCalled == true) {
-          // set result spec for current analysis engine
-          node.setResultSpec(currentAnalysisResultSpec);
-
-          // return current analysis engine node
-          return new SimpleStepWithResultSpec(node.getCasProcessorKey(), currentAnalysisResultSpec);
-        } else // no engine left which can be called
-        {
-          return new FinalStep();
-        }
-      }
-    } else if (mFlowTable != null) {
+//    if (mNodeList != null) {
+//      // check if another engine is available
+//      if (mIndex >= mNodeList.size()) {
+//        return new FinalStep();
+//      } else {
+//        // get array of ouput capabilities for the current languge from the current result spec
+//        TypeOrFeature[] ouputCapabilities = mResultSpec.getResultTypesAndFeatures(documentLanguage);
+//
+//        // strip language extension if available
+//        int index = documentLanguage.indexOf(LANGUAGE_SEPARATOR);
+//
+//        // if country extension was available
+//        if (index >= 0) {
+//          // create HashSet for outputSpec
+//          HashSet outputSpec = new HashSet();
+//
+//          // add language with country extension output capabilities to the outputSpec
+//          if (ouputCapabilities.length > 0) {
+//            for (int i = 0; i < ouputCapabilities.length; i++) {
+//              outputSpec.add(ouputCapabilities[i]);
+//            }
+//
+//            // get array of output capabilities only for the language without country extension
+//            ouputCapabilities = mResultSpec.getResultTypesAndFeatures(documentLanguage.substring(0,
+//                    index));
+//
+//            // add language output capabilities to the outputSpec
+//            for (int i = 0; i < ouputCapabilities.length; i++) {
+//              outputSpec.add(ouputCapabilities[i]);
+//            }
+//
+//            // convert all output capabilities to a outputCapabilities array
+//            ouputCapabilities = new TypeOrFeature[outputSpec.size()];
+//            outputSpec.toArray(ouputCapabilities);
+//          } else // for language with country extension was noting found
+//          {
+//            // get array of output capabilities with the new main language without country extension
+//            ouputCapabilities = mResultSpec.getResultTypesAndFeatures(documentLanguage.substring(0,
+//                    index));
+//          }
+//        }
+//
+//        // current analysis node which contains the current analysis engine
+//        AnalysisSequenceCapabilityNode node;
+//
+//        // result spec for the current analysis engine
+//        ResultSpecification currentAnalysisResultSpec = null;
+//
+//        // flag if current analysis engine should be called or not
+//        boolean shouldEngineBeCalled = false;
+//
+//        // check output capabilites from the current result spec
+//        do {
+//          // get next analysis engine from the sequence node
+//          node = (AnalysisSequenceCapabilityNode) mNodeList.get(mIndex++);
+//
+//          // get capability container from the current analysis engine
+//          CapabilityContainer capabilityContainer = node.getCapabilityContainer();
+//
+//          // create current analysis result spec without any language information
+//          currentAnalysisResultSpec = UIMAFramework.getResourceSpecifierFactory()
+//                  .createResultSpecification();
+//
+//          // check if engine should be called - loop over all ouput capabilities of the result spec
+//          for (int i = 0; i < ouputCapabilities.length; i++) {
+//            // check if current ToF can be produced by the current analysis engine
+//            if (capabilityContainer.hasOutputTypeOrFeature(ouputCapabilities[i], documentLanguage,
+//                    true)) {
+//              currentAnalysisResultSpec.addResultTypeOrFeature(ouputCapabilities[i]);
+//              shouldEngineBeCalled = true;
+//
+//              // remove current ToF from the result spec
+//              mResultSpec.removeTypeOrFeature(ouputCapabilities[i]);
+//            }
+//
+//          }
+//          // skip engine if not output capability match
+//        } while (shouldEngineBeCalled == false && mIndex < mNodeList.size());
+//
+//        // check if current engine should be called
+//        if (shouldEngineBeCalled == true) {
+//          // set result spec for current analysis engine
+//          node.setResultSpec(currentAnalysisResultSpec);
+//
+//          // return current analysis engine node
+//          return new SimpleStepWithResultSpec(node.getCasProcessorKey(), currentAnalysisResultSpec);
+//        } else // no engine left which can be called
+//        {
+//          return new FinalStep();
+//        }
+//      }
+//    } else if (mFlowTable != null) {
+    
+      // in this impl, mFlowTable is never null
       AnalysisSequenceCapabilityNode node = null;
 
       // check if document language is included in the flowTable
-      List flow = (List) mFlowTable.get(documentLanguage);
+      List<AnalysisSequenceCapabilityNode> flow = mFlowTable.get(documentLanguage);
 
-      if (flow == null) // try to get flow without language extension or with x-unspecified
-      {
+      if (flow == null) { // try to get flow without language extension or with x-unspecified
         // strip language extension if available
         int index = documentLanguage.indexOf(LANGUAGE_SEPARATOR);
 
         // if country extension is available
         if (index >= 0) {
           // check if document language is included in the flowTable
-          flow = (List) mFlowTable.get(documentLanguage.substring(0, index));
+          flow = mFlowTable.get(documentLanguage.substring(0, index));
           // If the language was not found, use flow for unspecified lang instead.
           if (flow == null) {
-            flow = (List) mFlowTable.get(UNSPECIFIED_LANGUAGE);
+            flow = mFlowTable.get(UNSPECIFIED_LANGUAGE);
           }
-        } else // try to get flow for language x-unspecified
-        {
-          flow = (List) mFlowTable.get(UNSPECIFIED_LANGUAGE);
+        } else {// try to get flow for language x-unspecified
+          flow = mFlowTable.get(UNSPECIFIED_LANGUAGE);
         }
       }
 
@@ -260,9 +263,23 @@
         }
       }
       if (node != null) {
-        return new SimpleStepWithResultSpec(node.getCasProcessorKey(), node.getResultSpec());
-      }
-    }
+        // see if this next cas processor was previously given this result spec, and 
+        // if so, set a flag indicating this
+        
+        Map<String, ResultSpecification> lastResultSpecForComponent = mParentController.getLastResultSpecForComponent();
+        String component = node.getCasProcessorKey();
+        ResultSpecification neededResultSpec = node.getResultSpec();      
+        ResultSpecification previousResultSpec = lastResultSpecForComponent.get(component);
+        
+        if (null == previousResultSpec || previousResultSpec != neededResultSpec) {
+          lastResultSpecForComponent.put(component, neededResultSpec);
+          return new SimpleStepWithResultSpec(component, neededResultSpec); 
+        } 
+        // null is a special flag saying the previous component result spec is still good
+        return new SimpleStepWithResultSpec(node.getCasProcessorKey(), null);
+//        return new SimpleStepWithResultSpec(component, neededResultSpec); // for testing with caching disabled
+      } 
+//    }
     return new FinalStep();
   }
 
@@ -288,6 +305,8 @@
 
   /**
    * recompiles all result specs in the flow table with the current type system
+   * Actual recompiling is done later when first needed; what happens now is that
+   * the type system is set into the result spec, which the compile will need.
    */
   protected void recompileFlowTable() {
 
@@ -308,7 +327,7 @@
           AnalysisSequenceCapabilityNode node = (AnalysisSequenceCapabilityNode) sequence.get(i);
           if (node != null) {
             // recompile result spec
-            node.getResultSpec().compile(mLastTypeSystem);
+            node.getResultSpec().setTypeSystem(mLastTypeSystem);
           }
         }
       }

Modified: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/uimacpp/CppUimajEngine.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/uimacpp/CppUimajEngine.java?rev=615608&r1=615607&r2=615608&view=diff
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/uimacpp/CppUimajEngine.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/uimacpp/CppUimajEngine.java Sun Jan 27 06:21:40 2008
@@ -191,7 +191,7 @@
       // 2. create result spec
       if (ae != null) {
 
-        ResultSpecification rs = ae.createResultSpecification();
+        ResultSpecification rs = ae.createResultSpecification(casImpl.getTypeSystem());
         for (int i = 0; i < resultSpecTypes.length; ++i) {
           // allAnnotatorFeatures is not considere here! (TODO)
           rs