1111import weka .core .Instances ;
1212import weka .core .converters .ArffLoader ;
1313import weka .filters .Filter ;
14+ import weka .filters .unsupervised .attribute .Remove ;
1415
1516import java .io .File ;
1617import java .io .IOException ;
@@ -36,27 +37,39 @@ public void createFeatures() {
3637
3738 //Create and set attributes for the train instances
3839 if (options .getArffInstancesFiles ().isEmpty ()) {
39- ArrayList <Attribute > trainAttributes = createAttributes (getCategories (options .getAllClasses ()), dataset .getTrainMethods (), featureSets );
40+ ArrayList <Attribute > trainAttributes = createAttributes (getCategories (options .getAllClasses ()), dataset .getTrainMethods ());
4041 structure = new Instances ("swan-srm" , trainAttributes , 0 );
41- convertToMekaInstances (structure );
4242
4343 Set <Method > methods = new HashSet <>(dataset .getTrainMethods ());
4444 methods .addAll (dataset .getTestMethods ());
4545
4646 evaluateFeatureData (methods );
47- trainInstances = createInstances (structure , trainAttributes , dataset .getTrainMethods (), getCategories (options .getAllClasses ()));
47+ trainInstances = createInstances (new Instances ( structure ) , trainAttributes , dataset .getTrainMethods (), getCategories (options .getAllClasses ()));
4848 } else {
4949 ArffLoader loader = new ArffLoader ();
5050
5151 try {
5252 loader .setSource (new File (options .getArffInstancesFiles ().get (0 )));
53+
5354 trainInstances = loader .getDataSet ();
5455 structure = loader .getStructure ();
56+
57+ //append remaining instances
58+ if (options .getArffInstancesFiles ().size () > 1 ) {
59+ for (int x = 1 ; x < options .getArffInstancesFiles ().size (); x ++) {
60+
61+ ArffLoader arffLoader = new ArffLoader ();
62+ arffLoader .setSource (new File (options .getArffInstancesFiles ().get (x )));
63+
64+ trainInstances = mergeInstances (trainInstances , arffLoader .getDataSet ());
65+ structure = mergeInstances (structure , arffLoader .getStructure ());
66+ }
67+ }
5568 } catch (IOException e ) {
5669 e .printStackTrace ();
5770 }
5871
59- createAttributes (getCategories (options .getAllClasses ()), dataset .getTestMethods (), featureSets );
72+ createAttributes (getCategories (options .getAllClasses ()), dataset .getTestMethods ());
6073 evaluateFeatureData (dataset .getTestMethods ());
6174 }
6275 testInstances = createTestSet ();
@@ -104,22 +117,22 @@ public Instances mergeInstances(Instances first, Instances second) {
104117
105118 public Instances createTestSet () {
106119
120+ Instances testInstances = new Instances (structure );
107121 //Create and set attributes for the test instances.
108122 Attribute idAttr = new Attribute ("id" , dataset .getTestMethods ().stream ().map (Method ::getArffSafeSignature ).collect (Collectors .toList ()));
109- structure .replaceAttributeAt (idAttr , structure .attribute ("id" ).index ());
110- ArrayList <Attribute > aList = Collections .list (structure .enumerateAttributes ());
123+ testInstances .replaceAttributeAt (idAttr , testInstances .attribute ("id" ).index ());
124+ ArrayList <Attribute > aList = Collections .list (testInstances .enumerateAttributes ());
111125
112- return createInstances (structure , aList , dataset .getTestMethods (), getCategories (options .getAllClasses ()));
126+ return createInstances (testInstances , aList , dataset .getTestMethods (), getCategories (options .getAllClasses ()));
113127 }
114128
115129 /**
116130 * Creates instances and adds attributes for the features, classes, and method signatures.
117131 *
118- * @param categories list of categories
119- * @param methods list of training methods
120- * @param featureSets classification mode
132+ * @param categories list of categories
133+ * @param methods list of training methods
121134 */
122- public ArrayList <Attribute > createAttributes (Set <Category > categories , Set <Method > methods , List < FeatureSet . Type > featureSets ) {
135+ public ArrayList <Attribute > createAttributes (Set <Category > categories , Set <Method > methods ) {
123136
124137 ArrayList <Attribute > attributes = new ArrayList <>();
125138
0 commit comments