Java Code Examples for org.apache.uima.resource.metadata.TypeDescription#setAllowedValues()

The following examples show how to use org.apache.uima.resource.metadata.TypeDescription#setAllowedValues() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TypeSystemUtil.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Convert a {@link Type} to an equivalent {@link TypeDescription}.
 * 
 * @param aType
 *          type object to convert
 * @param aTypeSystem
 *          the TypeSystem that contains <code>aType</code>
 * @return a TypeDescription that is equivalent to <code>aType</code>
 */
public static TypeDescription type2TypeDescription(Type aType, TypeSystem aTypeSystem) {
  TypeDescription typeDesc = UIMAFramework.getResourceSpecifierFactory().createTypeDescription();
  typeDesc.setName(aType.getName());
  Type superType = aTypeSystem.getParent(aType);
  typeDesc.setSupertypeName(superType.getName());
  // special handling for string subtypes (which have "allowed values", rather than features)
  Type stringType = aTypeSystem.getType("uima.cas.String");
  if (aTypeSystem.subsumes(stringType, aType)) {
    String[] allowedValues = getAllowedValuesForType(aType, aTypeSystem);
    AllowedValue[] avObjs = new AllowedValue[allowedValues.length];
    for (int i = 0; i < allowedValues.length; i++) {
      AllowedValue av = UIMAFramework.getResourceSpecifierFactory().createAllowedValue();
      av.setString(allowedValues[i]);
      avObjs[i] = av;
    }
    typeDesc.setAllowedValues(avObjs);
  } else {
    List<FeatureDescription> featDescs = new ArrayList<>();
    for (Feature feat : aType.getFeatures()){ 
      if (!superType.getFeatures().contains(feat)) {
        featDescs.add(feature2FeatureDescription(feat));
      }
    }
    FeatureDescription[] featDescArr = new FeatureDescription[featDescs.size()];
    featDescs.toArray(featDescArr);
    typeDesc.setFeatures(featDescArr);
  }
  return typeDesc;
}
 
Example 2
Source File: Ecore2UimaTypeSystem.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Eenum 2 uima type.
 *
 * @param aEEnum the a E enum
 * @param aUimaNamespace the a uima namespace
 * @param aOptions the a options
 * @return the type description
 * @throws URISyntaxException the URI syntax exception
 */
private static TypeDescription eenum2UimaType(EEnum aEEnum, String aUimaNamespace, Map aOptions)
        throws URISyntaxException {
  TypeDescription type = uimaFactory.createTypeDescription();
  // set name
  if (aUimaNamespace != null) {
    type.setName(aUimaNamespace + "." + aEEnum.getName());
  } else {
    type.setName(aEEnum.getName());
  }
  // set supetype to String
  type.setSupertypeName(CAS.TYPE_NAME_STRING);
  // try to get desecription from EAnnotation
  EAnnotation eannot = aEEnum.getEAnnotation("http://uima.apache.org");
  if (eannot != null) {
    type.setDescription((String) eannot.getDetails().get("description"));
  }
  // set allowed values
  EList literals = aEEnum.getELiterals();
  AllowedValue[] vals = new AllowedValue[literals.size()];
  for (int i = 0; i < literals.size(); i++) {
    EEnumLiteral literal = (EEnumLiteral) literals.get(i);
    vals[i] = uimaFactory.createAllowedValue();
    vals[i].setString(literal.getName());
    EAnnotation literalAnnot = literal.getEAnnotation("http://uima.apache.org");
    if (literalAnnot != null) {
      vals[i].setDescription((String) literalAnnot.getDetails().get("description"));
    }
  }
  type.setAllowedValues(vals);
  return type;
}
 
Example 3
Source File: TypeSection.java    From uima-uimaj with Apache License 2.0 2 votes vote down vote up
/**
 * Adds the allowed value.
 *
 * @param td the td
 * @param av the av
 */
private void addAllowedValue(TypeDescription td, AllowedValue av) {
  td.setAllowedValues((AllowedValue[]) Utility.addElementToArray(td.getAllowedValues(), av,
          AllowedValue.class));
}
 
Example 4
Source File: TypeSection.java    From uima-uimaj with Apache License 2.0 2 votes vote down vote up
/**
 * Removes the allowed value.
 *
 * @param td -
 *          local or merged (2 callers)
 * @param av the av
 */
private void removeAllowedValue(TypeDescription td, AllowedValue av) {
  td.setAllowedValues((AllowedValue[]) Utility.removeEqualElementFromArray(td.getAllowedValues(),
          av, AllowedValue.class));
}