本文整理汇总了Java中weka.experiment.ResultProducer类的典型用法代码示例。如果您正苦于以下问题:Java ResultProducer类的具体用法?Java ResultProducer怎么用?Java ResultProducer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ResultProducer类属于weka.experiment包,在下文中一共展示了ResultProducer类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: isKeyInTable
import weka.experiment.ResultProducer; //导入依赖的package包/类
/**
* Executes a database query to see whether a result for the supplied key is
* already in the database.
*
* @param tableName the name of the table to search for the key in
* @param rp the ResultProducer who will generate the result if required
* @param key the key for the result
* @return true if the result with that key is in the database already
* @throws Exception if an error occurs
*/
protected boolean isKeyInTable(String tableName, ResultProducer rp,
Object[] key) throws Exception {
String query = "SELECT Key_Run" + " FROM " + tableName;
String[] keyNames = rp.getKeyNames();
if (keyNames.length != key.length) {
throw new Exception("Key names and key values of different lengths");
}
boolean first = true;
for (int i = 0; i < key.length; i++) {
if (key[i] != null) {
if (first) {
query += " WHERE ";
first = false;
} else {
query += " AND ";
}
query += "Key_" + keyNames[i] + '=';
if (key[i] instanceof String) {
query += "'" + processKeyString(key[i].toString()) + "'";
} else {
query += key[i].toString();
}
}
}
boolean retval = false;
ResultSet rs = select(query);
if (rs.next()) {
retval = true;
if (rs.next()) {
throw new Exception("More than one result entry " + "for result key: "
+ query);
}
}
close(rs);
return retval;
}
开发者ID:marcioadr88,项目名称:weka-datasource-extension,代码行数:48,代码来源:ExtendedDatabaseUtils.java
示例2: getResultsTableName
import weka.experiment.ResultProducer; //导入依赖的package包/类
/**
* Gets the name of the experiment table that stores results from a particular
* ResultProducer.
*
* @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;
}
开发者ID:marcioadr88,项目名称:weka-datasource-extension,代码行数:36,代码来源:ExtendedDatabaseUtils.java
示例3: getResultFromTable
import weka.experiment.ResultProducer; //导入依赖的package包/类
/**
* Executes a database query to extract a result for the supplied key from the
* database.
*
* @param tableName the name of the table where the result is stored
* @param rp the ResultProducer who will generate the result if required
* @param key the key for the result
* @return true if the result with that key is in the database already
* @throws Exception if an error occurs
*/
public Object[] getResultFromTable(String tableName, ResultProducer rp,
Object[] key) throws Exception {
String query = "SELECT ";
String[] resultNames = rp.getResultNames();
for (int i = 0; i < resultNames.length; i++) {
if (i != 0) {
query += ", ";
}
query += resultNames[i];
}
query += " FROM " + tableName;
String[] keyNames = rp.getKeyNames();
if (keyNames.length != key.length) {
throw new Exception("Key names and key values of different lengths");
}
boolean first = true;
for (int i = 0; i < key.length; i++) {
if (key[i] != null) {
if (first) {
query += " WHERE ";
first = false;
} else {
query += " AND ";
}
query += "Key_" + keyNames[i] + '=';
if (key[i] instanceof String) {
query += "'" + processKeyString(key[i].toString()) + "'";
} else {
query += key[i].toString();
}
}
}
ResultSet rs = select(query);
ResultSetMetaData md = rs.getMetaData();
int numAttributes = md.getColumnCount();
if (!rs.next()) {
throw new Exception("No result for query: " + query);
}
// Extract the columns for the result
Object[] result = new Object[numAttributes];
for (int i = 1; i <= numAttributes; i++) {
switch (translateDBColumnType(md.getColumnTypeName(i))) {
case STRING:
result[i - 1] = rs.getString(i);
if (rs.wasNull()) {
result[i - 1] = null;
}
break;
case FLOAT:
case DOUBLE:
result[i - 1] = new Double(rs.getDouble(i));
if (rs.wasNull()) {
result[i - 1] = null;
}
break;
default:
throw new Exception("Unhandled SQL result type (field " + (i + 1)
+ "): " + ExtendedDatabaseUtils.typeName(md.getColumnType(i)));
}
}
if (rs.next()) {
throw new Exception("More than one result entry " + "for result key: "
+ query);
}
close(rs);
return result;
}
开发者ID:marcioadr88,项目名称:weka-datasource-extension,代码行数:79,代码来源:ExtendedDatabaseUtils.java
示例4: putResultInTable
import weka.experiment.ResultProducer; //导入依赖的package包/类
/**
* Executes a database query to insert a result for the supplied key into the
* database.
*
* @param tableName the name of the table where the result is stored
* @param rp the ResultProducer who will generate the result if required
* @param key the key for the result
* @param result the result to store
* @throws Exception if an error occurs
*/
public void putResultInTable(String tableName, ResultProducer rp,
Object[] key, Object[] result) throws Exception {
String query = "INSERT INTO " + tableName + " VALUES ( ";
// Add the results to the table
for (int i = 0; i < key.length; i++) {
if (i != 0) {
query += ',';
}
if (key[i] != null) {
if (key[i] instanceof String) {
query += "'" + processKeyString(key[i].toString()) + "'";
} else if (key[i] instanceof Double) {
query += safeDoubleToString((Double) key[i]);
} else {
query += key[i].toString();
}
} else {
query += "NULL";
}
}
for (Object element : result) {
query += ',';
if (element != null) {
if (element instanceof String) {
query += "'" + element.toString() + "'";
} else if (element instanceof Double) {
query += safeDoubleToString((Double) element);
} else {
query += element.toString();
// !!
// System.err.println("res: "+ result[i].toString());
}
} else {
query += "NULL";
}
}
query += ')';
if (m_Debug) {
System.err.println("Submitting result: " + query);
}
update(query);
close();
}
开发者ID:marcioadr88,项目名称:weka-datasource-extension,代码行数:56,代码来源:ExtendedDatabaseUtils.java
注:本文中的weka.experiment.ResultProducer类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论