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);
  }
Exemplo n.º 2
0
  /** 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;
  }
Exemplo n.º 3
0
  /** Remove these keys whose value is identical to the defaults. */
  private static void removeKeysWithDefaultValues(
      Map<String, Object> overrides, AttributeValueSet defaults) {
    Iterator<Map.Entry<String, Object>> i = overrides.entrySet().iterator();
    while (i.hasNext()) {
      final Map.Entry<String, Object> e = i.next();
      final String key = e.getKey();
      final Object value = e.getValue();

      if (ObjectUtils.equals(value, defaults.getAttributeValue(key))) {
        i.remove();
      }
    }
  }
Exemplo n.º 4
0
  /**
   * 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;
  }