public static void main(String[] args) throws Exception { // The label passed to the constructor does not affect the webapp final AttributeValueSet attributeValueSet = new AttributeValueSet("Example set"); // Add all the attributes you want to change to a non-default value. // You can use attribute keys from Workbench Attribute Info view or the manuals. Map<String, Object> attributes = new HashMap<String, Object>(); LingoClusteringAlgorithmDescriptor.attributeBuilder(attributes) .desiredClusterCountBase(20) .matrixReducer() .factorizationQuality(FactorizationQuality.MEDIUM) .factorizationFactory(LocalNonnegativeMatrixFactorizationFactory.class); CompletePreprocessingPipelineDescriptor.attributeBuilder(attributes) .documentAssigner() .exactPhraseAssignment(true); TermDocumentMatrixBuilderDescriptor.attributeBuilder(attributes).titleWordsBoost(2.5); attributeValueSet.setAttributeValues(attributes); // We'll need to wrap the exported attribute values in a AttributeValueSets, // even if we want to export just one set. final AttributeValueSets attributeValueSets = new AttributeValueSets(); attributeValueSets.addAttributeValueSet("example-id", attributeValueSet); attributeValueSets.serialize(System.out); }
/** Default attribute value set for a given component. */ @SuppressWarnings("unchecked") static AttributeValueSet getDefaultAttributeValueSet(String componentId) { BindableDescriptor desc = WorkbenchCorePlugin.getDefault().getComponentDescriptor(componentId); final HashMap<String, Object> defaults = Maps.newHashMap(); for (Map.Entry<String, AttributeDescriptor> e : desc.flatten().only(Input.class).attributeDescriptors.entrySet()) { defaults.put(e.getKey(), e.getValue().defaultValue); } removeSpecialKeys(defaults); removeInternalNonConfigurationAttributes(defaults, componentId); AttributeValueSet result = new AttributeValueSet("defaults"); result.setAttributeValues(defaults); return result; }
/** * Creates an {@link AttributeValueSets} for saving as XML. The result contains two sets: * components defaults and the overriding values the user changed using the editor. Additionally, * {@link Internal} non-configuration and a number of special attributes are removed. */ private AttributeValueSets createAttributeValueSetsToSave(Map<String, Object> overrides) { final String componentId = getComponentId(); assert componentId != null; final AttributeValueSet defaults = getDefaultAttributeValueSet(componentId); /* * Create an AVS for the default values and a based-on AVS with overridden values. */ final AttributeValueSet overridenAvs = new AttributeValueSet("overridden-attributes", defaults); removeSpecialKeys(overrides); removeInternalNonConfigurationAttributes(overrides, componentId); removeKeysWithDefaultValues(overrides, defaults); overrides.keySet().retainAll(defaults.getAttributeValues().keySet()); overridenAvs.setAttributeValues(overrides); // Flatten and save. final AttributeValueSets merged = new AttributeValueSets(); merged.addAttributeValueSet(overridenAvs.label, overridenAvs); merged.addAttributeValueSet(defaults.label, defaults); merged.setDefaultAttributeValueSetId(overridenAvs.label); return merged; }