我正在尝试使用Weka的Java API创建新的字符串属性...
通读API javadocs,看来这样做的方法是使用以下构造函数:
Attribute
public Attribute(java.lang.String attributeName,
FastVector attributeValues)
Constructor for nominal attributes and string attributes. If a null vector of attribute values is passed to the method, the attribute is assumed to be a string.
Parameters:
attributeName - the name for the attribute
attributeValues - a vector of strings denoting the attribute values. Null if the attribute is a string attribute.
但是我对应该传递给attributeValues参数的方式感到困惑...
当我放入null时,Java会
在放入Null时抱怨受保护的对象,当我放入Null时,这是语法错误,
当new FastVector()
它
创建一个新对象时,它将变为名义上的属性,而不是字符串属性...
FastVector fv = new FastVector();
fv.addElement(null);
然后将fv传递给参数,它将返回空指针异常...
我到底应该在attributeValues参数中放入什么,以使其成为字符串属性?
您必须将null强制转换为FastVector。否则,更多方法将应用于方法签名:
FastVector attributes = new FastVector();
attributes.addElement(new Attribute("attr", (FastVector) null));
这是一个用于动态创建实例的好资源:http : //weka.wikispaces.com/Creating+an+ARFF+file
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句