Package org.apache.uima.resource

Examples of org.apache.uima.resource.ResourceInitializationException


    }
    else if (value instanceof Boolean) {
      return (Boolean) value;
    }
    else {
      throw new ResourceInitializationException(
          ResourceInitializationException.STANDARD_MESSAGE_CATALOG,
          new Object[] {"The parameter: "  + parameter + " does not have" +
          "the expected type Boolean"});
    }
  }
View Full Code Here


   * @throws ResourceInitializationException - if type does not match
   */
  public static void checkFeatureType(Feature feature, String expectedType)
  throws ResourceInitializationException {
    if (!feature.getRange().getName().equals(expectedType)) {
      throw new ResourceInitializationException(
          ResourceInitializationException.STANDARD_MESSAGE_CATALOG,
          new Object[] { "The Feature " + feature.getName() +
              " must be of type " + expectedType + " !"
          });
    }
View Full Code Here

    // do validation common to all descriptor types (e.g. config parameters)
    super.validate(aResourceManager);

    // TypeSystem may not be specified for an Aggregate Analysis Engine
    if (!isPrimitive() && getAnalysisEngineMetaData().getTypeSystem() != null) {
      throw new ResourceInitializationException(
              ResourceInitializationException.AGGREGATE_AE_TYPE_SYSTEM,
              new Object[] { getSourceUrlString() });
    }
   
    //Keys in FixedFlow or LanguageCapabilityFlow must be defined
    FlowConstraints fc = getAnalysisEngineMetaData().getFlowConstraints();
    String[] keys = null;
    if (fc instanceof FixedFlow) {
      keys = ((FixedFlow)fc).getFixedFlow();
    }
    else if (fc instanceof CapabilityLanguageFlow) {
      keys = ((CapabilityLanguageFlow)fc).getCapabilityLanguageFlow();
    }
    if (keys != null) {
      for (int i = 0; i < keys.length; i++) {
        if (!getDelegateAnalysisEngineSpecifiersWithImports().containsKey(keys[i])) {
          throw new ResourceInitializationException(ResourceInitializationException.UNDEFINED_KEY_IN_FLOW,
                  new Object[]{getAnalysisEngineMetaData().getName(), keys[i], getSourceUrlString()});
        }
      }
    }
  }
View Full Code Here

          String aGroupName, ResourceManager aResourceManager) throws ResourceInitializationException {
    //make sure delegate analysis engine specifiers are resolved using the correct resource manager
    try {
      resolveImports(aResourceManager);
    } catch (InvalidXMLException e) {
      throw new ResourceInitializationException(e);
    }
   
    for (int i = 0; i < aParams.length; i++) {
      String[] overrides = aParams[i].getOverrides();
      if (overrides.length > 0 && isPrimitive()) {
        throw new ResourceInitializationException(
                ResourceInitializationException.PARAM_OVERRIDE_IN_PRIMITIVE, new Object[] {
                    aParams[i].getName(), getMetaData().getName(), getSourceUrlString() });
      } else if (overrides.length == 0 && !isPrimitive()) {
        // Were deprecated for many years ... now no longer supported.
        throw new ResourceInitializationException(
                ResourceInitializationException.INVALID_PARAM_OVERRIDE_NO_OVERRIDES, new Object[] {
                    aParams[i].getName(), getMetaData().getName(), getSourceUrlString() });
      }
      for (int j = 0; j < overrides.length; j++) {
        // overrides should be of form delegateKey/paramName
        int slashPos = overrides[j].indexOf('/');
        if (slashPos <= 0 || slashPos >= overrides[j].length()) {
          throw new ResourceInitializationException(
                  ResourceInitializationException.INVALID_PARAM_OVERRIDE_SYNTAX, new Object[] {
                      overrides[j], aParams[i].getName(), getMetaData().getName(),
                      getSourceUrlString() });
        }
        String delegateKey = overrides[j].substring(0, slashPos);
        String paramName = overrides[j].substring(slashPos + 1);
        // get component descriptor (could be an AE or could be the FlowController)
        ResourceSpecifier componentSpecifier = getComponentSpecifier(delegateKey);
        if (componentSpecifier == null) {
          throw new ResourceInitializationException(
                  ResourceInitializationException.INVALID_PARAM_OVERRIDE_NONEXISTENT_DELEGATE,
                  new Object[] { overrides[j], aParams[i].getName(), getMetaData().getName(),
                      delegateKey, getSourceUrlString() });
        }
        if (componentSpecifier instanceof ResourceCreationSpecifier) {
          ConfigurationParameter overriddenParam = null;
          ConfigurationParameterDeclarations delegateParamDecls = ((ResourceCreationSpecifier) componentSpecifier)
                  .getMetaData().getConfigurationParameterDeclarations();
          if (aGroupName == null) // param not in group
          {
            overriddenParam = delegateParamDecls.getConfigurationParameter(null, paramName);
            if (overriddenParam == null) {
              throw new ResourceInitializationException(
                      ResourceInitializationException.INVALID_PARAM_OVERRIDE_NONEXISTENT_PARAMETER,
                      new Object[] { overrides[j], aParams[i].getName(), getMetaData().getName(),
                          delegateKey, paramName, getSourceUrlString() });

            }
          } else {
            // make sure parameter exists in group
            overriddenParam = delegateParamDecls.getConfigurationParameter(aGroupName, paramName);
            if (overriddenParam == null) {
              throw new ResourceInitializationException(
                      ResourceInitializationException.INVALID_PARAM_OVERRIDE_NONEXISTENT_PARAMETER_IN_GROUP,
                      new Object[] { overrides[j], aParams[i].getName(), getMetaData().getName(),
                          delegateKey, paramName, aGroupName, getSourceUrlString() });
            }
          }
View Full Code Here

    if (getFlowControllerDeclaration() != null
            && key.equals(getFlowControllerDeclaration().getKey())) {
      try {
        getFlowControllerDeclaration().resolveImports();
      } catch (InvalidXMLException e) {
        throw new ResourceInitializationException(e);
      }
      componentSpecifier = getFlowControllerDeclaration().getSpecifier();
    } else {
      try {
        componentSpecifier = (ResourceSpecifier) getDelegateAnalysisEngineSpecifiers().get(key);
      } catch (InvalidXMLException e) {
        throw new ResourceInitializationException(e);
      }
    }
    return componentSpecifier;
  }
View Full Code Here

    if (sofaMappings != null) {
      for (int s = 0; s < sofaMappings.length; s++) {
        String componentKey = sofaMappings[s].getComponentKey();
        ResourceSpecifier componentSpec = getComponentSpecifier(componentKey);
        if (componentSpec == null) {
          throw new ResourceInitializationException(
                  ResourceInitializationException.SOFA_MAPPING_HAS_UNDEFINED_COMPONENT_KEY,
                  new Object[] { componentKey, sofaMappings[s].getAggregateSofaName(), aggName,
                      getSourceUrlString() });
        }
        String componentSofaName = sofaMappings[s].getComponentSofaName();
        if (componentSofaName == null) {
          componentSofaName = CAS.NAME_DEFAULT_SOFA;
        } else if (componentSpec instanceof AnalysisEngineDescription
                && !CAS.NAME_DEFAULT_SOFA.equals(componentSofaName)
                && !declaresSofa((AnalysisEngineDescription) componentSpec, componentSofaName)) {
          throw new ResourceInitializationException(
                  ResourceInitializationException.SOFA_MAPPING_HAS_UNDEFINED_COMPONENT_SOFA,
                  new Object[] { componentKey, componentSofaName,
                      sofaMappings[s].getAggregateSofaName(), aggName, getSourceUrlString() });
        }

        String compoundKey = sofaMappings[s].getComponentKey() + "@/@"
                + sofaMappings[s].getComponentSofaName();
        String aggSofaName = sofaMappings[s].getAggregateSofaName();
        // check for double-mapping
        String existingMapping = (String) sofamap.get(compoundKey);
        if (existingMapping != null && !existingMapping.equals(aggSofaName)) {
          throw new ResourceInitializationException(
                  ResourceInitializationException.SOFA_MAPPING_CONFLICT, new Object[] {
                      sofaMappings[s].getComponentSofaName(), sofaMappings[s].getComponentKey(),
                      aggName, existingMapping, aggSofaName, getSourceUrlString() });
        } else {
          sofamap.put(compoundKey, aggSofaName);
        }
      }
    }

    // Rules for SofAs:
    // (1) Each component output sofa must be mapped to an aggregate output sofa
    // (2) Each aggregate output sofa must be mapped to a component output sofa
    // (3) Each component input sofa must be mapped to an aggregate input sofa OR a component output
    // sofa
    // (4) Each aggregate input sofa must be mapped to a component input sofa

    // From (1) and (3) we derive that:
    // Each component input sofa must be mapped to an aggregate input sofa OR an aggregate output
    // sofa
    // (which is easier to check)

    // Exception: if aggregate contains a remote component, we cannot check that remote
    // component's input or output sofas, so rules (2) and (4) cannot be checked.

    boolean containsRemote = false;
    Set<String> correctlyMappedAggregateOutputs = new HashSet<String>();
    Set<String> correctlyMappedAggregateInputs = new HashSet<String>();

    Iterator<Map.Entry<String, ResourceSpecifier>> iter;
    try {
      iter = getDelegateAnalysisEngineSpecifiers().entrySet().iterator();
    } catch (InvalidXMLException e) {
      throw new ResourceInitializationException(e);
    }
    while (iter.hasNext()) {
      Map.Entry<String, ResourceSpecifier> entry = iter.next();
      String componentKey = entry.getKey();
      ResourceSpecifier delegateSpec = entry.getValue();

      if (delegateSpec instanceof AnalysisEngineDescription) {
        Capability[] caps = ((AnalysisEngineDescription) delegateSpec).getAnalysisEngineMetaData()
                .getCapabilities();
        for (int i = 0; i < caps.length; i++) {
          // all component output sofas must be mapped to aggregate output sofas
          String[] outputSofas = caps[i].getOutputSofas();
          for (int j = 0; j < outputSofas.length; j++) {
            String aggSofa = (String) sofamap.get(componentKey + "@/@" + outputSofas[j]);
            if (aggSofa == null) // no declared mapping, name remains unchanged
            {
              aggSofa = outputSofas[j];
            }
            if (!capabilitiesContainSofa(aggSofa, true)) {
              throw new ResourceInitializationException(
                      ResourceInitializationException.OUTPUT_SOFA_NOT_DECLARED_IN_AGGREGATE,
                      new Object[] { outputSofas[j], componentKey, aggName, getSourceUrlString() });
            }
            correctlyMappedAggregateOutputs.add(aggSofa);
          }

          // all component input sofas must be mapped to aggregate input OR output sofas
          String[] inputSofas = caps[i].getInputSofas();
          for (int j = 0; j < inputSofas.length; j++) {
            String aggSofa = (String) sofamap.get(componentKey + "@/@" + inputSofas[j]);
            if (aggSofa == null) // no declared mapping, name remains unchanged
            {
              aggSofa = inputSofas[j];
            }
            if (!capabilitiesContainSofa(aggSofa, false) && !capabilitiesContainSofa(aggSofa, true)) {
              throw new ResourceInitializationException(
                      ResourceInitializationException.INPUT_SOFA_HAS_NO_SOURCE, new Object[] {
                          inputSofas[j], componentKey, aggName, getSourceUrlString() });
            }
            correctlyMappedAggregateInputs.add(aggSofa);
          }

          // also check default text sofa
          String aggDefSofa = (String) sofamap.get(componentKey + "@/@" + CAS.NAME_DEFAULT_SOFA);
          if (aggDefSofa != null) {
            if (capabilitiesContainSofa(aggDefSofa, true)) {
              correctlyMappedAggregateOutputs.add(aggDefSofa);
            } else {
              correctlyMappedAggregateInputs.add(aggDefSofa);
            }
          }
        }
      } // delegateSpec is not an AnalysisEngineDescription
      else {
        containsRemote = true;
      }
    }

    if (!containsRemote) {
      // check that all aggregate outputs and inputs were mapped correclty to
      // component inputs/outputs
      Capability[] caps = this.getAnalysisEngineMetaData().getCapabilities();
      for (int i = 0; i < caps.length; i++) {
        String[] sofas = caps[i].getOutputSofas();
        for (int j = 0; j < sofas.length; j++) {
          if (!correctlyMappedAggregateOutputs.contains(sofas[j])) {
            throw new ResourceInitializationException(
                    ResourceInitializationException.AGGREGATE_SOFA_NOT_MAPPED, new Object[] {
                        sofas[j], aggName, getSourceUrlString() });
          }
        }
        sofas = caps[i].getInputSofas();
        for (int j = 0; j < sofas.length; j++) {
          if (!correctlyMappedAggregateInputs.contains(sofas[j])) {
            throw new ResourceInitializationException(
                    ResourceInitializationException.AGGREGATE_SOFA_NOT_MAPPED, new Object[] {
                        sofas[j], aggName, getSourceUrlString() });
          }
        }
      }
View Full Code Here

 
  public void load(DataResource resource) throws ResourceInitializationException {
    try {
        model = loadModel(resource.getInputStream());
    } catch (IOException e) {
        throw new ResourceInitializationException(
          ExceptionMessages.MESSAGE_CATALOG,
          ExceptionMessages.IO_ERROR_MODEL_READING, new Object[] {
            e.getMessage()}, e);
    }
  }
View Full Code Here

            (TokenNameFinderModelResource) context.getResourceObject(UimaUtil.MODEL_PARAMETER);
       
        model = modelResource.getModel();
    }
    catch (ResourceAccessException e) {
        throw new ResourceInitializationException(e);
    }

    Integer beamSize = AnnotatorUtil.getOptionalIntegerParameter(context,
        UimaUtil.BEAM_SIZE_PARAMETER);
View Full Code Here

          .getResourceAsStream(context, modelName);
     
      nameFinderDictionary = new Dictionary(inModel);

    } catch (IOException e) {
      throw new ResourceInitializationException(
        ExceptionMessages.MESSAGE_CATALOG,
        ExceptionMessages.IO_ERROR_DICTIONARY_READING,
        new Object[] {e.getMessage()});
    }
   
View Full Code Here

  }
 
  private static void checkForNull(Object value, String parameterName)
    throws ResourceInitializationException {
    if (value == null) {
      throw new ResourceInitializationException(
        ExceptionMessages.MESSAGE_CATALOG,
        ExceptionMessages.PARAMETER_NOT_FOUND,
          new Object[] {parameterName});
    }
  }
View Full Code Here

TOP

Related Classes of org.apache.uima.resource.ResourceInitializationException

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.