/** * 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); } }
protected boolean isSameFeatureDescription(FeatureDescription f1, FeatureDescription f2) { if (!f2.getName().equals(f1.getName())) return false; return f2.getRangeTypeName().equals(f1.getRangeTypeName()); }
/** * 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; } } } }
/** * Update gui feature. * * @param fItem the f item * @param fd the fd * @param td the td */ private void updateGuiFeature(TableTreeItem 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.booleanValue()) ? 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) : ""); }
/** * Gets the local feature definition. * * @param td the td * @param fd the fd * @return the local feature definition */ protected FeatureDescription getLocalFeatureDefinition(TypeDescription td, FeatureDescription fd) { return getLocalFeatureDefinition(td, fd.getName()); }
String featName = aFeatures[i].getName(); String rangeTypeName = aFeatures[i].getRangeTypeName(); String elementTypeName = aFeatures[i].getElementType(); Boolean multiRefsAllowed = aFeatures[i].getMultipleReferencesAllowed(); if (existingFeatures[j].getName().equals(featName)) { feat = existingFeatures[j]; break; FeatureDescription featDesc = aType.addFeature(featName, aFeatures[i].getDescription(), rangeTypeName, elementTypeName, multiRefsAllowed); featDesc.setSourceUrl(aFeatures[i].getSourceUrl()); } else {// feature does exist 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; throw new ResourceInitializationException( ResourceInitializationException.INCOMPATIBLE_MULTI_REFS, new Object[] { aType.getName() + ":" + feat.getName(), aType.getSourceUrlString() }); if (!elementTypesCompatible(feat.getElementType(), elementTypeName)) { throw new ResourceInitializationException(
private String checkFSFeatureOfType(String featureName, String longTypeName) { TypeDescription t = typeDescriptionMap.get(longTypeName); if (t == null) { return null; } FeatureDescription[] features = t.getFeatures(); for (FeatureDescription featureDescription : features) { String name = featureDescription.getName(); String rangeTypeName = featureDescription.getRangeTypeName(); boolean isFS = isFeatureStructure(rangeTypeName); if (name.equals(featureName)) { if (isFS) { return rangeTypeName; } else if (StringUtils.equals(CAS.TYPE_NAME_FS_ARRAY, rangeTypeName)) { String elementType = featureDescription.getElementType(); if (elementType == null) { return CAS.TYPE_NAME_FS_ARRAY; } else { return elementType; } } } } return null; }
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)); } }
boolean hasArrayRange(FeatureDescription fd) { TypeInfo bi = (TypeInfo) JcasGen.builtInTypes.get(fd.getRangeTypeName()); if (null == bi) return false; return bi.isArray; }
sb.append("<li><b>" + eachFeat.getName() + "</b> (" + eachFeat.getRangeTypeName() + ") </li>"); if (eachFeat.getDescription() != null && !eachFeat.getDescription().trim().isEmpty()) { sb.append("<p>"); sb.append(eachFeat.getDescription()); sb.append("</p>");
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);
String getJavaRangeArrayElementType(FeatureDescription fd) { String arrayElementCasNameWithNameSpace = fd.getElementType(); TypeInfo bi = (TypeInfo) JcasGen.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); }
/** * Handle hover. * * @param event the event */ public void handleHover(Event event) { // next getItem call requires that table have SWT.FULL_SELECTION Style TableTreeItem 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.booleanValue()) ? "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(""); }
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; }
/** * 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; }
featDesc.setName(feat.getShortName()); Type rangeType = feat.getRange(); if (rangeType.isArray()) { featDesc.setRangeTypeName(typeName); featDesc.setElementType(rangeType.getComponentType().getName()); } else { featDesc.setRangeTypeName(feat.getRange().getName());
descriptionUI.setText(convertNull(existingFd.getDescription())); featureNameUI.setText(originalFeatureName = existingFd.getName()); featureRangeNameUI.setText(existingFd.getRangeTypeName()); Boolean mra = existingFd.getMultipleReferencesAllowed(); multiRefUI.select((null == mra) ? 0 : (mra.booleanValue()) ? 2 : 1); String ert = existingFd.getElementType(); elementRangeNameUI.setText((null == ert) ? "" : ert);
/** * 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 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()]); }
Feature f = t.getFeatureByBaseName(fdesc.getName()); fdesc.getName(), tdesc.getName()); upgradeRequired = true; break nextType; if (CAS.TYPE_NAME_FS_ARRAY.equals(fdesc.getRangeTypeName())) { if (!Objects.equals(fdesc.getElementType(), f.getRange().getComponentType().getName())) { log.info( "CAS update required: ranges of feature {} on type {} do not match: {} <-> {}", fdesc.getName(), tdesc.getName(), fdesc.getRangeTypeName(), f.getRange().getName()); upgradeRequired = true; if (!Objects.equals(fdesc.getRangeTypeName(), f.getRange().getName())) { log.info( "CAS update required: ranges of feature {} on type {} do not match: {} <-> {}", fdesc.getName(), tdesc.getName(), fdesc.getRangeTypeName(), f.getRange().getName()); upgradeRequired = true;
/** * 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; }