问题
Having real trouble figuring out where i'm going wrong on this one. Building a system using WEKA in java to study associations and am trying to implement the Apriori algorithm. Currently this is the code:
package model;
import weka.associations.*;
import weka.core.Instances;
import weka.core.converters.ConverterUtils.DataSource;
public class Apriori {
public static void main(String args[]) throws Exception {
String dataset = "/Users/andrew/workspace/Movies/src/data/tagsfinal.arff";
DataSource dsource = new DataSource(dataset);
Instances dapriori = dsource.getDataSet();
Apriori apriori = new Apriori();
apriori.buildAssociations(dapriori);
System.out.println(apriori);
}
}
From looking at several implementations across the web this seems to be a widely accepted method of doing this however i receive an error on the "apriori.buildAssociations" line telling me that the method is undefined for the type Apriori. Furthermore, the import statement i use for the associations only works as the package type and when trying to extend it to :
import weka.associations.Apriori;
this throws an error message that "The import weka.associations.Apriori conflicts with a type defined in the same file". I have scoured StackOverflow alongside other resources and realize there is a lot of type undefined questions out there however have yet to find a solution to this problem. Any help/pointers would be greatly appreciated.
回答1:
Your class is also named Apriori
, so you are experiencing a name clash.
You should change the name of your own class to a different name (e.g. AprioriTest
). In the unprobable case where you would really need your class to be named Apriori
, then you would have to refer to the library's implementation by it's full name:
weka.associations.Apriori apriori = new weka.associations.Apriori();
apriori.buildAssociations(dapriori);
来源:https://stackoverflow.com/questions/35610155/method-undefined-for-type-java