Package org.apache.uima.analysis_engine

Examples of org.apache.uima.analysis_engine.ResultSpecification


    // do proper typecasts and call process method
    try {
      if (mAnnotator instanceof TextAnnotator) {
        CAS cas = (CAS) aCAS;
        ResultSpecification rs = getResultSpecForLanguage(cas.getDocumentLanguage());
        rs.setTypeSystem(cas.getTypeSystem());
        ((TextAnnotator) mAnnotator).process(cas, rs);
      } else if (mAnnotator instanceof JTextAnnotator) {
        JCas jcas = (JCas) aCAS;
        ResultSpecification rs = getResultSpecForLanguage(jcas.getDocumentLanguage());
        rs.setTypeSystem(jcas.getTypeSystem());
        ((JTextAnnotator) mAnnotator).process(jcas, rs);
      } else if (mAnnotator instanceof GenericAnnotator) {
        mDefaultResultSpecification.setTypeSystem(((CAS) aCAS).getTypeSystem());
        ((GenericAnnotator) mAnnotator).process((CAS) aCAS, mDefaultResultSpecification);
      }
View Full Code Here


   * @param language
   * @return the ResultSpecification for the language
   */
  private ResultSpecification getResultSpecForLanguage(String language) {
    // we cache this since it is called for each document
    ResultSpecification rs = (ResultSpecification) mLanguageToResultSpecMap.get(language);
    if (rs == null) {
      TypeOrFeature[] tofs = mDefaultResultSpecification.getResultTypesAndFeatures(language);
      if (tofs.length > 0) {
        rs = UIMAFramework.getResourceSpecifierFactory().createResultSpecification();
        rs.setResultTypesAndFeatures(tofs);
      } else {
        // special case: if annotator lists no outputs for this language, call it
        // with the actual result spec, set up by language.
    
        // An earlier version of this comment erroneously asserted
View Full Code Here

   */
  protected List<AnalysisSequenceCapabilityNode> computeSequence(String language, Capability[] aCapabilities) {
    language = Language.normalize(language)// lower-cases, replaces _ with -, changes null to x-unspecified

    // create resultSpec from the current aggregate capabilities
    ResultSpecification aggrResultsToProduce = UIMAFramework.getResourceSpecifierFactory()
            .createResultSpecification();

    if (aCapabilities != null) {
      aggrResultsToProduce.addCapabilities(aCapabilities);
    } else {
      return null;
    }

    // create array list for the current sequence
    List<AnalysisSequenceCapabilityNode> newSequence = new ArrayList<AnalysisSequenceCapabilityNode>();

    // loop over all annotators that should be called
    // In this loop we will gradually reduce the set of output capabilities
    for (int sequenceIndex = 0; sequenceIndex < mStaticSequence.size(); sequenceIndex++) {
      // get array of output capabilities for the current language from the current result spec
      TypeOrFeature[] tofsNeeded = aggrResultsToProduce.getResultTypesAndFeatures(language);

      // Augment these outputCapabilities if the language-spec is for a country, to
      // include the outputCapabilities for the language without the country-spec.
     
      // strip language extension if available
      int index = language.indexOf(LANGUAGE_SEPARATOR);

      // if country extension is available
      if (index >= 0) {
        // create Set for outputSpecs, so we can eliminate duplicates
        Set<TypeOrFeature> outputSpec = new HashSet<TypeOrFeature>();

        // add language with country extension removed,
        // to the existing output capabilities (or if non exist, just use
        // the capabilities for the language without the country extension)
        if (tofsNeeded.length > 0) {
          // copy all existing capabilities to the Set
          for (TypeOrFeature outputCapability : tofsNeeded) {
            outputSpec.add(outputCapability);
          }

          // get array of output capabilities only for the language without country extension
          tofsNeeded = aggrResultsToProduce.getResultTypesAndFeatures(language.substring(0, index));

          // add language output capabilities to the Set
          for (TypeOrFeature outputCapability : tofsNeeded) {
            outputSpec.add(outputCapability);
          }

          // convert all output capabilities to a outputCapabilities array
          tofsNeeded = new TypeOrFeature[outputSpec.size()];
          outputSpec.toArray(tofsNeeded);
        } else { // for language with country extension was noting found       
          // get array of output capabilities with the new main language without country extension
          tofsNeeded = aggrResultsToProduce.getResultTypesAndFeatures(language.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 capabilities from the current result spec

      // get next analysis engine from the sequence node
      node = mStaticSequence.get(sequenceIndex);

      // get capability container from the current analysis engine
      ResultSpecification delegateProduces = node.getCapabilityContainer();

      // create current analysis result spec without any language information
      currentAnalysisResultSpec = UIMAFramework.getResourceSpecifierFactory()
              .createResultSpecification();

      // check if engine should be called -
      //   loop over all remaining output capabilities of the aggregate's result spec
      //     to see if this component of the aggregate produces that type or feature,
      //     for this language
      for (TypeOrFeature tof : tofsNeeded) {
        if ((tof.isType() && delegateProduces.containsType(tof.getName(), language)) ||
            (!tof.isType() && delegateProduces.containsFeature(tof.getName(), language))) {
//        if (capabilityContainer.hasOutputTypeOrFeature(tof, language, true)) {
          currentAnalysisResultSpec.addResultTypeOrFeature(tof);
          shouldEngineBeCalled = true;
          // remove current ToF from the result spec
          aggrResultsToProduce.removeTypeOrFeature(tof);
View Full Code Here

        // 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);
        }
View Full Code Here

     
      //Check TestAnnotator fields only at the very end of processing,
      //we can't test from the threads themselves since the state of
      //these fields is nondeterministic during the multithreaded processing.
      assertEquals("testing...", TestAnnotator.getLastDocument());
      ResultSpecification lastResultSpec = TestAnnotator.getLastResultSpec();
      ResultSpecification resultSpec = new ResultSpecification_impl(lastResultSpec.getTypeSystem());
      resultSpec.addResultType("NamedEntity", true);
      assertEquals(resultSpec, lastResultSpec);

    } catch (Exception e) {
      JUnitExtension.handleException(e);
    }
View Full Code Here

         
      //Check TestAnnotator fields only at the very end of processing,
      //we can't test from the threads themselves since the state of
      //these fields is nondeterministic during the multithreaded processing.
      assertEquals("testing...", SimpleCasGenerator.getLastDocument());
      ResultSpecification lastResultSpec = SimpleCasGenerator.getLastResultSpec();
      ResultSpecification resultSpec = new ResultSpecification_impl(lastResultSpec.getTypeSystem());
      resultSpec.addResultType("NamedEntity", true);
      assertEquals(resultSpec, lastResultSpec);

    } catch (Exception e) {
      JUnitExtension.handleException(e);
    }
View Full Code Here

    tae.process(tcas);
    assertEquals("new test", TestAnnotator.lastDocument);
    tcas.reset();

    // process(CAS,ResultSpecification)
    ResultSpecification resultSpec = new ResultSpecification_impl(tcas.getTypeSystem());
    resultSpec.addResultType("NamedEntity", true);

    tcas.setDocumentText("testing...");
    tae.process(tcas, resultSpec);
    assertEquals("testing...", TestAnnotator.lastDocument);
    assertEquals(resultSpec, TestAnnotator.lastResultSpec);
View Full Code Here

        tcas.setDocumentText("new test");
        mAE.process(tcas);
        tcas.reset();

        // process(CAS,ResultSpecification)
        ResultSpecification resultSpec = new ResultSpecification_impl(tcas.getTypeSystem());
        resultSpec.addResultType("NamedEntity", true);

        tcas.setDocumentText("testing...");
        mAE.process(tcas, resultSpec);
        tcas.reset();
View Full Code Here

          tcas.setDocumentText("new test");
          mAE.process(tcas);
          tcas.reset();
 
          // process(CAS,ResultSpecification)
          ResultSpecification resultSpec = new ResultSpecification_impl(tcas.getTypeSystem());
          resultSpec.addResultType("NamedEntity", true);
 
          tcas.setDocumentText("testing...");
          mAE.process(tcas, resultSpec);
          tcas.reset();
        }
View Full Code Here

            rsFromOutputCapabilities.addCapabilities(this.getAnalysisEngineMetaData().getCapabilities());
          }
          // the actual ResultSpec we send to the component is formed by
          // looking at this primitive AE's declared output types and eliminating
          // any that are not in mCurrentResultSpecification.
          ResultSpecification analysisComponentResultSpec =
            ((ResultSpecification_impl)mCurrentResultSpecification).intersect((ResultSpecification_impl)rsFromOutputCapabilities);
          mAnalysisComponent.setResultSpecification(analysisComponentResultSpec);
          mResultSpecChanged = false;
        }
      
View Full Code Here

TOP

Related Classes of org.apache.uima.analysis_engine.ResultSpecification

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.