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

📄 xelopesserviceimpl.java

📁 一个数据挖掘软件ALPHAMINERR的整个过程的JAVA版源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 *    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)
  * @author Victor Borichev
  * @version 1.1
  */

package com.prudsys.pdm.Adapters.ServiceAPI;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringReader;
import java.io.StringWriter;
import java.rmi.RemoteException;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;

import com.prudsys.pdm.Adapters.ServiceAPI.DataSource.DataSource;
import com.prudsys.pdm.Adapters.ServiceAPI.DataSource.DataSources;
import com.prudsys.pdm.Adapters.ServiceAPI.DataSource.DatabaseSource;
import com.prudsys.pdm.Adapters.ServiceAPI.DataSource.FileSource;
import com.prudsys.pdm.Core.MiningAlgorithm;
import com.prudsys.pdm.Core.MiningAlgorithmParameter;
import com.prudsys.pdm.Core.MiningAlgorithmSpecification;
import com.prudsys.pdm.Core.MiningDataException;
import com.prudsys.pdm.Core.MiningDataSpecification;
import com.prudsys.pdm.Core.MiningException;
import com.prudsys.pdm.Core.MiningModel;
import com.prudsys.pdm.Core.MiningSettings;
import com.prudsys.pdm.Input.MiningFilterStream;
import com.prudsys.pdm.Input.MiningInputStream;
import com.prudsys.pdm.Input.MiningVector;
import com.prudsys.pdm.Input.Records.Arff.MiningArffStream;
import com.prudsys.pdm.Input.Records.Csv.MiningCsvStream;
import com.prudsys.pdm.Input.Relational.MiningSqlSource;
import com.prudsys.pdm.Input.Relational.MiningSqlStream;
import com.prudsys.pdm.Utils.GeneralUtils;

/**
 * Implements XelopesService interface.
 *
 * @see XelopesService
 */
public class XelopesServiceImpl implements XelopesService
{
  /** Functions supported by this XELOPES service. */
  private static final String[] supportedFunctions = {

    MiningModel.ASSOCIATION_RULES_FUNCTION,
    MiningModel.CLASSIFICATION_FUNCTION,
    MiningModel.CLUSTERING_FUNCTION,
    MiningModel.CUSTOMER_SEQUENTIAL_FUNCTION,
    MiningModel.REGRESSION_FUNCTION,
    MiningModel.SEQUENTIAL_FUNCTION,
    MiningModel.TIME_SERIES_PREDICTION_FUNCTION
  };

  /** Names of all data sources. */
  private String[] sourceNames = null;

  /** Mapping name => data source description. */
  private Hashtable<String, DataSource> source2desc = null;

  /**
   * Constructor.
   */
  public XelopesServiceImpl()
  {
    //MiningAlgorithmSpecification.setAlgorithmsFileName("config/algorithms.xml");
  }

  /**
   * Returns test string.
   *
   * @return test string
   * @throws RemoteException could not return test string
   */
  public String getTestString() throws RemoteException
  {
    return "Implementation of XELOPES Service API";
  }

  /**
   * Returns all model functions that are supported by this service.
   *
   * @return all functions supported
   * @throws RemoteException something went wrong
   */
  public String[] getSupportedFunctions() throws RemoteException
  {
    return supportedFunctions;
  }

  /**
   * Returns all model algorithms that are supported by this service.
   *
   * @return all algorithms supported
   * @throws RemoteException something went wrong
   */
  public String[] getAllSupportedAlgorithms() throws RemoteException
  {
    try {
      String[] algNames = MiningAlgorithmSpecification.getMiningAlgorithms();
      return algNames;
    }
    catch(MiningException ex) {
      throw new RemoteException("Can't return all algorithms cause: " + ex.getMessage());
    }
  }

  /**
   * Returns all algorithms supported for a given function class.
   *
   * @param functionName given function class
   * @return algorithms belonging to this class supported
   * @throws RemoteException can't return algorithms
   */
  public String[] getSupportedAlgorithms(String functionName) throws RemoteException
  {
    try {
      Object[] objs = MiningAlgorithmSpecification.getMiningAlgorithms(functionName);
      String[] algs = new String[objs.length];
      for (int i = 0; i < algs.length; i++)
        algs[i] = objs[i].toString();
      return algs;
    }
    catch (MiningException ex) {
      throw new RemoteException("Can't return algorithms with function name = " + functionName+" cause: "+ex.getMessage());
    }
  }

  /**
   * Returns all service algorithm parameters for a given algorithm.
   *
   * @param algorithmName name of the algorithm
   * @return algorithm parameters supported by this algorithm
   * @throws RemoteException something went wrong
   */
  public ServiceAlgorithmParameter[] getAlgorithmParameters(String algorithmName) throws RemoteException
  {

    ServiceAlgorithmParameter[] sap = null;
    try {
      // Get Mining Agorithm Specification:
      MiningAlgorithmSpecification mas = MiningAlgorithmSpecification.getMiningAlgorithmSpecification(algorithmName,null);

      // Parameters of Mining Settings:
      String className = mas.getClassname();
      if( className == null )
        throw new RemoteException( "algorithm classname attribute expected." );
      MiningAlgorithm algorithm = GeneralUtils.createMiningAlgorithmInstance(className);
      MiningSettings settings   = algorithm.createMiningSettings();
      ServiceAlgorithmParameter[] msPar = LookupService.buildAlgorithmParamFromMiningSettings(settings);
      int nMsPar = 0;
      if (msPar != null) nMsPar = msPar.length;

      // Parameters of Mining Agorithm Specification:
      MiningAlgorithmParameter[] params  = mas.getInputAttribute();
      int nMasPar = 0;
      if (params != null) nMasPar = params.length;
      ServiceAlgorithmParameter[] masPar = new ServiceAlgorithmParameter[nMasPar];
      for (int i = 0; i < nMasPar; i++)
      {
        masPar[i] = new ServiceAlgorithmParameter();
        masPar[i].setName( params[i].getName() );
        masPar[i].setType( params[i].getType() );
        masPar[i].setValue( params[i].getValue() );
        masPar[i].setDescription( params[i].getDescr() );
        masPar[i].setDomain(1);
        masPar[i].setStatus(0);
        masPar[i].setID("");
        masPar[i].setChildIDs("");
      };

      // Build final parameter array:
      sap = new ServiceAlgorithmParameter[ nMsPar + nMasPar ];
      for (int i = 0; i < nMsPar; i++)
        sap[i] = msPar[i];
      for (int i = 0; i < nMasPar; i++)
        sap[i+nMsPar] = masPar[i];
    }
    catch(Exception ex) {
      throw new RemoteException("Can't return algorithms parameters:\n" + getExceptionInfo(ex));
    };

    return sap;
  }

  /**
   * Returns names of all data sources available.
   *
   * @return names of all data sources available
   * @throws RemoteException something went wrong
   */
  public String[] getDataSources() throws RemoteException {

    try {
      if (sourceNames == null) readDataSources("config/datasources.xml");
      return sourceNames;
    }
    catch (Exception ex) {
      throw new RemoteException( getExceptionInfo(ex) );
    }
  }

  /**
   * Returns meta data for a given data source as PMML string.
   *
   * @param sourceName name of data source
   * @return PMML document with data dictionary of data source
   * @throws RemoteException method not supported
   */
  public String getDataSourceMetaData(String sourceName) throws RemoteException {

    try {
      // Open appropriate mining input stream:
      MiningInputStream mis = getInputStreamFromDataSource(sourceName);

      // Get meta data:
      MiningDataSpecification mds = mis.getMetaData();

      // Write meta data to PMML:
      StringWriter writer = new StringWriter();
      mds.writePmml(writer);
      String metaData = writer.getBuffer().toString();

      // Close stream:
      try {
        mis.close();
      }
      catch (Exception ex) {
      };

      return metaData;
    }
    catch(Exception ex) {
      throw new RemoteException("Can't get meta data:\n" + getExceptionInfo(ex));
    }
  }

⌨️ 快捷键说明

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