Java Code Examples for org.apache.uima.resource.metadata.FeatureDescription#getRangeTypeName()
The following examples show how to use
org.apache.uima.resource.metadata.FeatureDescription#getRangeTypeName() .
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: OwlSchemaFactory.java From baleen with Apache License 2.0 | 5 votes |
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 2
Source File: AnnotationSchemaServiceImpl.java From webanno with Apache License 2.0 | 5 votes |
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 |
/** * 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 4
Source File: Jg.java From uima-uimaj with Apache License 2.0 | 5 votes |
/** * 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 5
Source File: Jg.java From uima-uimaj with Apache License 2.0 | 5 votes |
/** * 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 6
Source File: Jg.java From uima-uimaj with Apache License 2.0 | 5 votes |
/** * 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 7
Source File: CasCreationUtils.java From uima-uimaj with Apache License 2.0 | 4 votes |
/** * 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() }); } } } }