Java Code Examples for org.apache.uima.resource.metadata.FeatureDescription#getElementType()

The following examples show how to use org.apache.uima.resource.metadata.FeatureDescription#getElementType() . 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: TypeSection.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Update gui feature.
 *
 * @param fItem the f item
 * @param fd the fd
 * @param td the td
 */
private void updateGuiFeature(TreeItem fItem, FeatureDescription fd, TypeDescription td) {
  String rangeType;
  fItem.setText(NAME_COL, fd.getName());
  fItem.setText(RANGE_COL, formatName(rangeType = fd.getRangeTypeName()));
  fItem.setData(fd);
  setItemColor(fItem, null != getLocalFeatureDefinition(td, fd));
  if (isArrayOrListType(rangeType)) {
    Boolean mra = fd.getMultipleReferencesAllowed();
    fItem.setImage(MULTIPLE_REF_OK_COL,
            (null != mra && mra) ? TAEConfiguratorPlugin
                    .getImage(TAEConfiguratorPlugin.IMAGE_MREFOK) : TAEConfiguratorPlugin
                    .getImage(TAEConfiguratorPlugin.IMAGE_NOMREF));
  } else {
    fItem.setImage(MULTIPLE_REF_OK_COL, null);
  }

  String ert = fd.getElementType();
  fItem.setText(ELEMENT_TYPE_COL,
          (isFSArrayOrListType(rangeType) && ert != null) ? formatName(ert) : "");

}
 
Example 2
Source File: AnnotationSchemaServiceImpl.java    From webanno with Apache License 2.0 5 votes vote down vote up
private void exportBuiltInTypeDescription(TypeSystemDescription aSource,
        TypeSystemDescription aTarget, String aType)
{
    TypeDescription builtInType = aSource.getType(aType);
    
    if (builtInType == null) {
        throw new IllegalArgumentException(
                "No type description found for type [" + aType + "]");
    }
    
    TypeDescription clonedType = aTarget.addType(builtInType.getName(),
            builtInType.getDescription(), builtInType.getSupertypeName());
    
    if (builtInType.getFeatures() != null) {
        for (FeatureDescription feature : builtInType.getFeatures()) {
            clonedType.addFeature(feature.getName(), feature.getDescription(),
                    feature.getRangeTypeName(), feature.getElementType(),
                    feature.getMultipleReferencesAllowed());
            
            // Export types referenced by built-in types also as built-in types. Note that
            // it is conceptually impossible for built-in types to refer to custom types, so
            // this is cannot lead to a custom type being exported as a built-in type.
            if (
                    feature.getElementType() != null && 
                    !isNativeUimaType(feature.getElementType()) &&
                    aTarget.getType(feature.getElementType()) == null
            ) {
                exportBuiltInTypeDescription(aSource, aTarget, feature.getElementType());
            }
            else if (
                    feature.getRangeTypeName() != null && 
                    !isNativeUimaType(feature.getRangeTypeName()) &&
                    aTarget.getType(feature.getRangeTypeName()) == null
            ) {
                exportBuiltInTypeDescription(aSource, aTarget, feature.getRangeTypeName());
            }
        }
    }
}
 
Example 3
Source File: Jg.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the java range array element type.
 *
 * @param fd the fd
 * @return the java range array element type
 */
String getJavaRangeArrayElementType(FeatureDescription fd) {
  String arrayElementCasNameWithNameSpace = fd.getElementType();
  TypeInfo bi = Jg.builtInTypes.get(fd.getRangeTypeName());
  if (null == bi) {
    if (null == arrayElementCasNameWithNameSpace)
      return "";
    return getJavaName(arrayElementCasNameWithNameSpace);
  }
  if (null != arrayElementCasNameWithNameSpace && !"".equals(arrayElementCasNameWithNameSpace)) {
    return getJavaName(arrayElementCasNameWithNameSpace);
  }
  return getJavaName(bi.arrayElNameWithPkg);
}
 
Example 4
Source File: CasCreationUtils.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
/**
 * Merges features into a TypeDescription.
 * 
 * @param aType
 *                TypeDescription into which to merge the features
 * @param aFeatures
 *                array of features to merge
 * 
 * @throws ResourceInitializationException
 *                 if an incompatibility exists
 */
protected static void mergeFeatures(TypeDescription aType, FeatureDescription[] aFeatures)
    throws ResourceInitializationException {
  FeatureDescription[] existingFeatures = aType.getFeatures();
  if (existingFeatures == null) {
    existingFeatures = EMPTY_FEAT_DESC_ARRAY;
  }

  for (int i = 0; i < aFeatures.length; i++) {
    String featName = aFeatures[i].getName();
    String rangeTypeName = aFeatures[i].getRangeTypeName();
    String elementTypeName = aFeatures[i].getElementType();
    Boolean multiRefsAllowed = aFeatures[i].getMultipleReferencesAllowed();

    // see if a feature already exists with this name
    FeatureDescription feat = null;
    for (int j = 0; j < existingFeatures.length; j++) {
      if (existingFeatures[j].getName().equals(featName)) {
        feat = existingFeatures[j];
        break;
      }
    }

    if (feat == null) {
      // doesn't exist; add it
      FeatureDescription featDesc = aType.addFeature(featName, aFeatures[i].getDescription(),
          rangeTypeName, elementTypeName, multiRefsAllowed);
      featDesc.setSourceUrl(aFeatures[i].getSourceUrl());
    } else {// feature does exist
      // check that the range types match
      if (!feat.getRangeTypeName().equals(rangeTypeName)) {
        throw new ResourceInitializationException(
            ResourceInitializationException.INCOMPATIBLE_RANGE_TYPES, new Object[] {
                aType.getName() + ":" + feat.getName(), rangeTypeName, feat.getRangeTypeName(),
                aType.getSourceUrlString() });
      }
      Boolean mra1 = feat.getMultipleReferencesAllowed();
      Boolean mra2 = multiRefsAllowed;

      // the logic here:
      // OK if both null
      // OK if both not-null, and are equals()
      // OK if one is null, the other has boolean-value of false (false is the default)
      // not ok otherwise

      if (!(((mra1 == null) && (mra2 == null)) || ((mra1 != null) && mra1.equals(mra2))
          || ((mra1 == null) && !mra2) || ((mra2 == null) && !mra1))) {
        throw new ResourceInitializationException(
            ResourceInitializationException.INCOMPATIBLE_MULTI_REFS, new Object[] {
                aType.getName() + ":" + feat.getName(), aType.getSourceUrlString() });
      }

      if (!elementTypesCompatible(feat.getElementType(), elementTypeName)) {
        throw new ResourceInitializationException(
            ResourceInitializationException.INCOMPATIBLE_ELEMENT_RANGE_TYPES, new Object[] {
                aType.getName() + TypeSystem.FEATURE_SEPARATOR + feat.getName(), elementTypeName,
                feat.getElementType(), aType.getSourceUrlString() });
      }
    }
  }
}