Package org.apache.uima.flow

Examples of org.apache.uima.flow.FinalStep


      // if CAS was passed to a CAS multiplier on the last step, special processing
      // is needed according to the value of the ActionAfterCasMultiplier config parameter
      if (wasPassedToCasMultiplier) {
        switch (mActionAfterCasMultiplier) {
          case ACTION_STOP:
            return new FinalStep();
          case ACTION_DROP:
            return new FinalStep(internallyCreatedCas);
          case ACTION_DROP_IF_NEW_CAS_PRODUCED:
            if (casMultiplierProducedNewCas) {
              return new FinalStep(internallyCreatedCas);
            }
            // else, continue with flow
            break;
          // if action is ACTION_CONTINUE, just continue with flow
        }
        wasPassedToCasMultiplier = false;
        casMultiplierProducedNewCas = false;
      }

      if (currentStep >= mSequence.size()) {
        return new FinalStep(); // this CAS has finished the sequence
      }

      // if next step is a CasMultiplier, set wasPassedToCasMultiplier to true for next time
      // TODO: optimize
      AnalysisEngineMetaData md = (AnalysisEngineMetaData) getContext()
View Full Code Here


    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) {
      AnalysisSequenceCapabilityNode node = null;

      // check if document language is included in the flowTable
      List flow = (List) mFlowTable.get(documentLanguage);

      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));
          // If the language was not found, use flow for unspecified lang instead.
          if (flow == null) {
            flow = (List) mFlowTable.get(UNSPECIFIED_LANGUAGE);
          }
        } else // try to get flow for language x-unspecified
        {
          flow = (List) mFlowTable.get(UNSPECIFIED_LANGUAGE);
        }
      }

      // if flow is available get next node
      if (flow != null) {
        if (flow.size() > mIndex) {
          node = (AnalysisSequenceCapabilityNode) flow.get(mIndex++);
          while (node == null && flow.size() > mIndex) {
            node = (AnalysisSequenceCapabilityNode) flow.get(mIndex++);
          }
        }
      }
      if (node != null) {
        return new SimpleStepWithResultSpec(node.getCasProcessorKey(), node.getResultSpec());
      }
    }
    return new FinalStep();
  }
View Full Code Here

            nextStep = flow.next();
          }
          // FinalStep was returned from FlowController.
          // We're done with the CAS.
          assert (nextStep instanceof FinalStep);
          FinalStep finalStep = (FinalStep) nextStep;
          activeCASes.remove(cas);
          // If this is the input CAS, just return null to indicate we're done
          // processing it. It is an error if the FlowController tried to drop this CAS.
          if (cas == mInputCas) {
            if (finalStep.getForceCasToBeDropped()) {
              throw new AnalysisEngineProcessException(
                      AnalysisEngineProcessException.ILLEGAL_DROP_CAS, new Object[0]);
            }
            return null;
          }
          // Otherwise, this is a new CAS produced within this Aggregate. We may or
          // may not return it, depending on the setting of the outputsNewCASes operational
          // property in this AE's metadata, and on the value of FinalStep.forceCasToBeDropped
          if (mOutputNewCASes && !finalStep.getForceCasToBeDropped()) {
            return cas;
          } else {
            cas.release();
          }
        }
View Full Code Here

     *
     * @see org.apache.uima.flow.Flow#next()
     */
    public Step next() throws AnalysisEngineProcessException {
      if (currentStep >= mSequence.length) {
        return new FinalStep(); // this CAS has finished the sequence
      }
      // If CAS was segmented, do not continue with flow. The individual segments
      // are processed further but the original CAS is not.
      if (wasSegmented) {
        return new FinalStep(internallyCreatedCas);
      }

      // otherwise, we just send the CAS to the next AE in sequence.
      return new SimpleStep(mSequence[currentStep++]);
    }
View Full Code Here

TOP

Related Classes of org.apache.uima.flow.FinalStep

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.