protected String getFullJavaName(TypeDescription td) { return td.getName(); }
private void inferFeatureMap(TypeDescription type) { // 1 - Recursively add features of the super type TypeDescription superType = typeSystemDescription.getType(type.getSupertypeName()); if(superType != null) inferFeatureMap(superType); // 2 - Add features of this type for(FeatureDescription feature:type.getFeatures()) { String featureFQN = type.getName() + ":" + feature.getName(); featureMap.put(feature.getName(), featureFQN); featureMap.put(featureFQN, featureFQN); } }
@Override public void generateFeature(TypeSystemDescription aTSD, TypeDescription aTD, AnnotationFeature aFeature) { // Link type TypeDescription linkTD = aTSD.addType(aFeature.getLinkTypeName(), "", CAS.TYPE_NAME_TOP); linkTD.addFeature(aFeature.getLinkTypeRoleFeatureName(), "", CAS.TYPE_NAME_STRING); linkTD.addFeature(aFeature.getLinkTypeTargetFeatureName(), "", aFeature.getType()); // Link feature aTD.addFeature(aFeature.getName(), "", CAS.TYPE_NAME_FS_ARRAY, linkTD.getName(), false); }
/** * Removes the feature. * * @param td the td * @param fd the fd */ private void removeFeature(TypeDescription td, FeatureDescription fd) { td.setFeatures((FeatureDescription[]) Utility.removeElementFromArray(td.getFeatures(), fd, FeatureDescription.class)); }
/** * Type update. * * @param td the td * @param dialog the dialog */ private void typeUpdate(TypeDescription td, AddTypeDialog dialog) { td.setName(setValueChanged(dialog.typeName, td.getName())); td.setDescription(setValueChanged(multiLineFix(dialog.description), td.getDescription())); td.setSupertypeName(setValueChanged(dialog.supertypeName, td.getSupertypeName())); }
private Set<FeatureDescription> getAllDeclaredFeatures(TypeDescription typeDescription, Map<String, TypeDescription> typeMap) { Set<FeatureDescription> result = new HashSet<FeatureDescription>(); if (typeDescription == null) { return result; } FeatureDescription[] features = typeDescription.getFeatures(); if (features == null) { return result; } result.addAll(Arrays.asList(features)); String supertypeName = typeDescription.getSupertypeName(); if (supertypeName != null) { TypeDescription parent = typeMap.get(supertypeName); result.addAll(getAllDeclaredFeatures(parent, typeMap)); } return result; }
if (td.getFeatures().length > 0) { stringBuffer.append("import org.apache.uima.cas.impl.FeatureImpl;\nimport org.apache.uima.cas.Feature;\n"); for(Iterator i = jg.collectImports(td, true).iterator(); i.hasNext();) { String imp = (String)i.next(); if (!imp.equals(jg.getJavaNameWithPkg(td.getName()+"_Type"))) { stringBuffer.append("import "); stringBuffer.append(imp); String typeName_Type = typeName + "_Type"; stringBuffer.append("/** "); stringBuffer.append(jg.nullBlank(td.getDescription())); stringBuffer.append("\n * Updated by JCasGen "); stringBuffer.append(jg.getDate()); stringBuffer.append(typeName_Type); stringBuffer.append(" extends "); stringBuffer.append(jg.getJavaName(td.getSupertypeName()) + "_Type"); stringBuffer.append(" {\n /** generated \n * @return the generator for this type\n */\n @Override\n protected FSGenerator getFSGenerator() {return fsGenerator;}\n /** generated */\n private final FSGenerator fsGenerator = \n new FSGenerator() {\n public FeatureStructure createFS(int addr, CASImpl cas) {\n if ("); stringBuffer.append(typeName_Type); stringBuffer.append(typeName); stringBuffer.append(".typeIndexID;\n /** generated \n modifiable */\n @SuppressWarnings (\"hiding\")\n public final static boolean featOkTst = JCasRegistry.getFeatOkTst(\""); stringBuffer.append(td.getName()); stringBuffer.append("\");\n"); FeatureDescription[] fds = td.getFeatures(); for (int i = 0; i < fds.length; i++) { FeatureDescription fd = fds[i];
private static void addTypeToMergedTypeSystem(Map<String, Set<String>> aOutputMergedTypes, Map<String,TypeDescription> typeNameMap, TypeDescription type) throws ResourceInitializationException { String typeName = type.getName(); String supertypeName = type.getSupertypeName(); TypeDescription existingType = typeNameMap.get(typeName); if (existingType == null) { existingType.setName(typeName); existingType.setDescription(type.getDescription()); existingType.setSupertypeName(supertypeName); existingType.setAllowedValues(type.getAllowedValues()); existingType.setSourceUrl(type.getSourceUrl()); typeNameMap.put(type.getName(), existingType); FeatureDescription[] features = type.getFeatures(); if (features != null) { mergeFeatures(existingType, type.getFeatures()); String existingSupertypeName = existingType.getSupertypeName(); if (!existingSupertypeName.equals(supertypeName)) { existingType.setSupertypeName(supertypeName); ResourceInitializationException.INCOMPATIBLE_SUPERTYPES, new Object[] { typeName, supertypeName, existingSupertypeName, type.getSourceUrlString() }); ResourceInitializationException.ALLOWED_VALUES_NOT_IDENTICAL, new Object[] { typeName, avAsString(av1), avAsString(av2), type.getSourceUrlString() }); int prevNumFeatures = existingType.getFeatures().length;
while (it.hasNext()) { TypeDescription curTypeDesc = it.next(); String typeName = curTypeDesc.getName(); String superTypeName = curTypeDesc.getSupertypeName(); if (superTypeName == null) { throw new ResourceInitializationException( ResourceInitializationException.NO_SUPERTYPE, new Object[] { typeName, curTypeDesc.getSourceUrlString() }); ResourceInitializationException.REDEFINING_BUILTIN_TYPE, new Object[] { typeSystemMgr.getParent(builtIn), typeName, superTypeName, curTypeDesc.getSourceUrlString() }); if (curTypeDesc.getSupertypeName().equals(CAS.TYPE_NAME_STRING)) { AllowedValue[] vals = curTypeDesc.getAllowedValues(); if (vals == null) { throw new ResourceInitializationException( ResourceInitializationException.MISSING_ALLOWED_VALUES, new Object[] { typeName, curTypeDesc.getSourceUrlString() }); if (curTypeDesc.getAllowedValues() != null && curTypeDesc.getAllowedValues().length > 0) { throw new ResourceInitializationException( ResourceInitializationException.ALLOWED_VALUES_ON_NON_STRING_TYPE, new Object[] { typeName, curTypeDesc.getSourceUrlString() }); if (td_j.getName().equals(td_i.getSupertypeName())) { foundSuperType = true;
TypeDescription td = tds[i]; if (noGenTypes.contains(td.getName())) continue; if (td.getSupertypeName().equals("uima.cas.String")) continue; if (limitJCasGenToProjectScope && isOutOfScope(td, projectPathDir)) { Set<String> mt = mergedTypesAddingFeatures.get(td.getName()); if (null == mt) { continue; sb.append(" ").append(p).append('\n'); error.newError(IError.ERROR, getString("limitingButTypeWasExtended", new Object[]{td.getName(), sb.toString()}), null); continue; .getName()); if (null != builtInFeatures) { generatedBuiltInTypes.add(td.getName()); List newFeatures = setDifference(td.getFeatures(), builtInFeatures); int newFeaturesSize = newFeatures.size(); if (newFeaturesSize > 0) { for (int j = builtInFeatures.length, k = 0; k < newFeaturesSize; j++, k++) newFds[j] = (FeatureDescription) newFeatures.get(k); td.setFeatures(newFds); } else {
if (null == mergedTd) return typeFeature0; FeatureDescription[] locallyDefinedFeatures = localTd.getFeatures(); if (null == locallyDefinedFeatures || locallyDefinedFeatures.length == 0) return typeFeature0; FeatureDescription[] remainingFeatures = mergedTd.getFeatures(); ArrayList deletedFeatures = new ArrayList(); Type thisType = typeSystem.getType(localTd.getName()); List subsumedTypesList = typeSystem.getProperlySubsumedTypes(thisType); subsumedTypesList.add(thisType);
FeatureDescription[] existingFeatures = aType.getFeatures(); if (existingFeatures == null) { existingFeatures = new FeatureDescription[0]; FeatureDescription featDesc = aType.addFeature(featName, aFeatures[i].getDescription(), rangeTypeName, elementTypeName, multiRefsAllowed); featDesc.setSourceUrl(aFeatures[i].getSourceUrl()); throw new ResourceInitializationException( ResourceInitializationException.INCOMPATIBLE_RANGE_TYPES, new Object[] { aType.getName() + ":" + feat.getName(), rangeTypeName, feat.getRangeTypeName(), aType.getSourceUrlString() }); throw new ResourceInitializationException( ResourceInitializationException.INCOMPATIBLE_MULTI_REFS, new Object[] { aType.getName() + ":" + feat.getName(), aType.getSourceUrlString() }); throw new ResourceInitializationException( ResourceInitializationException.INCOMPATIBLE_ELEMENT_RANGE_TYPES, new Object[] { aType.getName() + TypeSystem.FEATURE_SEPARATOR + feat.getName(), elementTypeName, feat.getElementType(), aType.getSourceUrlString() });
/** * Update gui type. * * @param item the item * @param td the td */ private void updateGuiType(TableTreeItem item, TypeDescription td) { item.setText(NAME_COL, formatName(td.getName())); item.setText(SUPER_COL, formatName(td.getSupertypeName())); }
@Override public void generateFeature(TypeSystemDescription aTSD, TypeDescription aTD, AnnotationFeature aFeature) { aTD.addFeature(aFeature.getName(), "", CAS.TYPE_NAME_STRING); }
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)) { localTd.setSupertypeName(newTypeName); 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++) {
descriptionUI.setText(convertNull(existingTd.getDescription())); typeNameUI.setText(originalTypeName = existingTd.getName()); supertypeNameUI.setText(convertNull(existingTd.getSupertypeName()));
private void analyzeType(TypeSystem aTS, TypeSystemDescription aTSD, TypeDescription aTD) { log.trace("Analyzing [{}]", aTD.getName()); Type type = aTS.getType(aTD.getName()); if (aTD.getName().startsWith("uima.tcas.")) { log.debug("[{}] is a built-in UIMA type. Skipping.", aTD.getName()); return; "de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence".equals(aTD.getName()) || "de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token".equals(aTD.getName()) ) { log.debug("[{}] is a DKPro Core segmentation type. Skipping.", aTD.getName()); return; log.debug("[{}] is not an annotation type. Skipping.", aTD.getName()); return; log.debug("[{}] looks like an elevated type. Skipping.", aTD.getName()); return; if (isChain) { details = chainDetails; layer.setName(removeEnd(aTD.getName(), "Chain")); layer.setUiName(removeEnd(type.getShortName(), "Chain")); layer.setType(CHAIN_TYPE); layer.setName(aTD.getName()); layer.setUiName(type.getShortName()); layer.setType(RELATION_TYPE);
private OntClass addType(OntModel ontModel, OntClass parent, Type type) { TypeDescription description = descriptions.getType(type.getName()); OntClass ontClass = ontModel.createClass(namespace + type.getShortName()); String comment = description.getDescription(); if (comment != null) { ontClass.addComment(comment, EN); } HashSet<FeatureDescription> features = new HashSet<>(); if (parent != null) { parent.addSubClass(ontClass); features.addAll(Arrays.asList(description.getFeatures())); } else { for (Feature feature : type.getFeatures()) { TypeDescription typeDescription = descriptions.getType(feature.getDomain().getName()); if (typeDescription != null) { features.addAll(Arrays.asList(typeDescription.getFeatures())); } } } for (FeatureDescription feature : features) { if (!ignoreProperties.contains(feature.getName())) { addFeature(ontModel, ontClass, feature); } } for (Type child : typeSystem.getDirectSubtypes(type)) { addType(ontModel, ontClass, child); } return ontClass; }
/** * 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; }
FeatureStructure casFS = iter.next(); TypeDescription newType = UIMAFramework.getResourceSpecifierFactory().createTypeDescription(); newType.setName(casFS.getType()); newType.setSupertypeName("uima.tcas.annotation"); newType.setDescription("CasData Type"); String features[] = casFS.getFeatureNames(); if (features != null) { description = " featue of the casDataType"; newType.addFeature(featName, description, rangeName);