📄 simpleexampleset.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.operator.OperatorException;import edu.udo.cs.yale.operator.FatalException;import edu.udo.cs.yale.tools.LogService;import edu.udo.cs.yale.tools.Ontology;import java.util.ArrayList;import java.util.Set;import java.util.Map;import java.util.HashMap;import java.util.Collection;/** A simple implementation of ExampleSet without any specials. */public class SimpleExampleSet extends AbstractExampleSet { /** The list of attributes contained in this example set. */ private ArrayList attributes = new ArrayList(); /** Maps attribute names to names. */ private Map attributeNameMap = new HashMap(); /** A map to store user data in. */ private Map userDataMap = new HashMap(); /** Maps names of named special attributes to {@link Attribute}s */ private Map specialAttributeMap = new HashMap(); /** The table used for reading the examples from. */ private ExampleTable exampleTable; /** Clone constructor. */ public SimpleExampleSet(SimpleExampleSet exampleSet) { super(exampleSet); this.exampleTable = exampleSet.exampleTable; this.specialAttributeMap = new HashMap(); this.specialAttributeMap.putAll(exampleSet.specialAttributeMap); this.attributeNameMap.putAll(exampleSet.attributeNameMap); this.attributes.addAll(exampleSet.attributes); this.userDataMap.putAll(exampleSet.userDataMap); } /** Private setter constructor. */ private SimpleExampleSet(Attribute label, Attribute predictedLabel, Attribute weight, Attribute idAttribute) { this.setLabel(label); this.setPredictedLabel(predictedLabel); this.setWeight(weight); this.setIdAttribute(idAttribute); } /** Constructs a new SimpleExampleSet backed by the given example table. * The example set initially does not have any special attributes. */ public SimpleExampleSet(ExampleTable exampleTable, Collection regularAttributes) { this.exampleTable = exampleTable; addAllAttributes(regularAttributes); } /** Constructs a new SimpleExampleSet backed by the given example table. * All attributes in the table apart from the special attributes become normal * attributes. */ public SimpleExampleSet(ExampleTable exampleTable, Attribute label, Attribute predictedLabel, Attribute weight, Attribute idAttribute) { this(label, predictedLabel, weight, idAttribute); this.exampleTable = exampleTable; for (int i = 0; i < exampleTable.getNumberOfAttributes(); i++ ) { Attribute attribute = exampleTable.getAttribute(i); if (((label == null) || (attribute.getIndex() != label.getIndex())) && ((predictedLabel == null) || (attribute.getIndex() != predictedLabel.getIndex())) && ((idAttribute == null) || (attribute.getIndex() != idAttribute.getIndex())) && ((weight == null) || (attribute.getIndex() != weight.getIndex()))) { addAttribute(attribute); } } }// public SimpleExampleSet(ExampleTable exampleTable,// Collection attributeList,// Attribute label,// Attribute predictedLabel,// Attribute weight,// Attribute idAttribute) {// this(label, predictedLabel, weight, idAttribute);// this.exampleTable = exampleTable;// addAllAttributes(attributeList);// } public void addAttribute(Attribute attribute) { if (attributeNameMap.get(attribute.getName()) != null) throw new RuntimeException("Attribute name already used: "+attribute.getName()); attributeNameMap.put(attribute.getName(), attribute); attributes.add(attribute); clearUserData(); } public void removeAttribute(Attribute attribute) { if (!attributes.remove(attribute)) throw new java.util.NoSuchElementException("Attribute "+attribute.getName() + " is not in example set."); attributeNameMap.remove(attribute.getName()); clearUserData(); } public ExampleTable getExampleTable() { return exampleTable; } public int getNumberOfAttributes() { return attributes.size(); } public Attribute getAttribute(int index) { return (Attribute)attributes.get(index); } public Attribute getAttribute(String name) { return (Attribute)attributeNameMap.get(name); } public Attribute getSpecialAttribute(String name) { return (Attribute)specialAttributeMap.get(name); } public void setSpecialAttribute(String name, Attribute attribute) { specialAttributeMap.put(name, attribute); } public int getSize() { return exampleTable.getSize(); } // -------------------- user data -------------------- public void clearUserData() { userDataMap.clear(); } public void setUserData(String key, Object data) { if (key == null) throw new IllegalArgumentException("Key must not be null!"); userDataMap.put(key, data); } public Object getUserData(String key) { if (key == null) throw new IllegalArgumentException("Key must not be null!"); Object data = userDataMap.get(key); return data; } public Set getUserDataKeys() { return userDataMap.keySet(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -