/** * Gets the type or feature. * * @param a the a * @param name the name * @return the type or feature */ public static TypeOrFeature getTypeOrFeature(TypeOrFeature[] a, String name) { if (null == a) return null; for (int i = 0; i < a.length; i++) { if (a[i].getName().equals(name)) return a[i]; } return null; }
@Override boolean visit(TypeOrFeature i_o) { if ((!i_o.isType()) && i_o.getName().equals(typePlusFeature)) { return true; } return false; } };
@Override public int compare(Object o1, Object o2) { TypeOrFeature tf = (TypeOrFeature) o2; return (tf.isType() == false && tf.getName().equals(o1)) ? 0 : 1; } };
@Override boolean visit(TypeOrFeature i_o) { if (i_o.isType() && i_o.getName().equals(sOldTypeName)) { capabilityChanged[0] = true; i_o.setName(sNewTypeName); } else if (!i_o.isType() && i_o.getName().startsWith(oldTypeName_colon)) { capabilityChanged[0] = true; i_o.setName(sNewTypeName + ':' + i_o.getName().substring(oldTypeName_colon.length())); } return false; } };
/** * Checks for type. * * @param items the items * @param name the name * @return true, if successful */ private boolean hasType(TypeOrFeature[] items, String name) { if (null == items) return false; for (int i = 0; i < items.length; i++) { if (items[i].isType() && items[i].getName().equals(name)) return true; } return false; }
/** * Type or feature array remove. * * @param a the a * @param s the s * @return the type or feature[] */ public TypeOrFeature[] typeOrFeatureArrayRemove(TypeOrFeature[] a, String s) { TypeOrFeature[] result = new TypeOrFeature[a.length - 1]; for (int i = 0, j = 0; i < a.length; i++) { if (!a[i].getName().equals(s)) { // debug if (j == a.length - 1) throw new InternalErrorCDE("feature or type not found: looking for " + s); result[j++] = a[i]; } } return result; }
@Override boolean visit(TypeOrFeature i_o) { if (!i_o.isType() && i_o.getName().equals(oldFullFeatureName)) { somethingChanged[0] = true; i_o.setName(newFullFeatureName); } return false; } };
/** * Given a current list of inputs/ outputs, made up of "Types" and "features", make a new list * keeping all the types, and keeping all the features that belong to other types, and adding the * features that are passed in for one particular type in the "features" parameter. * * @param items the items * @param typeName the type name * @param features - * associated with the type * @return the type or feature[] */ private TypeOrFeature[] replaceFeaturesKeepingTypes(TypeOrFeature[] items, String typeName, List features) { List newItems = new ArrayList(); typeName = typeName + ':'; if (null != items) for (int i = 0; i < items.length; i++) { if (items[i].isType() || !items[i].getName().startsWith(typeName)) newItems.add(items[i]); } for (Iterator it = features.iterator(); it.hasNext();) { newItems.add(it.next()); } return (TypeOrFeature[]) newItems.toArray(new TypeOrFeature[newItems.size()]); }
/** Add this crd's capabilities for other downstream aeds. */ private void addCapabilities(CollectionReaderDescription crd) { for (Capability capability : crd.getCollectionReaderMetaData() .getCapabilities()) { for (TypeOrFeature output : capability.getOutputs()) { // LOG.info("add @TypeCapability: " + output.getName()); outputTypes.add(output.getName()); } } }
/** * Match capabilities to. * * @param capabilities the capabilities * @param search the search * @param isInput the is input * @return true, if successful */ private boolean matchCapabilitiesTo(Capability[] capabilities, Pattern search, boolean isInput) { if (null == search) return true; for (int i = 0; i < capabilities.length; i++) { TypeOrFeature[] typeOrFeatures = isInput ? capabilities[i].getInputs() : capabilities[i] .getOutputs(); if (null != typeOrFeatures) { for (int j = 0; j < typeOrFeatures.length; j++) { if (search.matcher(typeOrFeatures[j].getName()).find()) { return true; } } } } return false; }
/** * @see org.apache.uima.analysis_engine.ResultSpecification#removeTypeOrFeature(org.apache.uima.analysis_engine.TypeOrFeature) * This removes the type or feature for all languages. * Beware: there are two possible ToFs one with allFeatures set or not (if they have different languages). */ public void removeTypeOrFeature(TypeOrFeature tof) { String name = tof.getName(); if (tof.isType()) { rsTypesMap.remove(name); } else { int i = name.indexOf(TypeSystem.FEATURE_SEPARATOR); rsTypesMap.remove(name.substring(0, i), name.substring(i+1)); } setCompileNeeded(); }
private void addResultTof(TypeOrFeature tof, String[] langs, boolean replace) { String name = tof.getName(); String typeName = null; String shortFeatName = null; int i = name.indexOf(TypeSystem.FEATURE_SEPARATOR); if (i < 0) { typeName = name; rsTypesMap.add(typeName, tof.isAllAnnotatorFeatures(), langs, replace); } else { typeName = name.substring(0, i); shortFeatName = name.substring(i+1); rsTypesMap.add(typeName, shortFeatName, langs, replace); } setCompileNeeded(); }
/** * Checks that this @param aed is provided with the right {@link Annotation} * s in the upstream of this pipeline, and prints an error log otherwise. * Add this aed's capabilities for other downstream aeds. */ private void checkAndAddCapabilities(AnalysisEngineDescription aed) { for (Capability capability : aed.getAnalysisEngineMetaData() .getCapabilities()) { for (TypeOrFeature input : capability.getInputs()) if (!outputTypes.contains(input.getName())) LOG.error("AnalysisEngine " + aed.getAnnotatorImplementationName() + " is missing input @TypeCapability: " + input.getName()); } for (Capability capability : aed.getAnalysisEngineMetaData() .getCapabilities()) { for (TypeOrFeature output : capability.getOutputs()) { // LOG.info("add @TypeCapability: " + output.getName()); outputTypes.add(output.getName()); } } }
/** * return true if the type has a feature (except all-features) marked as INPUT (OUTPUT). * * @param typeName the type name * @param IO the io * @return true if the type has a feature (except all-features) marked as INPUT (OUTPUT) */ private boolean someFeatureOnType(String typeName, int IO) { // special case for all-features TypeOrFeature[] tofs = (IO == INPUT) ? capability.getInputs() : capability.getOutputs(); // you can remove the "INPUT" or "OUTPUT" designation from a type // even if it has the all-features flag on. String typeNamePlusColon = typeName + ':'; for (int i = 0; i < tofs.length; i++) { if (!tofs[i].isType() && tofs[i].getName().startsWith(typeNamePlusColon)) return true; } return false; }
/** * Instantiates a new adds the capability feature dialog. * * @param aSection the a section * @param aSelectedType the a selected type * @param c the c */ public AddCapabilityFeatureDialog(AbstractSection aSection, Type aSelectedType, Capability c) { super( aSection, "Specify features input and / or output", "Designate by mouse clicking one or more features in the Input and/or Output column, to designate as Input and/or Output press \"OK\""); selectedType = aSelectedType; allFeatures = selectedType.getFeatures().toArray(featureArray0); Arrays.sort(allFeatures); capability = c; TypeOrFeature[] localInputs = c.getInputs(); String typeName = selectedType.getName(); if (null != localInputs) { for (int i = 0; i < localInputs.length; i++) { if (localInputs[i].isType() && typeName.equals(localInputs[i].getName())) { inputNotAllowed = false; break; } } } }
private static void serializeResultSpecification(ResultSpecification rs, CASImpl cas, IntVector resultSpecTypes, IntVector resultSpecFeatures) { TypeOrFeature[] tofs = rs.getResultTypesAndFeatures(); TypeSystemImpl tsImpl = cas.getTypeSystemImpl(); for (int i = 0; i < tofs.length; ++i) { if (tofs[i].isType()) { TypeImpl t = (TypeImpl) tsImpl.getType(tofs[i].getName()); resultSpecTypes.add(t.getCode()); } else { FeatureImpl f = (FeatureImpl) tsImpl.getFeatureByFullName(tofs[i].getName()); resultSpecFeatures.add(f.getCode()); } } }
/** * @see org.apache.uima.analysis_engine.ResultSpecification#addCapabilities(org.apache.uima.resource.metadata.Capability[], * boolean) */ public void addCapabilities(Capability[] capabilities, boolean outputs) { if (null == capabilities) { return; } for (Capability capability : capabilities) { TypeOrFeature[] tofs = outputs ? capability.getOutputs() : capability.getInputs(); for (TypeOrFeature tof : tofs) { String typeName = tof.getName(); if (!tof.isType()) { int i = typeName.indexOf(TypeSystem.FEATURE_SEPARATOR); String shortFeatName = typeName.substring(i+1); typeName = typeName.substring(0, i); rsTypesMap.add(typeName, shortFeatName, capability.getLanguagesSupported(), false); } else { rsTypesMap.add(typeName, tof.isAllAnnotatorFeatures(), capability.getLanguagesSupported(), false); } } } setCompileNeeded(); }