📄 attribute.java
字号:
/* * YALE - Yet Another Learning Environment * Copyright (C) 2002, 2003 * Simon Fischer, Ralf Klinkenberg, Ingo Mierswa, * Katharina Morik, Oliver Ritthoff * Artificial Intelligence Unit * Computer Science Department * University of Dortmund * 44221 Dortmund, Germany * email: yale@ls8.cs.uni-dortmund.de * web: http://yale.cs.uni-dortmund.de/ * * 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 2 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, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA. */package edu.udo.cs.yale.example;import edu.udo.cs.yale.tools.Ontology;import edu.udo.cs.yale.tools.LogService;import edu.udo.cs.yale.tools.Ontology;import java.util.Map;import java.util.Collection;import java.util.HashMap;import java.util.Enumeration;import java.io.Serializable;import java.io.File;/** This class holds all information on a single attribute. * <ul> * <li>the name * <li>the index, i.e. its column in the {@link ExampleTable} and {@link DataRow} * <li>the value type (nominal, numerical, ...) * <li>the block type (single value, time series...) * <li>a number indicating the block it belongs to (important for time series only) * <li>minimum, maximum and average of the values of the attribute * <li>information about how the attribute was generated * </ul> * * @see edu.udo.cs.yale.tools.Ontology#ATTRIBUTE_VALUE_TYPE * @see edu.udo.cs.yale.tools.Ontology#ATTRIBUTE_BLOCK_TYPE * @yale.todo Replace {@link Attribute#indexToSymbolMap} by an ArrayList. * * @author simon, ingo * @version $Id: Attribute.java,v 2.13 2003/09/10 13:02:06 fischer Exp $ */public class Attribute implements Cloneable, Serializable { /** This attribute value should is used as poitive if the value type is CLASSIFICATION. */ public static final String POSITIVE_CLASS = "+1"; /** This attribute value should is used as negative if the value type is CLASSIFICATION. */ public static final String NEGATIVE_CLASS = "-1"; /** Names for SI-Units. */ private static final String UNIT_NAME[] = {"m", "s","kg", "A", "K", "cd", "mol"}; public static final int UNDEFINED_ATTRIBUTE_INDEX = -1; /** The index that will be assigned to the first class. */ public static final int FIRST_CLASS_INDEX = 1; /** The map between symbolic values and their indices. */ private Map symbolToIndexMap, indexToSymbolMap; private int nextFreeSymbolMapIndex = FIRST_CLASS_INDEX; /** The current highest id for generated symbols. Is increased each time a new symbol is generated. */ private static int genSym = 1; private static final String GENSYM_PREFIX = "gensym"; /** block number: the block number has not been set properly. */ public final static int UNDEFINED_BLOCK_NR = -1; /** optionally contains the name of the attribute. */ private String name; /** Name of the function if this attribute was generated. */ private String generatingFunctionName; /** If this attribute was generated, this array of attributes holds * the input arguments of the generation. */ private Attribute[] generatingFunctionArguments; /** This flag is true if the generating function should be displayed as infix operator. */ private boolean generatingFunctionInfix; /** All attributes belonging to the same block should have a common * blockNr. Single values should have a unique block number. */ private int blockNr = UNDEFINED_BLOCK_NR; /** An int indicating the value type in terms of the Ontology.ATTRIBUTE_VALUE_TYPE. */ private int valueType = Ontology.ATTRIBUTE_VALUE; /** An int indicating the block type in terms of the Ontology.ATTRIBUTE_BLOCK_TYPE. */ private int blockType = Ontology.ATTRIBUTE_BLOCK; /** Index of this attribute in its ExampleTable. */ private int index = UNDEFINED_ATTRIBUTE_INDEX; /** Maximum of all attribute values. */ private double maximum; /** Minimum of all attribute values. */ private double minimum; /** Average of all attribute values. */ private double average; /** Unit exponents. */ private int[] unit; /** Creates an undefined attribute with most general types and generated name. */ public Attribute() { name = createName(); this.generatingFunctionName = this.name; this.generatingFunctionArguments = null; this.generatingFunctionInfix = false; } /** Use this constructor only to create a reference attribute that specifies * the return value of a generator. */ public Attribute(int valueType, int blockType) { this (null, valueType, blockType, UNDEFINED_BLOCK_NR, null); } /** Creates a simple, not generated attribute. */ public Attribute(String name, int valueType, int blockType, int blockNr, String units) { this.name = (name != null) ? name : createName(); setValueType(valueType); this.blockType = blockType; this.blockNr = blockNr; this.index = -1; this.unit = new int[UNIT_NAME.length]; parseUnits(units); this.generatingFunctionName = this.name; this.generatingFunctionArguments = null; this.generatingFunctionInfix = false; } /** Creates a simple, not generated attribute with most general types. */ public Attribute(String name) { this(name, Ontology.ATTRIBUTE_VALUE, Ontology.ATTRIBUTE_BLOCK, UNDEFINED_BLOCK_NR, null); } /** Creates a new generated attribute. */ public Attribute(int valueType, int blockType, String functionName, Attribute[] arguments, boolean infix, int blockNumber, int[] unit) { this.name = createName(); setValueType(valueType); this.blockType = blockType; if (unit == null) { this.unit = new int[UNIT_NAME.length]; } else { this.unit = unit; } this.generatingFunctionName = functionName; this.generatingFunctionArguments = arguments; this.generatingFunctionInfix = infix && (arguments.length == 2); this.blockNr = blockNumber; } /** Creates a new attribute which is still to generate. */ public Attribute(String functionName, Attribute[] arguments) { this(Ontology.ATTRIBUTE_VALUE, Ontology.ATTRIBUTE_BLOCK, functionName, arguments, false, UNDEFINED_BLOCK_NR,null); } /** Creates a new attribute that has the same properties as argument. */ public Attribute(Attribute argument, String functionName) { this(argument); this.name = functionName+"("+argument.name+")"; this.generatingFunctionName = functionName; this.generatingFunctionArguments = new Attribute[] { argument }; this.generatingFunctionInfix = false; this.index = -1; } /** Private clone constructor. */ private Attribute(Attribute a) { this.valueType = a.valueType; this.blockType = a.blockType; this.name = new String(a.name); this.blockNr = a.blockNr; this.index = a.index; this.symbolToIndexMap = a.symbolToIndexMap; this.indexToSymbolMap = a.indexToSymbolMap; this.generatingFunctionName = a.generatingFunctionName; this.generatingFunctionArguments = a.generatingFunctionArguments; this.generatingFunctionInfix = a.generatingFunctionInfix; this.unit = new int[a.unit.length]; System.arraycopy(a.unit, 0, this.unit, 0, a.unit.length); this.maximum = a.maximum; this.minimum = a.minimum; this.average = a.average; } /** Clones this attribute. */ public Object clone() { return new Attribute(this); } /** * Get the value of name. * @return value of name. */ public String getName() { return name; } /** * Set the value of name. * @param v Value to assign to name. */ public void setName(String v) { this.name = v; } /** * Get the value of minimum. * @return value of minimum. */ public double getMinimum() { return minimum; } /** * Set the value of minimum. * @param v Value to assign to minimum. */ public void setMinimum(double v) { this.minimum = v; } /** * Get the value of average. * @return value of average. */ public double getAverage() { return average; } /** Set the value of average. * @param v Value to assign to average. */ public void setAverage(double v) { this.average = v; } /** Get the value of maximum. * @return value of maximum. */ public double getMaximum() { return maximum; } /** Set the value of maximum. * @param v Value to assign to maximum. */ public void setMaximum(double v) { this.maximum = v; } /** Returns a string that describes how this attribute was generated * from other attributes. */ public String getConstructionDescription() { return getConstructionDescription(true); } /** Returns a string that describes how this attribute was generated * from other attributes. * @param useInfix Whether or not to use infix notation */ public String getConstructionDescription(boolean useInfix) { if (generatingFunctionArguments == null) return generatingFunctionName; if ((generatingFunctionInfix) && (useInfix)) { return "("+ generatingFunctionArguments[0].getConstructionDescription() + generatingFunctionName +
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -