📄 miningstoreddata.java
字号:
/*
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/**
* Title: XELOPES Data Mining Library
* Description: The XELOPES library is an open platform-independent and data-source-independent library for Embedded Data Mining.
* Copyright: Copyright (c) 2002 Prudential Systems Software GmbH
* Company: ZSoft (www.zsoft.ru), Prudsys (www.prudsys.com)
* @author Valentine Stepanenko (valentine.stepanenko@zsoft.ru)
* @version 1.0
*/
package com.prudsys.pdm.Input;
import java.io.IOException;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Vector;
import org.omg.cwm.analysis.transformation.ClassifierMap;
import org.omg.cwm.analysis.transformation.FeatureMap;
import org.omg.cwm.analysis.transformation.TransformationMap;
import org.omg.cwm.analysis.transformation.TransformationPackage;
import com.prudsys.pdm.Core.MiningDataSpecification;
import com.prudsys.pdm.Core.MiningException;
/**
* Storage of data in memory. The data is stored in an
* array list variable. The MiningStoredData class can
* be generated from any mining input stream. (Of course,
* the data must fit into memory.)
*
* MiningStoredData implements the java.util.List
* interface and can hence by used very flexible.
*
* Supports the updateble stream type.
*/
public class MiningStoredData extends MiningInputStream implements List
{
// -----------------------------------------------------------------------
// Variables declarations
// -----------------------------------------------------------------------
/** Collection to store MiningData vectors. */
protected ArrayList<Object> miningVectors = new ArrayList<Object>();
/** Iterator to store MiningData vectors. */
protected Iterator<Object> iterator = null;
/** 2-dimensional array to store MiningData vectors. */
protected double[][] matrix = null;
/** Mining input stream from constructor. */
protected MiningInputStream inputStream = null;
// -----------------------------------------------------------------------
// Constructors
// -----------------------------------------------------------------------
/**
* Create empty MiningStoredData.
*/
public MiningStoredData()
{
this.miningVectors = new ArrayList<Object>();
this.iterator = this.iterator();
this.cursorPosition = -1;
}
/**
* Create MiningStoredData for a given mining input stream.
* The data of the stream is completely read in and
* stored in the array list.
*
* @param inputStream mining input stream
*/
public MiningStoredData( MiningInputStream inputStream ) throws IllegalArgumentException, MiningException
{
ArrayList<Object> vectors = new ArrayList<Object>();
if( inputStream == null )
{
throw new IllegalArgumentException( "MiningInputStream can't be null." );
}
while( inputStream.next() )
{
vectors.add( inputStream.read() );
}
this.miningVectors = vectors;
this.iterator = this.iterator();
this.cursorPosition = -1;
this.metaData = inputStream.getMetaData();
this.inputStream = inputStream;
}
/**
* Construct MiningStoredData from another MiningStoredData
* object. Shallow copy of data.
*
* @param miningStoredData object to be copied
*/
public MiningStoredData( MiningStoredData miningStoredData ) throws IllegalArgumentException, MiningException
{
if ( miningStoredData == null )
{
throw new IllegalArgumentException( "MiningStoredData can't be null." );
}
this.miningVectors = miningStoredData.getMiningVectors();
this.iterator = this.iterator();
this.cursorPosition = -1;
this.metaData = miningStoredData.getMetaData();
this.inputStream = miningStoredData;
}
/**
* Construct MiningStoredData from a given array list
* of mining vectors.
*
* BUG Fixed: if the mingVectors only has one Vector, the metaData will be null;
* By: Twang, on Feb. 16, 2005.
*
* @param miningVectors given array list
*/
public MiningStoredData( ArrayList<Object> miningVectors )
{
if( miningVectors == null )
{
throw new IllegalArgumentException( "ArrayList miningVectors can't be null." );
}
this.miningVectors = miningVectors;
this.iterator = this.iterator();
this.cursorPosition = -1;
//if( miningVectors != null && miningVectors.size() > 1 )
//>>Modified by TWang. [Bug 17]
if( miningVectors != null && miningVectors.size() > 0 )
{
this.metaData = ( (MiningVector)miningVectors.get( 0 ) ).getMetaData();
}
}
// -----------------------------------------------------------------------
// Getter and setter methods
// -----------------------------------------------------------------------
/**
* Returns supported stream methods.
*
* @return supported stream methods
*/
public Enumeration<String> getSupportedStreamMethods() {
Vector<String> suppmeth = new Vector<String>();
suppmeth.addElement("reset");
suppmeth.addElement("move");
suppmeth.addElement("updateSetMetaData");
suppmeth.addElement("updateRemoveAllVectors");
suppmeth.addElement("updateAppendVector");
return suppmeth.elements();
}
/**
* Finds physical vector model (CWM Resource Package "Object").
* This is just the meta data wrapped in a Package.
*
* @exception MiningException couldn't obtain physical model
*/
public void findPhysicalModel() throws MiningException {
org.omg.cwm.objectmodel.core.CorePackage cp = com.prudsys.pdm.Cwm.CWMCompletePackage.getCWMCompletePackage().getCore();
org.omg.cwm.objectmodel.core.Package dataPackage = cp.getPackage().createPackage("StoredData package", null);
dataPackage.addOwnedElement(metaData);
physicalModel = dataPackage;
}
/**
* Returns the CWM mapping from the physical to the logical data model.
* This is an identical transformation.
*
* @return transformation of physical to logical data model
* @throws MiningException couldn't get transformation
*/
public org.omg.cwm.analysis.transformation.TransformationMap getPhysicalToLogicalModelTransformation()
throws MiningException {
com.prudsys.pdm.Cwm.CWMCompletePackage cwmFactory =
com.prudsys.pdm.Cwm.CWMCompletePackage.getCWMCompletePackage();
TransformationPackage tpg = cwmFactory.getTransformation();
TransformationMap tm = tpg.getTransformationMap().createTransformationMap();
ClassifierMap cm = tpg.getClassifierMap().createClassifierMap();
tm.addOwnedElement(cm);
for (int i = 0; i < metaData.getAttributesNumber(); i++) {
FeatureMap fm = tpg.getFeatureMap().createFeatureMap();
fm.addSource( metaData.getMiningAttribute(i) );
fm.addTarget( metaData.getMiningAttribute(i) );
cm.addFeatureMap(fm);
};
metaData.addOwnedElement(tm);
physicalModel.addOwnedElement(tm);
return tm;
}
/**
* Returns data as matrix.
*
* @return data as matrix
*/
public double[][] getMatrix() throws MiningException
{
int size = miningVectors.size();
MiningVector vector = null;
matrix = new double[size][];
for( int i = 0; i < size; i++ )
{
vector = (MiningVector)miningVectors.get( i );
matrix[i] = vector.getValues();
}
return matrix;
}
/**
* Allows to set the meta data explicitely. Required if the empty
* constructor was applied because the dynamic adding of vectors
* does not set the meta data.
*
* @param metaData the meta data of this stream
*/
public void setMetaData(MiningDataSpecification metaData) {
this.metaData = metaData;
}
/**
* Returns input stream from the constructor.
*
* @return mining input stream
*/
public MiningInputStream getInputStream() {
return inputStream;
}
/**
* Returns array list of mining vectors.
*
* @return array list of mining vectors
*/
public ArrayList<Object> getMiningVectors() {
return miningVectors;
}
/**
* Returns number of vectors of mining data.
*
* @return number of vectors
*/
public int getVectorsNumber() {
return size();
}
// -----------------------------------------------------------------------
// General stream methods
// -----------------------------------------------------------------------
/**
* Opens mining stored data stream. This method can be left out because
* does nothing.
*
* @exception MiningException if a mining source access error occurs
*/
public void open() throws MiningException
{
}
/**
* Closes mining stored data stream. This method can be left out because
* does nothing.
*
* @exception MiningException if a mining source access error occurs
*/
public void close() throws MiningException
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -