我正在使用InstanceQuery SQL查询构造我的Instances。但是我的查询结果并不总是和SQL中的正常一样。 由于不同的SQL构建的这个实例有不同的头文件。一个简单的例子可以在下面看到。我怀疑我的结果因为这种行为而改变。所有数据库查询的相同实例头(arff)
页眉1
@attribute duration numeric
@attribute protocol_type {tcp,udp}
@attribute service {http,domain_u}
@attribute flag {SF}
头2
@attribute duration numeric
@attribute protocol_type {tcp}
@attribute service {pm_dump,pop_2,pop_3}
@attribute flag {SF,S0,SH}
我的问题是:我怎样才能给正确的头信息,以实例建设。
就像下面的工作流程是可能的?
- 从arff文件或其他地方获取预先准备好的标题信息。
- 给例如建设这个头信息
- 调用SQL函数,并得到实例(头+数据)
我使用下面的SQL函数来获取从数据库实例。
public static Instances getInstanceDataFromDatabase(String pSql
,String pInstanceRelationName){
try {
DatabaseUtils utils = new DatabaseUtils();
InstanceQuery query = new InstanceQuery();
query.setUsername(username);
query.setPassword(password);
query.setQuery(pSql);
Instances data = query.retrieveInstances();
data.setRelationName(pInstanceRelationName);
if (data.classIndex() == -1)
{
data.setClassIndex(data.numAttributes() - 1);
}
return data;
} catch (Exception e) {
throw new RuntimeException(e);
}
}