File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
swan-pipeline/src/main/java/de/fraunhofer/iem/swan/features Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -65,6 +65,43 @@ public void createFeatures() {
6565 this .instances .put ("test" , convertToMekaInstances (testInstances ));
6666 }
6767
68+ /**
69+ * Merge two instances into one instances object.
70+ * @param first instances
71+ * @param second instances
72+ * @return merged instances
73+ */
74+ public Instances mergeInstances (Instances first , Instances second ) {
75+
76+ for (int c = 0 ; c < 12 ; c ++) {
77+ second .renameAttribute (second .attribute (c ), "b_" + second .attribute (c ).name ());
78+ }
79+
80+ Instances instances = Instances .mergeInstances (first , second );
81+
82+ ArrayList <Integer > indices = new ArrayList <>();
83+
84+ for (int att = 0 ; att < instances .numAttributes (); att ++) {
85+ if (instances .attribute (att ).name ().startsWith ("b_" )) {
86+ indices .add (att );
87+ }
88+ }
89+
90+ Remove removeFilter = new Remove ();
91+ removeFilter .setAttributeIndicesArray (indices .stream ().mapToInt (i -> i ).toArray ());
92+ removeFilter .setInvertSelection (false );
93+
94+ try {
95+ removeFilter .setInputFormat (instances );
96+ instances = Filter .useFilter (instances , removeFilter );
97+
98+ } catch (Exception e ) {
99+ e .printStackTrace ();
100+ }
101+
102+ return instances ;
103+ }
104+
68105 public Instances createTestSet () {
69106
70107 //Create and set attributes for the test instances.
You can’t perform that action at this time.
0 commit comments