def init_columns(self): """ Sets the column indices based on the supplied names if necessary. """ if self.columns_determined: return data = self.instances if data is None: print("No instances set, cannot determine columns!") return # dataset if self.dataset_columns is None: raise Exception("No dataset columns set!") cols = "" for name in self.dataset_columns: att = data.attribute_by_name(name) if att is None: raise Exception("Dataset column not found: " + name) if len(cols) > 0: cols += "," cols += str(att.index + 1) javabridge.call(self.jobject, "setDatasetKeyColumns", "(Lweka/core/Range;)V", Range(ranges=cols).jobject) # run if self.run_column is None: raise Exception("No run columnn set!") att = data.attribute_by_name(self.run_column) if att is None: raise Exception("Run column not found: " + self.run_column) javabridge.call(self.jobject, "setRunColumn", "(I)V", att.index) # fold if not self.fold_column is None: att = data.attribute_by_name(self.fold_column) if att is None: index = -1 else: index = att.index javabridge.call(self.jobject, "setFoldColumn", "(I)V", index) # result if self._result_columns is None: raise Exception("No reset columns set!") cols = "" for name in self._result_columns: att = data.attribute_by_name(name) if att is None: raise Exception("Result column not found: " + name) if len(cols) > 0: cols += "," cols += str(att.index + 1) javabridge.call(self.jobject, "setResultsetKeyColumns", "(Lweka/core/Range;)V", Range(ranges=cols).jobject) self.columns_determined = True
def main(): """ Just runs some example code. """ # generic JavaObject stuff helper.print_title("Generic stuff using weka.core.SystemInfo") info = JavaObject(JavaObject.new_instance(classname="weka.core.SystemInfo")) jwrapper = info.jwrapper print("toString() method:") print(jwrapper.toString()) # random helper.print_title("Random") rnd = Random(1) for i in range(10): print(rnd.next_double()) for i in range(10): print(rnd.next_int(100)) # single index helper.print_title("SingleIndex") si = SingleIndex(index="first") upper = 10 si.upper(upper) print(str(si) + " (upper=" + str(upper) + ")\n -> " + str(si.index())) si.single_index = "3" si.upper(upper) print(str(si) + " (upper=" + str(upper) + ")\n -> " + str(si.index())) si.single_index = "last" si.upper(upper) print(str(si) + " (upper=" + str(upper) + ")\n -> " + str(si.index())) # range helper.print_title("Range") rng = Range(ranges="first") upper = 10 invert = False rng.upper(upper) rng.invert = invert print(str(rng.ranges) + " (upper=" + str(upper) + ", invert=" + str(invert) + ")\n -> " + str(rng.selection())) rng.ranges = "3" rng.upper(upper) rng.invert = invert print(str(rng.ranges) + " (upper=" + str(upper) + ", invert=" + str(invert) + ")\n -> " + str(rng.selection())) rng.ranges = "last" rng.upper(upper) rng.invert = invert print(str(rng.ranges) + " (upper=" + str(upper) + ", invert=" + str(invert) + ")\n -> " + str(rng.selection())) rng.ranges = "first-last" rng.upper(upper) rng.invert = invert print(str(rng.ranges) + " (upper=" + str(upper) + ", invert=" + str(invert) + ")\n -> " + str(rng.selection())) rng.ranges = "3,4,7-last" rng.upper(upper) rng.invert = invert print(str(rng.ranges) + " (upper=" + str(upper) + ", invert=" + str(invert) + ")\n -> " + str(rng.selection())) rng.ranges = "3,4,7-last" rng.upper(upper) invert = True rng.invert = invert print(str(rng.ranges) + " (upper=" + str(upper) + ", invert=" + str(invert) + ")\n -> " + str(rng.selection())) # tag helper.print_title("Tag") tag = Tag(ident=1, ident_str="one") print("tag=" + str(tag) + ", ident=" + str(tag.ident) + ", readable=" + tag.readable) tag.ident = 3 print("tag=" + str(tag) + ", ident=" + str(tag.ident) + ", readable=" + tag.readable) tag = Tag(ident=2, ident_str="two", readable="2nd tag") print("tag=" + str(tag) + ", ident=" + str(tag.ident) + ", readable=" + tag.readable)
def main(): """ Just runs some example code. """ # generic JavaObject stuff helper.print_title("Generic stuff using weka.core.SystemInfo") info = JavaObject(JavaObject.new_instance("weka.core.SystemInfo")) jwrapper = info.jwrapper print("toString() method:") print(jwrapper.toString()) # random helper.print_title("Random") rnd = Random(1) for i in xrange(10): print(rnd.next_double()) for i in xrange(10): print(rnd.next_int(100)) # single index helper.print_title("SingleIndex") si = SingleIndex(index="first") upper = 10 si.upper(upper) print(str(si) + " (upper=" + str(upper) + ")\n -> " + str(si.index())) si.single_index = "3" si.upper(upper) print(str(si) + " (upper=" + str(upper) + ")\n -> " + str(si.index())) si.single_index = "last" si.upper(upper) print(str(si) + " (upper=" + str(upper) + ")\n -> " + str(si.index())) # range helper.print_title("Range") rng = Range(ranges="first") upper = 10 invert = False rng.upper(upper) rng.invert = invert print(str(rng.ranges) + " (upper=" + str(upper) + ", invert=" + str(invert) + ")\n -> " + str(rng.selection())) rng.ranges = "3" rng.upper(upper) rng.invert = invert print(str(rng.ranges) + " (upper=" + str(upper) + ", invert=" + str(invert) + ")\n -> " + str(rng.selection())) rng.ranges = "last" rng.upper(upper) rng.invert = invert print(str(rng.ranges) + " (upper=" + str(upper) + ", invert=" + str(invert) + ")\n -> " + str(rng.selection())) rng.ranges = "first-last" rng.upper(upper) rng.invert = invert print(str(rng.ranges) + " (upper=" + str(upper) + ", invert=" + str(invert) + ")\n -> " + str(rng.selection())) rng.ranges = "3,4,7-last" rng.upper(upper) rng.invert = invert print(str(rng.ranges) + " (upper=" + str(upper) + ", invert=" + str(invert) + ")\n -> " + str(rng.selection())) rng.ranges = "3,4,7-last" rng.upper(upper) invert = True rng.invert = invert print(str(rng.ranges) + " (upper=" + str(upper) + ", invert=" + str(invert) + ")\n -> " + str(rng.selection())) # tag helper.print_title("Tag") tag = Tag(ident=1, ident_str="one") print("tag=" + str(tag) + ", ident=" + str(tag.ident) + ", readable=" + tag.readable) tag.ident = 3 print("tag=" + str(tag) + ", ident=" + str(tag.ident) + ", readable=" + tag.readable) tag = Tag(ident=2, ident_str="two", readable="2nd tag") print("tag=" + str(tag) + ", ident=" + str(tag.ident) + ", readable=" + tag.readable)