Example usage for weka.filters.unsupervised.attribute Remove useFilter

List of usage examples for weka.filters.unsupervised.attribute Remove useFilter

Introduction

In this page you can find the example usage for weka.filters.unsupervised.attribute Remove useFilter.

Prototype

public static Instances useFilter(Instances data, Filter filter) throws Exception 

Source Link

Document

Filters an entire set of instances through a filter and returns the new set.

Usage

From source file:org.opentox.jaqpot3.qsar.util.AttributeCleanup.java

License:Open Source License

private Instances remove(Instances input) throws QSARException {
    Remove remove = new Remove();
    ArrayList<Integer> attributeList = new ArrayList<Integer>();

    for (int i = 0; i < input.numAttributes(); i++) {
        Attribute attribute = input.attribute(i);
        if ((attribute.name().equals("compound_uri") || attribute.name().equalsIgnoreCase("uri"))
                && isKeepCompoundURI()) {
            continue;
        } else if (!isKeepCompoundURI()
                && (attribute.name().equals("compound_uri") || attribute.name().equalsIgnoreCase("uri"))) {
            attributeList.add(i);/*from w  ww  .  ja v a2s.  c  o  m*/
        }
        if (attribute.isNominal() && toBeRemoved.contains(AttributeType.nominal)) {
            attributeList.add(i);
            continue;
        } else if (attribute.isString() && toBeRemoved.contains(AttributeType.string)) {
            attributeList.add(i);
            continue;
        } else if (attribute.isNumeric() && toBeRemoved.contains(AttributeType.numeric)) {
            attributeList.add(i);
            continue;
        }
    }
    int[] attributeIndices = new int[attributeList.size()];
    for (int i = 0; i < attributeList.size(); i++) {
        attributeIndices[i] = attributeList.get(i).intValue();
    }
    remove.setAttributeIndicesArray(attributeIndices);
    try {
        remove.setInputFormat(input);
    } catch (Exception ex) {
        throw new QSARException("FilteringError: Invalid input format " + "for attribute-type removing filter",
                ex);
    }
    Instances output;
    try {
        output = Remove.useFilter(input, remove);
    } catch (Exception ex) {
        throw new QSARException("FilteringError: The filter is unable to " + "remove the specified types :"
                + toBeRemoved.toString(), ex);
    }
    return output;

}