Example usage for weka.experiment ResultProducer getCompatibilityState

List of usage examples for weka.experiment ResultProducer getCompatibilityState

Introduction

In this page you can find the example usage for weka.experiment ResultProducer getCompatibilityState.

Prototype

String getCompatibilityState();

Source Link

Document

Gets a description of the internal settings of the result producer, sufficient for distinguishing a ResultProducer instance from another with different settings (ignoring those settings set through this interface).

Usage

From source file:py.fpuna.lib.ExtendedDatabaseUtils.java

License:Open Source License

/**
 * Attempts to insert a results entry for the table into the experiment index.
 *
 * @param rp the ResultProducer generating the results
 * @return the name of the created results table
 * @throws Exception if an error occurs.
 *///w ww .j a v  a2 s.  co  m
public String createExperimentIndexEntry(ResultProducer rp) throws Exception {

    if (m_Debug) {
        System.err.println("Creating experiment index entry...");
    }

    // Execute compound transaction
    int numRows = 0;

    // Workaround for MySQL (doesn't support transactions)
    /*
     * if (m_Connection.getMetaData().getDriverName().
     * equals("Mark Matthews' MySQL Driver")) {
     * m_Statement.execute("LOCK TABLES " + EXP_INDEX_TABLE + " WRITE");
     * System.err.println("LOCKING TABLE"); } else {
     */

    // }

    // Get the number of rows
    String query = "SELECT COUNT(*) FROM " + EXP_INDEX_TABLE;
    ResultSet rs = select(query);
    if (m_Debug) {
        System.err.println("...getting number of rows");
    }
    if (rs.next()) {
        numRows = rs.getInt(1);
    }
    close(rs);

    // Add an entry in the index table
    String expType = rp.getClass().getName();
    String expParams = rp.getCompatibilityState();
    query = "INSERT INTO " + EXP_INDEX_TABLE + " VALUES ('" + expType + "', '" + expParams + "', " + numRows
            + " )";
    if (update(query) > 0) {
        if (m_Debug) {
            System.err.println("...create returned resultset");
        }
    }
    close();

    // Finished compound transaction
    // Workaround for MySQL (doesn't support transactions)
    /*
     * if (m_Connection.getMetaData().getDriverName().
     * equals("Mark Matthews' MySQL Driver")) {
     * m_Statement.execute("UNLOCK TABLES");
     * System.err.println("UNLOCKING TABLE"); } else {
     */
    if (!m_setAutoCommit) {
        m_Connection.commit();
        m_Connection.setAutoCommit(true);
    }
    // }

    String tableName = getResultsTableName(rp);
    if (tableName == null) {
        throw new Exception("Problem adding experiment index entry");
    }

    // Drop any existing table by that name (shouldn't occur unless
    // the experiment index is destroyed, in which case the experimental
    // conditions of the existing table are unknown)
    try {
        query = "DROP TABLE " + tableName;
        if (m_Debug) {
            System.err.println(query);
        }
        update(query);
    } catch (SQLException ex) {
        System.err.println(ex.getMessage());
    }
    return tableName;
}

From source file:py.fpuna.lib.ExtendedDatabaseUtils.java

License:Open Source License

/**
 * Gets the name of the experiment table that stores results from a particular
 * ResultProducer./*from ww  w. jav  a 2s  .c  om*/
 *
 * @param rp the ResultProducer
 * @return the name of the table where the results for this ResultProducer are
 * stored, or null if there is no table for this ResultProducer.
 * @throws Exception if an error occurs
 */
public String getResultsTableName(ResultProducer rp) throws Exception {
    // Get the experiment table name, or create a new table if necessary.
    if (m_Debug) {
        System.err.println("Getting results table name...");
    }
    String expType = rp.getClass().getName();
    String expParams = rp.getCompatibilityState();
    String query = "SELECT " + EXP_RESULT_COL + " FROM " + EXP_INDEX_TABLE + " WHERE " + EXP_TYPE_COL + "='"
            + expType + "' AND " + EXP_SETUP_COL + "='" + expParams + "'";
    String tableName = null;
    ResultSet rs = select(query);
    if (rs.next()) {
        tableName = rs.getString(1);
        if (rs.next()) {
            throw new Exception("More than one index entry " + "for experiment config: " + query);
        }
    }
    close(rs);
    if (m_Debug) {
        System.err.println(
                "...results table = " + ((tableName == null) ? "<null>" : EXP_RESULT_PREFIX + tableName));
    }
    return (tableName == null) ? tableName : EXP_RESULT_PREFIX + tableName;
}