All Downloads are FREE. Search and download functionalities are using the official Maven repository.

weka.filters.unsupervised.attribute.SortLabels Maven / Gradle / Ivy

Go to download

The Waikato Environment for Knowledge Analysis (WEKA), a machine learning workbench. This is the stable version. Apart from bugfixes, this version does not receive any other updates.

There is a newer version: 3.8.6
Show newest version
/*
 *   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 .
 */

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

package weka.filters.unsupervised.attribute;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Enumeration;
import java.util.Vector;

import weka.core.Attribute;
import weka.core.Capabilities;
import weka.core.Capabilities.Capability;
import weka.core.DenseInstance;
import weka.core.Instance;
import weka.core.Instances;
import weka.core.Option;
import weka.core.Range;
import weka.core.RevisionUtils;
import weka.core.SelectedTag;
import weka.core.Tag;
import weka.core.Utils;
import weka.filters.SimpleStreamFilter;

/**
 *  A simple filter for sorting the labels of nominal
 * attributes.
 * 

* * * Valid options are: *

* *

 * -D
 *  Turns on output of debugging information.
 * 
* *
 * -R <index1,index2-index4,...>
 *  Specify list of string attributes to convert to words.
 *  (default: select all relational attributes)
 * 
* *
 * -V
 *  Inverts the matching sense of the selection.
 * 
* *
 * -S <CASE|NON-CASE>
 *  Determines the type of sorting:
 *  CASE = Case-sensitive
 *  NON-CASE = Case-insensitive
 *  (default: CASE)
 * 
* * * * @author fracpete (fracpete at waikato dot ac dot nz) * @version $Revision: 12395 $ */ public class SortLabels extends SimpleStreamFilter { /** for serialization. */ private static final long serialVersionUID = 7815204879694105691L; /** * Represents a case-sensitive comparator for two strings. * * @author fracpete (fracpete at waikato dot ac dot nz) * @version $Revision: 12395 $ */ public static class CaseSensitiveComparator implements Comparator, Serializable { /** for serialization. */ private static final long serialVersionUID = 7071450356783873277L; /** * compares the two strings, returns -1 if o1 is smaller than o2, 0 if equal * and +1 if greater. * * @param o1 the first string to compare * @param o2 the second string to compare * @return returns -1 if o1 is smaller than o2, 0 if equal and +1 if greater */ @Override public int compare(String o1, String o2) { String s1; String s2; if ((o1 == null) && (o2 == null)) { return 0; } else if (o1 == null) { return -1; } else if (o2 == null) { return +1; } s1 = o1; s2 = o2; return s1.compareTo(s2); } } /** * Represents a case-insensitive comparator for two strings. * * @author fracpete (fracpete at waikato dot ac dot nz) * @version $Revision: 12395 $ */ public static class CaseInsensitiveComparator implements Comparator, Serializable { /** for serialization. */ private static final long serialVersionUID = -4515292733342486066L; /** * compares the two strings, returns -1 if o1 is smaller than o2, 0 if equal * and +1 if greater. * * @param o1 the first string to compare * @param o2 the second string to compare * @return returns -1 if o1 is smaller than o2, 0 if equal and +1 if greater */ @Override public int compare(String o1, String o2) { String s1; String s2; if ((o1 == null) && (o2 == null)) { return 0; } else if (o1 == null) { return -1; } else if (o2 == null) { return +1; } s1 = o1; s2 = o2; return s1.toLowerCase().compareTo(s2.toLowerCase()); } } /** sorts the strings case-sensitive. */ public final static int SORT_CASESENSITIVE = 0; /** sorts the strings case-insensitive. */ public final static int SORT_CASEINSENSITIVE = 1; /** Tag allowing selection of sort type. */ public final static Tag[] TAGS_SORTTYPE = { new Tag(SORT_CASESENSITIVE, "case", "Case-sensitive"), new Tag(SORT_CASEINSENSITIVE, "non-case", "Case-insensitive") }; /** * the range of attributes to process (only relational ones will be * processed). */ protected Range m_AttributeIndices = new Range("first-last"); /** the new order for the labels. */ protected int[][] m_NewOrder = null; /** the sort type. */ protected int m_SortType = SORT_CASEINSENSITIVE; /** the comparator to use for sorting. */ protected Comparator m_Comparator = new CaseSensitiveComparator(); /** * 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 "A simple filter for sorting the labels of nominal attributes."; } /** * Returns an enumeration describing the available options. * * @return an enumeration of all the available options. */ @Override public Enumeration




© 2015 - 2024 Weber Informatics LLC | Privacy Policy