org.apache.uima.resource.metadata.FeatureDescription Java Examples

The following examples show how to use org.apache.uima.resource.metadata.FeatureDescription. 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
/**
 * Type requires type.
 *
 * @param upstreamType the upstream type
 * @param typeName the type name
 * @return true, if successful
 */
private boolean typeRequiresType(TypeDescription upstreamType, String typeName) {
  if (null == typeName)
    return false;
  if (typeName.equals(upstreamType.getSupertypeName())) {
    return true;
  }

  FeatureDescription[] features = upstreamType.getFeatures();
  if (features == null) {
    return false;
  }

  for (int i = 0; i < features.length; i++) {
    if (typeName.equals(features[i].getRangeTypeName())) {
      return true;
    }
  }
  return false;
}
 
Example #2
Source File: TypeSystemUtil.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Convert a {@link Feature} to an equivalent {@link FeatureDescription}.
 * 
 * @param aFeature
 *          feature object to convert
 * @return a FeatureDescription that is equivalent to <code>aFeature</code>
 */
public static FeatureDescription feature2FeatureDescription(Feature aFeature) {
  FeatureDescription featDesc = UIMAFramework.getResourceSpecifierFactory()
          .createFeatureDescription();
  featDesc.setName(aFeature.getShortName());
  if (aFeature.isMultipleReferencesAllowed()) {
    featDesc.setMultipleReferencesAllowed(true);
  }
  Type rangeType = aFeature.getRange();
  //special check for array range types, which are represented in the CAS as
  //elementType[] but in the descriptor as an FSArray with an <elementType>
  if (rangeType.isArray() && !rangeType.getComponentType().isPrimitive()) {
    featDesc.setRangeTypeName(CAS.TYPE_NAME_FS_ARRAY);
    String elementTypeName = rangeType.getComponentType().getName();
    if (!CAS.TYPE_NAME_TOP.equals(elementTypeName)) {
      featDesc.setElementType(elementTypeName);
    }
  }
  else {
    featDesc.setRangeTypeName(rangeType.getName());
  }
  return featDesc;
}
 
Example #3
Source File: TypeSystemAnalysis.java    From webanno with Apache License 2.0 6 votes vote down vote up
private void analyzeFeatures(AnnotationLayer aLayer, TypeSystem aTS, TypeDescription aTD,
        Optional<? extends LayerDetails> aDetails)
{
    Type type = aTS.getType(aTD.getName());
    for (FeatureDescription fd : aTD.getFeatures()) {
        Feature feat = type.getFeatureByBaseName(fd.getName());
        // We do not need to set up built-in features
        if (isBuiltInFeature(feat)) {
            continue;
        }
        
        if (aDetails.isPresent() && aDetails.get().isHiddenFeature(feat)) {
            continue;
        }
        
        AnnotationFeature f = analyzeFeature(aTS, fd, feat);
        features.put(aLayer.getName(), f);
    }
}
 
Example #4
Source File: TypeSystemAnalysis.java    From webanno with Apache License 2.0 6 votes vote down vote up
private AnnotationFeature analyzeFeature(TypeSystem aTS, FeatureDescription aFD, Feature aFeat)
{
    AnnotationFeature feat = new AnnotationFeature();
    feat.setType(aFeat.getRange().getName());
    feat.setName(aFeat.getShortName());
    feat.setUiName(aFeat.getShortName());
    feat.setDescription(trimToNull(aFD.getDescription()));
    
    feat.setEnabled(true);
    
    if (isSlotFeature(aTS, aFeat)) {
        feat.setType(aFeat.getRange().getComponentType().getFeatureByBaseName("target")
                .getRange().getName());
        feat.setMode(MultiValueMode.ARRAY);
        feat.setLinkMode(LinkMode.WITH_ROLE);
        // Need to strip the "[]" marking the type as multi-valued off the type name 
        feat.setLinkTypeName(removeEnd(aFeat.getRange().getName(), "[]"));
        // FIXME Instead of hard-coding the feature names here, try to auto-detect them by
        // looking for a String feature and a feature whose type is subsumed by Annotation
        feat.setLinkTypeRoleFeatureName("role");
        feat.setLinkTypeTargetFeatureName("target");
    }
    
    return feat;
}
 
Example #5
Source File: TypeDescription_impl.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * @see TypeDescription#addFeature(String, String, String, String, Boolean)
 */
public FeatureDescription addFeature(String aFeatureName, String aDescription,
        String aRangeTypeName, String aElementTypeName, Boolean aMultipleReferencesAllowed) {
  // create new feature description
  FeatureDescription newFeature = new FeatureDescription_impl(aFeatureName, aDescription,
          aRangeTypeName, aElementTypeName, aMultipleReferencesAllowed);

  // add to array
  FeatureDescription[] features = getFeatures();
  if (features == null) {
    setFeatures(new FeatureDescription[] { newFeature });
  } else {
    FeatureDescription[] newArray = new FeatureDescription[features.length + 1];
    System.arraycopy(features, 0, newArray, 0, features.length);
    newArray[features.length] = newFeature;
    setFeatures(newArray);
  }

  return newFeature;
}
 
Example #6
Source File: TypeSection.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * verify a new or edited feature is valid. For new features: The name must be unique locally. It
 * may duplicate a non-local feature that isn't also built-in. (We presume built-in features are
 * fixed). (We allow dupl non-local feature in case this type system is used without the import,
 * in some other context?) We don't use the TCas because it isn't necessarily being updated
 * 
 * For edited features: If the name changed, do "new" test above on new name If the name changed,
 * do "remove" test on old name: If used in an index or capability, but merged/built-in name not
 * still there, warn about index being invalidated (not done here - done during feature update
 * itself). If name used in index, and range is not indexable - error
 *
 * @param dialog the dialog
 * @param td the td
 * @param oldFd the old fd
 * @return error message or null
 */
public String checkFeature(AddFeatureDialog dialog, TypeDescription td, FeatureDescription oldFd) {
  if (null == oldFd) { // adding new feature
    return newFeatureTests(td, dialog);
  }

  String errMsg = null;
  // modifying existing feature
  if (!oldFd.getName().equals(dialog.featureName)) { // name changed
    errMsg = newFeatureTests(td, dialog);
    if (null != errMsg)
      return errMsg;
    return null;
  }

  // Note: this test is different from above: it tests current name, not old name
  if (isFeatureUsedInIndex(td, dialog.featureName))
    if (!isIndexableRange(dialog.featureRangeName))
      return ("This feature is used in an index - it must have an indexable Range");
  return null;
}
 
Example #7
Source File: TypeSection.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the difference.
 *
 * @param all the all
 * @param subset the subset
 * @return the feature description[]
 */
private FeatureDescription[] setDifference(FeatureDescription[] all, FeatureDescription[] subset) {
  if (null == all)
    return featureDescriptionArray0;
  if (null == subset)
    return all;
  List<FeatureDescription> result = new ArrayList<>();

  outer: for (int i = 0; i < all.length; i++) {
    String name = all[i].getName();
    for (int j = 0; j < subset.length; j++) {
      if (subset[j].getName().equals(name))
        continue outer;
    }
    result.add(all[i]);
  }
  return (FeatureDescription[]) result.toArray(new FeatureDescription[result.size()]);
}
 
Example #8
Source File: TypeSection.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Feature update.
 *
 * @param fd the fd
 * @param dialog the dialog
 */
public void featureUpdate(FeatureDescription fd, AddFeatureDialog dialog) {
  valueChanged = false;
  String v = setValueChanged(dialog.featureName, fd.getName());
  fd.setName(v);
  v = setValueChanged(multiLineFix(dialog.description), fd.getDescription());
  fd.setDescription(v);
  String range = setValueChanged(dialog.featureRangeName, fd.getRangeTypeName());
  fd.setRangeTypeName(range);
  if (isArrayOrListType(range)) {
    Boolean b = setValueChangedCapitalBoolean(dialog.multiRef, fd.getMultipleReferencesAllowed());
    fd.setMultipleReferencesAllowed(b);
    if (isFSArrayOrListType(range)) {
      v = setValueChanged(dialog.elementRangeName, fd.getElementType());
      fd.setElementType(v);
    } else {
      fd.setElementType(null);
    }
  } else {
    fd.setMultipleReferencesAllowed(null);
    fd.setElementType(null);
  }
}
 
Example #9
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 #10
Source File: TypeSection.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Handle hover.
 *
 * @param event the event
 */
public void handleHover(Event event) {
  // next getItem call requires that table have SWT.FULL_SELECTION Style
  TreeItem item = tt.getItem(new Point(event.x, event.y));
  if (null != item) {
    Object o = item.getData();
    if (null == o)
      throw new InternalErrorCDE("invalid state");

    if (o instanceof TypeDescription) {
      setToolTipText(tt, ((TypeDescription) o).getDescription());
    } else if (o instanceof FeatureDescription) {
      FeatureDescription fd = (FeatureDescription) o;
      if (item.getBounds(MULTIPLE_REF_OK_COL).contains(event.x, event.y)
              && isArrayOrListType(fd.getRangeTypeName())) {
        Boolean mra = fd.getMultipleReferencesAllowed();
        setToolTipText(tt, (mra != null && mra) ? "Multiple References Allowed"
                : "Multiple References Not Allowed");
      } else
        setToolTipText(tt, fd.getDescription());
    } else if (o instanceof AllowedValue) {
      setToolTipText(tt, ((AllowedValue) o).getDescription());
    }
  } else
    tt.setToolTipText("");
}
 
Example #11
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 #12
Source File: TypeSection.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the named feature description range.
 *
 * @param localFds the local fds
 * @param featureName the feature name
 * @param rangeName the range name
 */
// this function to set the corresponding feature in the "local" type's fd array
private void setNamedFeatureDescriptionRange(FeatureDescription[] localFds, String featureName,
        final String rangeName) {
  if (null != localFds) {
    for (int i = 0; i < localFds.length; i++) {
      FeatureDescription fd = localFds[i];
      if (fd.getName().equals(featureName)) {
        fd.setRangeTypeName(rangeName);
        return;
      }
    }
  }
}
 
Example #13
Source File: Jg.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Collect imports.
 *
 * @param td the td
 * @param _Type the type
 * @return the collection
 */
Collection<String> collectImports(TypeDescription td, boolean _Type) {
  if (_Type)
    _imports.clear();
  else
    imports.clear();
  collectImport(td.getName(), _Type);
  collectImport(td.getSupertypeName(), _Type);

  if (!_Type) {

    FeatureDescription[] fds = td.getFeatures();
    for (int i = 0; i < fds.length; i++) {
      FeatureDescription fd = fds[i];
      if (null != typeSystem) {
        String rangeTypeNameCAS = fd.getRangeTypeName();
        Type rangeCasType = typeSystem.getType(rangeTypeNameCAS);
        if (typeSystem.subsumes(casStringType, rangeCasType))
          continue;
      }
      collectImport(fd.getRangeTypeName(), false);
      if (isRangeTypeGeneric(fd)) {
        collectImport(getJavaRangeArrayElementType(fd), false);
      }
    }
  }
  return (_Type) ? _imports.values() : imports.values();
}
 
Example #14
Source File: Jg.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the java range type.
 *
 * @param fd the fd
 * @return the java range type
 */
String getJavaRangeType(FeatureDescription fd) {
  String rangeTypeNameCAS = fd.getRangeTypeName();
  if (null != typeSystem) {
    Type rangeCasType = typeSystem.getType(rangeTypeNameCAS);
    if (rangeCasType instanceof TypeImpl_string) {
      // type is a subtype of string, make its java type = to string
      return "String";
    }
  }
  return getJavaName(rangeTypeNameCAS);
}
 
Example #15
Source File: Jg.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the java range type, with generic types in <> as required.
 *
 * @param fd the fd
 * @return the java range type
 */
String getJavaRangeType2(FeatureDescription fd) {
 if (isRangeTypeGeneric(fd)) {
  String generic = getJavaRangeArrayElementType2(fd);
  return getJavaRangeType(fd) + "<" + (generic == null || generic.trim().isEmpty() ? "?" : generic) + ">";
 } else
  return getJavaRangeType(fd);
}
 
Example #16
Source File: Jg.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Checks for array range.
 *
 * @param fd the fd
 * @return true, if successful
 */
boolean hasArrayRange(FeatureDescription fd) {
  TypeInfo bi = Jg.builtInTypes.get(fd.getRangeTypeName());
  if (null == bi)
    return false;
  return bi.isArray;
}
 
Example #17
Source File: Jg.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Checks if is possible index key.
 *
 * @param fd the fd
 * @return true, if is possible index key
 */
boolean isPossibleIndexKey(FeatureDescription fd) {
  String rangeTypeName = fd.getRangeTypeName();
  // keys are primitives + string + string subtypes
  TypeImpl rangeType = (null == typeSystem) ? null : (TypeImpl) typeSystem.getType(rangeTypeName);
  return (null == typeSystem) ||          // default is to do checking
         rangeType.isStringSubtype() ||   
         BuiltinTypeKinds.primitiveTypeNames_contains(rangeTypeName);  // includes String
}
 
Example #18
Source File: Jg.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Checks if is string subtype.
 *
 * @param fd the fd
 * @return true, if is string subtype
 */
boolean isStringSubtype(FeatureDescription fd) {
  if (null != typeSystem) {
    String rangeTypeName = fd.getRangeTypeName();
    TypeImpl rangeType = (TypeImpl) typeSystem.getType(rangeTypeName);
    return rangeType.getSuperType() == ((TypeSystemImpl)typeSystem).stringType;
  }
  return false;
}
 
Example #19
Source File: OwlSchemaFactory.java    From baleen with Apache License 2.0 5 votes vote down vote up
private void addFeature(OntModel ontModel, OntClass ontClass, FeatureDescription feature) {
  if (ontModel.getDatatypeProperty(namespace + feature.getName()) == null) {
    DatatypeProperty property = ontModel.createDatatypeProperty(namespace + feature.getName());
    String propertyComment = feature.getDescription();
    if (propertyComment != null) {
      property.addComment(propertyComment, EN);
    }

    property.addDomain(ontClass);
    property.addRange(getRange(feature));
  }
}
 
Example #20
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, with generic type or ? in <> as needed
  *
  * @param fd the fd
  * @return the java range array element type
  */
 String getJavaRangeArrayElementType2(FeatureDescription fd) {
if(this.isElementTypeGeneric(fd))
	return getJavaRangeArrayElementType(fd) + "<?>";
else
	return getJavaRangeArrayElementType(fd);
 }
 
Example #21
Source File: Jg.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the difference.
 *
 * @param newFeatures the new features
 * @param alreadyDefinedFeatures the already defined features
 * @return the list
 */
List<FeatureDescription> setDifference(FeatureDescription[] newFeatures, FeatureDescription[] alreadyDefinedFeatures) {
  List<FeatureDescription> result = new ArrayList<>();
  outerLoop: for (int i = 0; i < newFeatures.length; i++) {
    for (int j = 0; j < alreadyDefinedFeatures.length; j++) {
      if (isSameFeatureDescription(newFeatures[i], alreadyDefinedFeatures[j]))
        continue outerLoop;
    }
    result.add(newFeatures[i]);
  }
  return result;
}
 
Example #22
Source File: Jg.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Checks if is same feature description.
 *
 * @param f1 the f 1
 * @param f2 the f 2
 * @return true, if is same feature description
 */
private boolean isSameFeatureDescription(FeatureDescription f1, FeatureDescription f2) {
  if (!f2.getName().equals(f1.getName()))
    return false;
  if (!f2.getRangeTypeName().equals(f1.getRangeTypeName()))
    return false;
  return true;
}
 
Example #23
Source File: TypeDescription_impl.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * @see TypeDescription#setFeatures(FeatureDescription[])
 */
public void setFeatures(FeatureDescription[] aFeatures) {
  if (aFeatures == null) {
    throw new UIMA_IllegalArgumentException(UIMA_IllegalArgumentException.ILLEGAL_ARGUMENT,
            new Object[] { "null", "aFeatures", "setFeatures" });
  }
  mFeatures = aFeatures;
}
 
Example #24
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 #25
Source File: TypeSystemDescription_implTest.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
public void testBuildFromXmlElement() throws Exception {
  try {
    File descriptor = JUnitExtension.getFile("TypeSystemDescriptionImplTest/TestTypeSystem.xml");
    TypeSystemDescription ts = UIMAFramework.getXMLParser().parseTypeSystemDescription(
            new XMLInputSource(descriptor));

    assertEquals("TestTypeSystem", ts.getName());
    assertEquals("This is a test.", ts.getDescription());
    assertEquals("The Apache Software Foundation", ts.getVendor());
    assertEquals("0.1", ts.getVersion());
    Import[] imports = ts.getImports();
    assertEquals(3, imports.length);
    assertEquals("org.apache.uima.resource.metadata.impl.TypeSystemImportedByName", imports[0]
            .getName());
    assertNull(imports[0].getLocation());
    assertNull(imports[1].getName());
    assertEquals("TypeSystemImportedByLocation.xml", imports[1].getLocation());

    TypeDescription[] types = ts.getTypes();
    assertEquals(6, types.length);
    TypeDescription paragraphType = types[4];
    assertEquals("Paragraph", paragraphType.getName());
    assertEquals("A paragraph.", paragraphType.getDescription());
    assertEquals("DocumentStructure", paragraphType.getSupertypeName());
    FeatureDescription[] features = paragraphType.getFeatures();
    assertEquals(2, features.length);
    assertEquals("sentences", features[0].getName());
    assertEquals("Direct references to sentences in this paragraph", features[0].getDescription());
    assertEquals("uima.cas.FSArray", features[0].getRangeTypeName());
    assertEquals("Sentence", features[0].getElementType());
    assertFalse(features[0].getMultipleReferencesAllowed());

    // ts.toXML(System.out);
  } catch (Exception e) {
    JUnitExtension.handleException(e);
  }
}
 
Example #26
Source File: AbstractImportablePartSection.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * returns null if no feature by this name.
 *
 * @param name the name
 * @param td the td
 * @return the feature from type description
 */
public FeatureDescription getFeatureFromTypeDescription(String name, TypeDescription td) {
  FeatureDescription[] fds = td.getFeatures();
  if (fds == null)
    return null;
  for (int i = 0; i < fds.length; i++) {
    if (name.equals(fds[i].getName()))
      return fds[i];
  }
  return null;
}
 
Example #27
Source File: RecommendationServiceImpl.java    From inception with Apache License 2.0 5 votes vote down vote up
public CAS cloneAndMonkeyPatchCAS(Project aProject, CAS aSourceCas, CAS aTargetCas)
    throws UIMAException, IOException
{
    try (StopWatch watch = new StopWatch(log, "adding score features")) {
        TypeSystemDescription tsd = annoService.getFullProjectTypeSystem(aProject);

        for (AnnotationLayer layer : annoService.listAnnotationLayer(aProject)) {
            TypeDescription td = tsd.getType(layer.getName());

            if (td == null) {
                log.trace("Could not monkey patch type [{}]", layer.getName());
                continue;
            }

            for (FeatureDescription feature : td.getFeatures()) {
                String scoreFeatureName = feature.getName() + FEATURE_NAME_SCORE_SUFFIX;
                td.addFeature(scoreFeatureName, "Score feature", CAS.TYPE_NAME_DOUBLE);
                
                String scoreExplanationFeatureName = feature.getName() + 
                        FEATURE_NAME_SCORE_EXPLANATION_SUFFIX;
                td.addFeature(scoreExplanationFeatureName, "Score explanation feature", 
                        CAS.TYPE_NAME_STRING);
            }

            td.addFeature(FEATURE_NAME_IS_PREDICTION, "Is Prediction", CAS.TYPE_NAME_BOOLEAN);
        }

        annoService.upgradeCas(aSourceCas, aTargetCas, tsd);
    }

    return aTargetCas;
}
 
Example #28
Source File: OwlSchemaFactory.java    From baleen with Apache License 2.0 5 votes vote down vote up
private Resource getRange(FeatureDescription feature) {

    String rangeTypeName = feature.getRangeTypeName();
    Resource range;
    switch (rangeTypeName) {
      case "uima.cas.Boolean":
        range = XSD.xboolean;
        break;
      case "uima.cas.Byte":
        range = XSD.xbyte;
        break;
      case "uima.cas.Short":
        range = XSD.xshort;
        break;
      case "uima.cas.Integer":
        range = XSD.xint;
        break;
      case "uima.cas.Long":
        range = XSD.xlong;
        break;
      case "uima.cas.Float":
        range = XSD.xfloat;
        break;
      case "uima.cas.Double":
        range = XSD.xdouble;
        break;
      case "uima.cas.String":
        // Fall
      default:
        range = XSD.xstring;
        break;
    }

    return range;
  }
 
Example #29
Source File: TypeSection.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * New Feature test: return null if OK, error message otherwise.
 *
 * @param td the td
 * @param dialog the dialog
 * @return error message or null
 */
private String newFeatureTests(TypeDescription td, AddFeatureDialog dialog) {
  FeatureDescription fd;

  if (isLocalFeature(dialog.featureName, td))
    return "Duplicate Feature Name in this Descriptor";
  if (isBuiltInFeature(dialog.featureName, td))
    return "Feature Name duplicates built-in feature for this type";

  if (null != (fd = getFeature(td, dialog.featureName)))
    // verify the range is the same
    if (!fd.getRangeTypeName().equals(dialog.featureRangeName))
      return "Range Name not the same as the range from an imported type/feature description";
  return null;
}
 
Example #30
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());
            }
        }
    }
}