Java Code Examples for org.apache.uima.resource.metadata.FeatureDescription#setRangeTypeName()
The following examples show how to use
org.apache.uima.resource.metadata.FeatureDescription#setRangeTypeName() .
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 |
/** * 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 2
Source File: TypeSystemUtil.java From uima-uimaj with Apache License 2.0 | 6 votes |
/** * 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: TypeSection.java From uima-uimaj with Apache License 2.0 | 5 votes |
/** * 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 4
Source File: TypeSection.java From uima-uimaj with Apache License 2.0 | 4 votes |
/** * return true if refresh is needed. * * @param oldTypeName the old type name * @param newTypeName the new type name * @return true if refresh is needed */ private boolean alterTypeMentionsInOtherTypes(String oldTypeName, String newTypeName) { // only modify locally modifiable types, but scan all types to give appropriate error msgs TypeSystemDescription typeSystem = getMergedTypeSystemDescription(); boolean refreshNeeded = false; boolean remergeNeeded = false; TypeDescription[] types = typeSystem.getTypes(); for (int i = 0; i < types.length; i++) { TypeDescription td = types[i]; TypeDescription localTd = getLocalTypeDefinition(td); String typeName = td.getName(); if (td.getSupertypeName().equals(oldTypeName)) { if (null != localTd) { // is a local type if (isImportedType(typeName)) { Utility .popMessage( "Imported type won't be changed", "There is both a local and imported version of type, '" + typeName + "', which has a supertype which is the item being renamed. Although the local version will be updated, but the imported one won't." + "This may cause an error when you save.", MessageDialog.WARNING); } if (isBuiltInType(typeName)) { // invalid: changed some type name which was a supertype of a built in - but // all the supertypes of built-ins are unchangable. throw new InternalErrorCDE("invalid state"); } } else { // is not a local type // can't be a built-in type because all the supertypes of built-ins are unchangeable Utility .popMessage( "Imported type not changed", "There is an imported type, '" + typeName + "', which has a supertype which is the item being renamed. It won't be updated - this may cause an error when you save this descriptor." + " If it does, you will need to edit the imported type to change it.", MessageDialog.WARNING); continue; } // guaranteed to have local type def here localTd.setSupertypeName(newTypeName); if (isImportedType(typeName)) { remergeNeeded = true; refreshNeeded = true; } else { td.setSupertypeName(newTypeName); updateGuiType(tt.getItems()[i], td); } } FeatureDescription fds[] = td.getFeatures(); FeatureDescription localFds[] = (null == localTd) ? null : localTd.getFeatures(); if (null != fds) { for (int j = 0; j < fds.length; j++) { FeatureDescription fd = fds[j]; if (oldTypeName.equals(fd.getRangeTypeName())) { if (warnAndSkipIfImported(typeName)) continue; // skipped if feature not present in local td, or no local td. setNamedFeatureDescriptionRange(localFds, fd.getName(), newTypeName); if (isImportedType(typeName)) { remergeNeeded = true; refreshNeeded = true; } else { fd.setRangeTypeName(newTypeName); updateGuiFeature(tt.getItems()[i].getItems()[j], fd, td); } } } } } if (remergeNeeded) rebuildMergedTypeSystem(); return refreshNeeded; }
Example 5
Source File: Ecore2UimaTypeSystem.java From uima-uimaj with Apache License 2.0 | 4 votes |
/** * E structural feature 2 uima feature. * * @param aStructuralFeature the a structural feature * @param aOptions the a options * @return - * @throws URISyntaxException the URI syntax exception */ private static FeatureDescription eStructuralFeature2UimaFeature( EStructuralFeature aStructuralFeature, Map aOptions) throws URISyntaxException { FeatureDescription feat = uimaFactory.createFeatureDescription(); feat.setName(aStructuralFeature.getName()); String rangeTypeName = null; String elementTypeName = null; EAnnotation eannot = aStructuralFeature.getEAnnotation("http://uima.apache.org"); if (eannot != null) { feat.setDescription((String) eannot.getDetails().get("description")); // the UIMA type name to use may be recorded as an EAnnotation; this is // particularly important for arrays and lists, since Ecore doesn't distinguish between // these two possible implementations for a multi-valued property rangeTypeName = (String) eannot.getDetails().get("uimaType"); // the elemnt type may also be specified as an EAnnotation; this is // used for the case where an FSArray or FSList is NOT represented // as a multi-valued property elementTypeName = (String) eannot.getDetails().get("elementType"); } EClassifier attrRangeType = aStructuralFeature.getEType(); // if range type wasn't specified in an EAnnotation, compute it ourselves if (rangeTypeName == null) { rangeTypeName = getUimaTypeName(attrRangeType, aStructuralFeature.isMany(), aOptions); } feat.setRangeTypeName(rangeTypeName); if (aStructuralFeature.isMany()) { // set the element type of the array/list to the EType of the structural feature // (except primitive, or TOP, which are assumed) String uimaElementType = getUimaTypeName(attrRangeType, false, aOptions); if (!CAS.TYPE_NAME_INTEGER.equals(uimaElementType) && !CAS.TYPE_NAME_FLOAT.equals(uimaElementType) && !CAS.TYPE_NAME_STRING.equals(uimaElementType) && !CAS.TYPE_NAME_TOP.equals(uimaElementType) && !CAS.TYPE_NAME_BYTE.equals(uimaElementType) && !CAS.TYPE_NAME_SHORT.equals(uimaElementType) && !CAS.TYPE_NAME_LONG.equals(uimaElementType) && !CAS.TYPE_NAME_DOUBLE.equals(uimaElementType) && !CAS.TYPE_NAME_BOOLEAN.equals(uimaElementType)) { feat.setElementType(uimaElementType); } } else if (!aStructuralFeature.getEType().equals(EcorePackage.eINSTANCE.getEByteArray())) { // if in Ecore we have a single-valued property whose range type is an array or list, // we need to set "multiple references allowed" to true in the UIMA type system // (exception: don't do this for the EByteArray data type, which is implicilty a // multi-valued type) if (isArrayOrList(rangeTypeName)) { feat.setMultipleReferencesAllowed(Boolean.TRUE); // also, set element type if one was contained in the EAnnotation feat.setElementType(elementTypeName); } } return feat; }