Package org.apache.uima.collection

Examples of org.apache.uima.collection.CasConsumerDescription


  public static String makeCasConsumer(String descFileName, boolean shouldCrash,
          String functionName, int errorCount, String exceptionName) throws Exception {

    XMLInputSource in = new XMLInputSource(descFileName);
    CasConsumerDescription ccd = UIMAFramework.getXMLParser().parseCasConsumerDescription(in);
    // set the function to crash, if desired
    if (shouldCrash) {
      ccd.getCasConsumerMetaData().getConfigurationParameterSettings().setParameterValue(
              "ErrorFunction", functionName);
      ccd.getCasConsumerMetaData().getConfigurationParameterSettings().setParameterValue(
              "ErrorCount", Integer.valueOf(errorCount));
      ccd.getCasConsumerMetaData().getConfigurationParameterSettings().setParameterValue(
              "ErrorException", exceptionName);
    }
    File baseDir = JUnitExtension.getFile("CpmTests" + FS + "CpeDesc");

    if (!baseDir.exists()) {
View Full Code Here


      String testDescXml = writer.getBuffer().toString();
      // System.out.println(testDescXml);

      // parse objects from XML (no schema validation)
      InputStream is = new ByteArrayInputStream(testDescXml.getBytes(encoding));
      CasConsumerDescription newDesc = (CasConsumerDescription) UIMAFramework.getXMLParser().parse(
              new XMLInputSource(is, null));

      // compare
      Assert.assertEquals(mTestDesc, newDesc);
    } catch (Exception e) {
View Full Code Here

      // serialize objects to byte array

      byte[] testDescBytes = SerializationUtils.serialize(mTestDesc);

      // deserialize
      CasConsumerDescription newDesc = (CasConsumerDescription) SerializationUtils
              .deserialize(testDescBytes);

      Assert.assertEquals(mTestDesc, newDesc);
    } catch (Exception e) {
      JUnitExtension.handleException(e);
View Full Code Here

   *      org.apache.uima.resource.ResourceSpecifier, java.util.Map)
   */
  public Resource produceResource(Class<? extends Resource> aResourceClass, ResourceSpecifier aSpecifier,
          Map<String, Object> aAdditionalParams) throws ResourceInitializationException {
    if (aSpecifier instanceof CasConsumerDescription) {
      CasConsumerDescription desc = (CasConsumerDescription) aSpecifier;

      final String frameworkImpl = desc.getFrameworkImplementation();
      if (frameworkImpl == null || frameworkImpl.length() == 0) {
        throw new ResourceInitializationException(
                ResourceInitializationException.MISSING_FRAMEWORK_IMPLEMENTATION,
                new Object[] { aSpecifier.getSourceUrlString() });
      }

      if (frameworkImpl.startsWith(Constants.JAVA_FRAMEWORK_NAME)) {
        String className = desc.getImplementationName();
        if (className == null || className.length() == 0) {
          throw new ResourceInitializationException(
                  ResourceInitializationException.MISSING_IMPLEMENTATION_CLASS_NAME,
                  new Object[] { aSpecifier.getSourceUrlString() });
        }

        // load class using UIMA Extension ClassLoader if there is one
        ClassLoader cl = null;
        Class<?> implClass = null;
        ResourceManager resourceManager = null;
        if (aAdditionalParams != null) {
          resourceManager = (ResourceManager) aAdditionalParams
                  .get(Resource.PARAM_RESOURCE_MANAGER);
        }
        if (resourceManager != null) {
          cl = resourceManager.getExtensionClassLoader();
        }
        if (cl == null) {
          cl = this.getClass().getClassLoader();
        }
        try {
          implClass = Class.forName(className, true, cl);
        } catch (ClassNotFoundException e) {
          throw new ResourceInitializationException(
                  ResourceInitializationException.CLASS_NOT_FOUND, new Object[] { className,
                      aSpecifier.getSourceUrlString() }, e);
        }

        // check to see if this is a subclass of Cas[Data]Consumer and of aResourceClass
        if (!CasConsumer.class.isAssignableFrom(implClass)
                && !CasDataConsumer.class.isAssignableFrom(implClass)) {
          throw new ResourceInitializationException(
                  ResourceInitializationException.NOT_A_CAS_CONSUMER, new Object[] { className,
                      aSpecifier.getSourceUrlString() });
        }
        if (!aResourceClass.isAssignableFrom(implClass)) {
          throw new ResourceInitializationException(
                  ResourceInitializationException.RESOURCE_DOES_NOT_IMPLEMENT_INTERFACE,
                  new Object[] { className, aResourceClass.getName(),
                      aSpecifier.getSourceUrlString() });
        }

        // instantiate this Resource Class
        Resource resource;
        try {
          resource = (Resource) implClass.newInstance();
        } catch (InstantiationException e) {
          throw new ResourceInitializationException(
                  ResourceInitializationException.COULD_NOT_INSTANTIATE, new Object[] { className,
                      aSpecifier.getSourceUrlString() }, e);
        } catch (IllegalAccessException e) {
          throw new ResourceInitializationException(
                  ResourceInitializationException.COULD_NOT_INSTANTIATE, new Object[] { className,
                      aSpecifier.getSourceUrlString() }, e);
        }
        // attempt to initialize it
        if (resource.initialize(aSpecifier, aAdditionalParams)) {
          // success!
          return resource;
        } else
        // failure, for some unknown reason :( This isn't likely to happen
        {
          throw new ResourceInitializationException(
                  ResourceInitializationException.ERROR_INITIALIZING_FROM_DESCRIPTOR, new Object[] {
                      className, aSpecifier.getSourceUrlString() });
        }
      } else if (frameworkImpl.startsWith(Constants.CPP_FRAMEWORK_NAME)) {
        Resource resource = new UimacppAnalysisEngineImpl();
        if (resource.initialize(aSpecifier, aAdditionalParams)) {
          // success!
          return resource;
        } else
        // failure, for some unknown reason :( This isn't likely to happen
        {
          throw new ResourceInitializationException(
                  ResourceInitializationException.ERROR_INITIALIZING_FROM_DESCRIPTOR, new Object[] {
                      UimacppAnalysisComponent.class.getName(), aSpecifier.getSourceUrlString() });
        }
      } else {
        throw new ResourceInitializationException(
                ResourceInitializationException.UNSUPPORTED_FRAMEWORK_IMPLEMENTATION, new Object[] {
                    desc.getFrameworkImplementation(), aSpecifier.getSourceUrlString() });
      }
    } else {
      return null;
    }
  }
View Full Code Here

  protected void setUp() throws Exception {
    ccFactory = new CasConsumerFactory_impl();
  }

  public void testInvalidFrameworkImplementation() {
    CasConsumerDescription desc = new CasConsumerDescription_impl();
    desc.setFrameworkImplementation("foo");   
    try {
      ccFactory.produceResource(CasConsumer.class, desc, Collections.EMPTY_MAP);
      fail();
    } catch (ResourceInitializationException e) {
      assertNotNull(e.getMessage());
View Full Code Here

      XMLInputSource in = new XMLInputSource(aeSpecifierFile);
      ResourceSpecifier aeSpecifier = UIMAFramework.getXMLParser().parseResourceSpecifier(in);

      // create and configure CAS consumer that will write the output (in
      // XMI format)
      CasConsumerDescription casConsumerDesc = XmiWriterCasConsumer.getDescription();
      ConfigurationParameterSettings consumerParamSettings = casConsumerDesc.getMetaData()
              .getConfigurationParameterSettings();
      consumerParamSettings.setParameterValue(XmiWriterCasConsumer.PARAM_OUTPUTDIR, outputDir
              .getAbsolutePath());
      // declare uima.cas.TOP as an input so that ResultSpec on user's AE will be set to produce all
      // 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) {
View Full Code Here

                        Messages.getString("MultiPageEditor.failedCasInitValidationMsg") + "\n" + getMessagesToRootCause(e), //$NON-NLS-1$ //$NON-NLS-2$
                        MessageDialog.ERROR);
        return false;
      }
    } else if (isCasConsumerDescriptor()) {
      CasConsumerDescription casCons = (CasConsumerDescription) casConsumerDescription.clone();
      try {
        casCons.doFullValidation(createResourceManager());
      } catch (Throwable e) {
        Utility
                .popMessage(
                        Messages.getString("MultiPageEditor.failedCasConsValidation"), //$NON-NLS-1$
                        Messages.getString("MultiPageEditor.failedCasConsValidationMsg") + "\n" + getMessagesToRootCause(e), //$NON-NLS-1$ //$NON-NLS-2$
View Full Code Here

      ResourceManager resMgr = UIMAFramework.newDefaultResourceManager();
      resMgr.setDataPath(dataPath);

      if (specifier instanceof CasConsumerDescription) {
        cc = UIMAFramework.produceCasConsumer(specifier);
        CasConsumerDescription ccdesc = (CasConsumerDescription) specifier;
        Capability[] capabilities = ccdesc.getCasConsumerMetaData().getCapabilities();
        for (int i = 0; i < capabilities.length; i++) {
          String[] inputsofas = capabilities[i].getInputSofas();
          if (inputsofas.length > 0)
            requiresTCas = false;
        }
View Full Code Here

        StringWriter writer = new StringWriter();
        aeSpecifier.toXML(writer);

        return writer.toString();
      } else if (specifier instanceof CasConsumerDescription) {
        CasConsumerDescription ccSpecifier = (CasConsumerDescription) specifier;
        ccSpecifier.getCasConsumerMetaData().resolveImports(resMgr);
        StringWriter writer = new StringWriter();
        ccSpecifier.toXML(writer);
        return writer.toString();
      }
    } catch (UnsupportedEncodingException e) {
      logException(e);
    } catch (InvalidXMLException e) {
View Full Code Here

      rm.setDataPath(TEST_DATAPATH);
      rm.setExtensionClassPath(TEST_EXTENSION_CLASSPATH, true);

      // create a UimaContext with Config Params and Resources
      UIMAFramework.getXMLParser().enableSchemaValidation(true);
      CasConsumerDescription ccDesc = UIMAFramework.getXMLParser().parseCasConsumerDescription(
              new XMLInputSource(JUnitExtension
                      .getFile("UimaContextTest/CasConsumerForUimaContextTest.xml")));
      CasConsumer cc = UIMAFramework.produceCasConsumer(ccDesc, rm, null);
      mContext = cc.getUimaContext();
View Full Code Here

TOP

Related Classes of org.apache.uima.collection.CasConsumerDescription

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.