在 Weka Java API 中创建字符串属性 [英] Creating a string attribute in Weka Java API
问题描述
我正在尝试使用 Weka 的 Java API 创建一个新的字符串属性...
I'm trying to create a new string Attribute using Weka's Java API...
通读API javadocs,看来这样做的方法是使用这个构造函数:
Reading through the API javadocs, it appears that the way to do so is to use this constructor:
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 参数的内容...
but I'm stuck as to what I should pass into the attributeValues parameter...
当我输入 null 时,Java 会抱怨受保护的对象
当我输入 Null 时,是语法错误
当我输入 new FastVector()
时,它变成了一个空的名义属性而不是一个字符串属性...
当我创建一个新对象时:
when I put in null, Java complains about protected objects
when I put in Null, it's syntax error
when I put in new FastVector()
, it becomes a nominal attribute that is empty rather than a string attribute...
when I create a new object:
FastVector fv = new FastVector();
fv.addElement(null);
然后将 fv 传递给参数,它返回一个空指针异常...
and then pass fv into the argument, it returns a null pointer exception...
我到底应该在 attributeValues 参数中放入什么,以便它成为字符串属性?
what exactly should I put into the attributeValues argument so that it becomes a string attribute?
推荐答案
您必须将 null 强制转换为 FastVector.否则会有更多的方法应用于方法签名:
You have to cast the null to FastVector. Otherwise more methods would apply to the method signature:
FastVector attributes = new FastVector();
attributes.addElement(new Attribute("attr", (FastVector) null));
这里是动态创建实例的好资源:http://weka.wikispaces.com/Creating+an+ARFF+file
Here is a good resource for creating Instances on the fly: http://weka.wikispaces.com/Creating+an+ARFF+file
这篇关于在 Weka Java API 中创建字符串属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!