⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 resultsetexamplesource.java

📁 一个很好的LIBSVM的JAVA源码。对于要研究和改进SVM算法的学者。可以参考。来自数据挖掘工具YALE工具包。
💻 JAVA
字号:
/*
 *  YALE - Yet Another Learning Environment
 *  Copyright (C) 2001-2004
 *      Simon Fischer, Ralf Klinkenberg, Ingo Mierswa, 
 *          Katharina Morik, Oliver Ritthoff
 *      Artificial Intelligence Unit
 *      Computer Science Department
 *      University of Dortmund
 *      44221 Dortmund,  Germany
 *  email: yale-team@lists.sourceforge.net
 *  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.operator.io;

import edu.udo.cs.yale.operator.Operator;
import edu.udo.cs.yale.operator.IOObject;
import edu.udo.cs.yale.operator.OperatorException;
import edu.udo.cs.yale.operator.UserError;
import edu.udo.cs.yale.operator.parameter.*;
import edu.udo.cs.yale.tools.DatabaseHandler;
import edu.udo.cs.yale.example.ExampleSet;
import edu.udo.cs.yale.example.ExampleTable;
import edu.udo.cs.yale.example.MemoryExampleTable;
import edu.udo.cs.yale.example.DataRowReader;
import edu.udo.cs.yale.example.ResultSetDataRowReader;
import edu.udo.cs.yale.example.DataRowFactory;
import edu.udo.cs.yale.example.Attribute;

import java.util.List;
import java.util.Iterator;
import java.sql.ResultSet;
import java.sql.SQLException;

/** Abstract superclass for operators that provide access to an {@link ExampleSet} via a {@link ResultSet}.
 *  @version $Id: ResultSetExampleSource.java,v 1.3 2004/09/01 12:39:50 ingomierswa Exp $
 */
public abstract class ResultSetExampleSource extends Operator {

    private static final Class[] INPUT_CLASSES = {};
    private static final Class[] OUTPUT_CLASSES = { ExampleSet.class };

    /** Returns a {@link ResultSet}. */
    public abstract ResultSet getResultSet() throws OperatorException;

    /** Since the {@link ResultSet} does not provide information about possible values
     *  of nominal attributes, subclasses must set these by implementing this method. 
     *  @param attributeList List of {@link Attribute} */
    public abstract void setNominalValues(List attributeList, 
					  ResultSet resultSet,
					  Attribute label) throws OperatorException;

    public IOObject[] apply() throws OperatorException {
	int dataRowType   = getParameterAsInt("datamanagement");
	ResultSet resultSet = getResultSet();
	List attributeList  = null;
	try {
	    attributeList  = DatabaseHandler.createAttributes(resultSet);
	} catch (SQLException e) {
	    throw new UserError(this, e, 304, e.getMessage());
	}
	setNominalValues(attributeList, resultSet, find(attributeList, getParameterAsString("label_attribute")));
	DataRowReader reader = new ResultSetDataRowReader(new DataRowFactory(dataRowType),
							  attributeList,
							  resultSet);
	ExampleTable table = new MemoryExampleTable(attributeList, reader);
	return new IOObject[] { createExampleSet(table) };
    }

    private static Attribute find(List attributeList, String name) throws OperatorException {
	if (name == null) return null;
	Iterator i = attributeList.iterator();
	while (i.hasNext()) {
	    Attribute attribute = (Attribute)i.next();
	    if (attribute.getName().equals(name))
		return attribute;
	}
	throw new UserError(null, 111, name);
    }

    protected ExampleSet createExampleSet(ExampleTable table) throws OperatorException {
	String labelName  = getParameterAsString("label_attribute");
	String weightName = getParameterAsString("weight_attribute");
	String idName     = getParameterAsString("id_attribute");
	Attribute label  = table.findAttribute(labelName); 
	Attribute weight = table.findAttribute(weightName);
	Attribute id     = table.findAttribute(idName);
	return table.createCompleteExampleSet(label, null, weight, id);
    }

    public List getParameterTypes() {
	List types = super.getParameterTypes();
	ParameterType type = new ParameterTypeString("label_attribute", "The (case sensitive) name of the label attribute");
	type.setExpert(false);
	types.add(type);
	types.add(new ParameterTypeString("weight_attribute", "The (case sensitive) name of the weight attribute"));
	types.add(new ParameterTypeString("id_attribute", "The (case sensitive) name of the id attribute"));
	types.add(new ParameterTypeCategory("datamanagement", "Determines, how the data is represented internally.",
					    DataRowFactory.TYPE_NAMES, DataRowFactory.TYPE_DOUBLE_ARRAY));
	return types;
    }

    public Class[] getInputClasses() {
	return INPUT_CLASSES;
    }

    public Class[] getOutputClasses() {
	return OUTPUT_CLASSES;
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -