开创了WEKA的Java API一个字符串属性 [英] creating a string attribute in weka java API
问题描述
所以我想用WEKA的Java API来创建一个新的字符串属性...
so I'm trying to create a new string Attribute using weka's java API...
通过API的javadoc读书,看来,这样做的方法是使用这个构造:
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...
当我把空,Java的抱怨受保护对象的结果
当我把空,它的语法错误结果
当我把在新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?
推荐答案
您必须空转换为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));
下面是动态创建实例的一个很好的资源:<一href=\"http://weka.wikispaces.com/Creating+an+ARFF+file\">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屋!