Package org.apache.uima.analysis_engine

Examples of org.apache.uima.analysis_engine.AnalysisEngineDescription


  }
  public void testDefaultingOperationalParameters() throws Exception {
    XMLInputSource in = new XMLInputSource(JUnitExtension
            .getFile("TextAnalysisEngineImplTest/TestPrimitiveOperationalParmsDefaults.xml"));
    AnalysisEngineDescription desc = UIMAFramework.getXMLParser().parseAnalysisEngineDescription(in);
    OperationalProperties opProps = desc.getAnalysisEngineMetaData().getOperationalProperties();
    assertNotNull(opProps);
    assertEquals(true, opProps.getModifiesCas());
    assertEquals(false, opProps.isMultipleDeploymentAllowed());
  }
View Full Code Here


      byte[] primitiveDescBytes = SerializationUtils.serialize(primitiveDesc);
      byte[] aggregateDescBytes = SerializationUtils.serialize(aggregateDesc);

      // deserialize
      AnalysisEngineDescription newPrimitiveDesc = (AnalysisEngineDescription) SerializationUtils
              .deserialize(primitiveDescBytes);
      AnalysisEngineDescription newAggregateDesc = (AnalysisEngineDescription) SerializationUtils
              .deserialize(aggregateDescBytes);

      Assert.assertEquals(primitiveDesc, newPrimitiveDesc);
      Assert.assertEquals(aggregateDesc, newAggregateDesc);
    } catch (Exception e) {
View Full Code Here

    }
  }

  public void testDelegateImports() throws Exception {
    // create aggregate TAE description and add delegate AE import
    AnalysisEngineDescription testAgg = new AnalysisEngineDescription_impl();
    Map<String, MetaDataObject> delegateMap = testAgg.getDelegateAnalysisEngineSpecifiersWithImports();
    Import_impl delegateImport = new Import_impl();
    delegateImport.setLocation(JUnitExtension.getFile(
            "TextAnalysisEngineImplTest/TestPrimitiveTae1.xml").toURI().toURL().toString());
    delegateMap.put("key", delegateImport);

    // test that import is resolved
    Map<String, ResourceSpecifier> mapWithImportsResolved = testAgg.getDelegateAnalysisEngineSpecifiers();
    assertEquals(1, mapWithImportsResolved.size());
    ResourceSpecifier obj = mapWithImportsResolved.values().iterator().next();
    assertTrue(obj instanceof AnalysisEngineDescription);

    // test that remove works
    delegateMap.remove("key");
    mapWithImportsResolved = testAgg.getDelegateAnalysisEngineSpecifiers();
    assertEquals(0, mapWithImportsResolved.size());

    // test the re-add works
    delegateMap.put("key", delegateImport);
    mapWithImportsResolved = testAgg.getDelegateAnalysisEngineSpecifiers();
    assertEquals(1, mapWithImportsResolved.size());
    obj = mapWithImportsResolved.values().iterator().next();
    assertTrue(obj instanceof AnalysisEngineDescription);

    // serialize to XML, preserving imports
    testAgg.toXML(new StringWriter(), true);

    // verify that imports are still resolved
    mapWithImportsResolved = testAgg.getDelegateAnalysisEngineSpecifiers();
    assertEquals(1, mapWithImportsResolved.size());
    obj = mapWithImportsResolved.values().iterator().next();
    assertTrue(obj instanceof AnalysisEngineDescription);
  }
View Full Code Here

            .getFile("TextAnalysisEngineImplTest/AggregateThatImportsItself.xml"));

    // try some that should work
    XMLInputSource in = new XMLInputSource(JUnitExtension
            .getFile("TextAnalysisEngineImplTest/AggregateTaeWithConfigParamOverrides.xml"));
    AnalysisEngineDescription desc = UIMAFramework.getXMLParser().parseAnalysisEngineDescription(in);
    desc.doFullValidation();
    in = new XMLInputSource(JUnitExtension
            .getFile("AnnotatorContextTest/AnnotatorWithGroupsAndNonGroupParams.xml"));
    desc = UIMAFramework.getXMLParser().parseAnalysisEngineDescription(in);
    desc.doFullValidation();

    // try aggregate containing remote service - should work even if can't connect
    in = new XMLInputSource(JUnitExtension
            .getFile("TextAnalysisEngineImplTest/AggregateWithUnknownRemoteComponent.xml"));
    desc = UIMAFramework.getXMLParser().parseAnalysisEngineDescription(in);
    desc.doFullValidation();

    // try aggregate with sofas
    in = new XMLInputSource(JUnitExtension.getFile("CpeSofaTest/TransAnnotatorAggregate.xml"));
    desc = UIMAFramework.getXMLParser().parseAnalysisEngineDescription(in);
    desc.doFullValidation();

    // try another aggregate with sofas
    in = new XMLInputSource(JUnitExtension
            .getFile("CpeSofaTest/TransAnnotatorAndTestAnnotatorAggregate.xml"));
    desc = UIMAFramework.getXMLParser().parseAnalysisEngineDescription(in);
    desc.doFullValidation();

    // try primitive with duplicate configuration group definitions
    in = new XMLInputSource(JUnitExtension
            .getFile("TextAnalysisEngineImplTest/AnnotatorWithDuplicateConfigurationGroups.xml"));
    desc = UIMAFramework.getXMLParser().parseAnalysisEngineDescription(in);
    desc.doFullValidation();

    // try aggregate with duplicate configuration group definitions
    in = new XMLInputSource(JUnitExtension
            .getFile("TextAnalysisEngineImplTest/AggregateWithDuplicateGroupOverrides.xml"));
    desc = UIMAFramework.getXMLParser().parseAnalysisEngineDescription(in);
    desc.doFullValidation();
   
    //test aggregate with import by name and configuration parameter overrides
    in = new XMLInputSource(JUnitExtension
            .getFile("TextAnalysisEngineImplTest/AeWithConfigParamOverridesAndImportByName.xml"));
    desc = UIMAFramework.getXMLParser().parseAnalysisEngineDescription(in);
    ResourceManager resMgr = UIMAFramework.newDefaultResourceManager();
    File dataPathDir = JUnitExtension.getFile("TextAnalysisEngineImplTest/dataPathDir");
    resMgr.setDataPath(dataPathDir.getCanonicalPath());
    desc.doFullValidation(resMgr);
   
    //test UIMA C++ descriptor (should succeed even though annotator library doesn't exist)
    in = new XMLInputSource(JUnitExtension
            .getFile("TextAnalysisEngineImplTest/TestUimaCppAe.xml"));
    desc = UIMAFramework.getXMLParser().parseAnalysisEngineDescription(in);
    desc.doFullValidation();
   
    in = new XMLInputSource(JUnitExtension
            .getFile("TextAnalysisEngineImplTest/TestAggregateContainingCppAnnotator.xml"));
    desc = UIMAFramework.getXMLParser().parseAnalysisEngineDescription(in);
    desc.doFullValidation();   
  }
View Full Code Here

 
  public void testValidate() throws Exception {
    //test aggregate with import by name and configuration parameter overrides
    XMLInputSource in = new XMLInputSource(JUnitExtension
            .getFile("TextAnalysisEngineImplTest/AeWithConfigParamOverridesAndImportByName.xml"));
    AnalysisEngineDescription desc = UIMAFramework.getXMLParser().parseAnalysisEngineDescription(in);
    ResourceManager resMgr = UIMAFramework.newDefaultResourceManager();
    File dataPathDir = JUnitExtension.getFile("TextAnalysisEngineImplTest/dataPathDir");
    resMgr.setDataPath(dataPathDir.getCanonicalPath());
    desc.validate(resMgr);
   
    //test invalid aggregate with undefined key in flow
    in = new XMLInputSource(JUnitExtension
            .getFile("TextAnalysisEngineImplTest/InvalidAggregate_UndefinedKeyInFlow.xml"));
    desc = UIMAFramework.getXMLParser().parseAnalysisEngineDescription(in);
    try {
      desc.validate()
      fail();
    }
    catch(ResourceInitializationException e) {
      //e.printStackTrace();
      assertEquals(ResourceInitializationException.UNDEFINED_KEY_IN_FLOW, e.getMessageKey());
View Full Code Here

            aeInputSource);

    AnalysisEnginePanel aePanel = new AnalysisEnginePanel(aeSpecifier, f, fileModStamp);
    String tabName;
    if (aeSpecifier instanceof AnalysisEngineDescription) {
      AnalysisEngineDescription aeDescription = (AnalysisEngineDescription) aeSpecifier;
      ResourceMetaData md = aeDescription.getMetaData();
      aePanel.populate(md, cpeCasProc.getConfigurationParameterSettings());
      tabName = md.getName();
    } else {
      tabName = f.getName();
    }
View Full Code Here

      // types
      casConsumerDesc.getCasConsumerMetaData().getCapabilities()[0].addInputType("uima.cas.TOP",
              true);

      // if XML tag was specified, also create XmlDetagger annotator that handles this
      AnalysisEngineDescription xmlDetaggerDesc = null;
      if (xmlTag != null && xmlTag.length() > 0) {
        xmlDetaggerDesc = XmlDetagger.getDescription();
        ConfigurationParameterSettings xmlDetaggerParamSettings = xmlDetaggerDesc.getMetaData()
                .getConfigurationParameterSettings();
        xmlDetaggerParamSettings.setParameterValue(XmlDetagger.PARAM_TEXT_TAG, xmlTag);
        usingXmlDetagger = true;
      }
      else {
        usingXmlDetagger = false;
      }
     
      // create an aggregate AE that includes the XmlDetagger (if needed), followed by
      //th user's AE descriptor, followed by the XMI Writer CAS Consumer, using fixed flow.
      // We use an aggregate AE here, rather than just adding the CAS Consumer to the CPE, so
      //that we can support the user's AE being a CAS Multiplier and we can specify sofa mappings.
      AnalysisEngineDescription aggDesc = UIMAFramework.getResourceSpecifierFactory()
              .createAnalysisEngineDescription();
      aggDesc.setPrimitive(false);
      aggDesc.getDelegateAnalysisEngineSpecifiersWithImports().put("UserAE", aeSpecifier);
      aggDesc.getDelegateAnalysisEngineSpecifiersWithImports().put("XmiWriter", casConsumerDesc);
      FixedFlow flow = UIMAFramework.getResourceSpecifierFactory().createFixedFlow();     
           
      if (xmlDetaggerDesc != null) {
        aggDesc.getDelegateAnalysisEngineSpecifiersWithImports().put("XmlDetagger", xmlDetaggerDesc);
        flow.setFixedFlow(new String[] {"XmlDetagger", "UserAE", "XmiWriter"});
       
        //to run XmlDetagger we need sofa mappings
        //XmlDetagger's "xmlDocument" input sofa gets mapped to the default sofa
        SofaMapping sofaMapping1 = UIMAFramework.getResourceSpecifierFactory().createSofaMapping();
        sofaMapping1.setComponentKey("XmlDetagger");
        sofaMapping1.setComponentSofaName("xmlDocument");
        sofaMapping1.setAggregateSofaName(CAS.NAME_DEFAULT_SOFA);
       
        //for UserAE and XmiWriter, may default sofa to the "plainTextDocument" produced by the XmlDetagger
        SofaMapping sofaMapping2 = UIMAFramework.getResourceSpecifierFactory().createSofaMapping();
        sofaMapping2.setComponentKey("UserAE");
        sofaMapping2.setAggregateSofaName("plainTextDocument");
        SofaMapping sofaMapping3 = UIMAFramework.getResourceSpecifierFactory().createSofaMapping();
        sofaMapping3.setComponentKey("XmiWriter");
        sofaMapping3.setAggregateSofaName("plainTextDocument");
               
        aggDesc.setSofaMappings(new SofaMapping[] {sofaMapping1, sofaMapping2, sofaMapping3});
      }
      else {
        //no XML detagger needed in the aggregate in flow
        flow.setFixedFlow(new String[] { "UserAE", "XmiWriter" });         
      }

     
      aggDesc.getAnalysisEngineMetaData().setName("DocumentAnalyzerAE");
      aggDesc.getAnalysisEngineMetaData().setFlowConstraints(flow);
      aggDesc.getAnalysisEngineMetaData().getOperationalProperties().setMultipleDeploymentAllowed(
              false);           
      progressMonitor.setProgress(1);

      // instantiate AE
      // keep this a local variable - so it doesn't hang on to the ae object
View Full Code Here

          XMLInputSource in = new XMLInputSource(url);
          XMLizable specifier = UIMAFramework.getXMLParser().parse(in);

          mergedTypesAddingFeatures.clear();
          if (specifier instanceof AnalysisEngineDescription) {
            AnalysisEngineDescription aeSpecifier = (AnalysisEngineDescription) specifier;
            if (!aeSpecifier.isPrimitive())
              typeSystemDescription = CasCreationUtils.mergeDelegateAnalysisEngineTypeSystems(
                      aeSpecifier, createResourceManager(), mergedTypesAddingFeatures);
            else
              typeSystemDescription = mergeTypeSystemImports(aeSpecifier
                      .getAnalysisEngineMetaData().getTypeSystem());

          } else if (specifier instanceof TypeSystemDescription)
            typeSystemDescription = mergeTypeSystemImports(((TypeSystemDescription) specifier));
          else {
View Full Code Here

        // get Resource Specifier from XML file
        URL url = this.getClass().getResource(aeFilePath);
        XMLInputSource in = new XMLInputSource(url);

        // get AE description
        AnalysisEngineDescription desc = UIMAFramework.getXMLParser()
                .parseAnalysisEngineDescription(in);

        /* iterate over each AE (to set runtime parameters) */
        for (String attributeName : runtimeParameters.keySet()) {
          Object val = getRuntimeValue(desc, attributeName);
          desc.getAnalysisEngineMetaData().getConfigurationParameterSettings().setParameterValue(
                  attributeName, val);
          if (log.isDebugEnabled())
            log.debug(new StringBuilder("setting ").append(attributeName).append(" : ").append(
                  runtimeParameters.get(attributeName)).toString());
        }
View Full Code Here

      UimaContextAdmin uctx = getUimaContextAdmin();

      // retrieve the sofa mappings for input/output sofas of this analysis engine
      HashMap sofamap = new HashMap();
      if (resourceSpecifier instanceof AnalysisEngineDescription) {
        AnalysisEngineDescription desc = (AnalysisEngineDescription) resourceSpecifier;
        SofaMapping[] sofaMappings = desc.getSofaMappings();
        if (sofaMappings != null && sofaMappings.length > 0) {
          for (int s = 0; s < sofaMappings.length; s++) {
            // the mapping is for this analysis engine
            if (sofaMappings[s].getComponentKey().equals(key)) {
              // if component sofa name is null, replace it with
View Full Code Here

TOP

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

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.