/*
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see .
 */

/*
 *    RenameAttribute.java
 *    Copyright (C) 2009-2012 University of Waikato, Hamilton, New Zealand
 *
 */

package weka.filters.unsupervised.attribute;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.Vector;

import weka.core.*;
import weka.core.Capabilities.Capability;
import weka.filters.SimpleStreamFilter;

/**
 *  This filter is used for renaming attributes.
* Regular expressions can be used in the matching and replacing.
* See Javadoc of java.util.regex.Pattern class for more information:
* http://java.sun.com/javase/6/docs/api/java/util/regex/Pattern.html *

* * * Valid options are: *

* *

 * -find <regexp>
 *  The regular expression that the attribute names must match.
 *  (default: ([\s\S]+))
 * 
* *
 * -replace <string>
 *  The string to replace the regular expression of matching attributes with.
 *  Cannot be used in conjunction with '-remove'.
 *  (default: $0)
 * 
* *
 * -remove
 *  In case the matching string needs to be removed instead of replaced.
 *  Cannot be used in conjunction with '-replace <string>'.
 *  (default: off)
 * 
* *
 * -all
 *  Replaces all occurrences instead of just the first.
 *  (default: only first occurrence)
 * 
* *
 * -R <range>
 *  The attribute range to work on.
 * This is a comma separated list of attribute indices, with "first" and "last" valid values.
 *  Specify an inclusive range with "-".
 *  E.g: "first-3,5,6-10,last".
 *  (default: first-last)
 * 
* *
 * -V
 *  Inverts the attribute selection range.
 *  (default: off)
 * 
* * * * @author fracpete (fracpete at waikato dot ac dot nz) * @version $Revision: 14508 $ */ public class RenameAttribute extends SimpleStreamFilter implements WeightedInstancesHandler, WeightedAttributesHandler { /** for serialization. */ private static final long serialVersionUID = 4216491776378279596L; /** the regular expression that the attribute names have to match. */ protected String m_Find = "([\\s\\S]+)"; /** the regular expression to replace the attribute name with. */ protected String m_Replace = "$0"; /** the attribute range to work on. */ protected Range m_AttributeIndices = new Range("first-last"); /** whether to replace all occurrences or just the first. */ protected boolean m_ReplaceAll = false; /** * Returns a string describing this filter. * * @return a description of the filter suitable for displaying in the * explorer/experimenter gui */ @Override public String globalInfo() { return "This filter is used for renaming attributes.\n\n" + "Regular expressions can be used in the matching and replacing.\n\n" + "See Javadoc of java.util.regex.Pattern class for more information:\n" + "http://java.sun.com/javase/6/docs/api/java/util/regex/Pattern.html"; } /** * Returns an enumeration describing the available options. * * @return an enumeration of all the available options. */ @Override public Enumeration

Ads help maintain this website.