id
int32
0
252k
repo
stringlengths
7
55
path
stringlengths
4
127
func_name
stringlengths
1
88
original_string
stringlengths
75
19.8k
language
stringclasses
1 value
code
stringlengths
51
19.8k
code_tokens
list
docstring
stringlengths
3
17.3k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
87
242
1,600
fracpete/python-weka-wrapper3
python/weka/filters.py
MultiFilter.filters
def filters(self): """ Returns the list of base filters. :return: the filter list :rtype: list """ objects = javabridge.get_env().get_object_array_elements( javabridge.call(self.jobject, "getFilters", "()[Lweka/filters/Filter;")) result = [] for obj in objects: result.append(Filter(jobject=obj)) return result
python
def filters(self): objects = javabridge.get_env().get_object_array_elements( javabridge.call(self.jobject, "getFilters", "()[Lweka/filters/Filter;")) result = [] for obj in objects: result.append(Filter(jobject=obj)) return result
[ "def", "filters", "(", "self", ")", ":", "objects", "=", "javabridge", ".", "get_env", "(", ")", ".", "get_object_array_elements", "(", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"getFilters\"", ",", "\"()[Lweka/filters/Filter;\"", ")", ")", "result", "=", "[", "]", "for", "obj", "in", "objects", ":", "result", ".", "append", "(", "Filter", "(", "jobject", "=", "obj", ")", ")", "return", "result" ]
Returns the list of base filters. :return: the filter list :rtype: list
[ "Returns", "the", "list", "of", "base", "filters", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/filters.py#L201-L213
1,601
fracpete/python-weka-wrapper3
python/weka/filters.py
MultiFilter.filters
def filters(self, filters): """ Sets the base filters. :param filters: the list of base filters to use :type filters: list """ obj = [] for fltr in filters: obj.append(fltr.jobject) javabridge.call(self.jobject, "setFilters", "([Lweka/filters/Filter;)V", obj)
python
def filters(self, filters): obj = [] for fltr in filters: obj.append(fltr.jobject) javabridge.call(self.jobject, "setFilters", "([Lweka/filters/Filter;)V", obj)
[ "def", "filters", "(", "self", ",", "filters", ")", ":", "obj", "=", "[", "]", "for", "fltr", "in", "filters", ":", "obj", ".", "append", "(", "fltr", ".", "jobject", ")", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"setFilters\"", ",", "\"([Lweka/filters/Filter;)V\"", ",", "obj", ")" ]
Sets the base filters. :param filters: the list of base filters to use :type filters: list
[ "Sets", "the", "base", "filters", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/filters.py#L216-L226
1,602
fracpete/python-weka-wrapper3
python/weka/flow/container.py
Container.generate_help
def generate_help(self): """ Generates a help string for this container. :return: the help string :rtype: str """ result = [] result.append(self.__class__.__name__) result.append(re.sub(r'.', '=', self.__class__.__name__)) result.append("") result.append("Supported value names:") for a in self.allowed: result.append(a) return '\n'.join(result)
python
def generate_help(self): result = [] result.append(self.__class__.__name__) result.append(re.sub(r'.', '=', self.__class__.__name__)) result.append("") result.append("Supported value names:") for a in self.allowed: result.append(a) return '\n'.join(result)
[ "def", "generate_help", "(", "self", ")", ":", "result", "=", "[", "]", "result", ".", "append", "(", "self", ".", "__class__", ".", "__name__", ")", "result", ".", "append", "(", "re", ".", "sub", "(", "r'.'", ",", "'='", ",", "self", ".", "__class__", ".", "__name__", ")", ")", "result", ".", "append", "(", "\"\"", ")", "result", ".", "append", "(", "\"Supported value names:\"", ")", "for", "a", "in", "self", ".", "allowed", ":", "result", ".", "append", "(", "a", ")", "return", "'\\n'", ".", "join", "(", "result", ")" ]
Generates a help string for this container. :return: the help string :rtype: str
[ "Generates", "a", "help", "string", "for", "this", "container", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/container.py#L84-L98
1,603
fracpete/python-weka-wrapper3
python/weka/plot/graph.py
plot_dot_graph
def plot_dot_graph(graph, filename=None): """ Plots a graph in graphviz dot notation. :param graph: the dot notation graph :type graph: str :param filename: the (optional) file to save the generated plot to. The extension determines the file format. :type filename: str """ if not plot.pygraphviz_available: logger.error("Pygraphviz is not installed, cannot generate graph plot!") return if not plot.PIL_available: logger.error("PIL is not installed, cannot display graph plot!") return agraph = AGraph(graph) agraph.layout(prog='dot') if filename is None: filename = tempfile.mktemp(suffix=".png") agraph.draw(filename) image = Image.open(filename) image.show()
python
def plot_dot_graph(graph, filename=None): if not plot.pygraphviz_available: logger.error("Pygraphviz is not installed, cannot generate graph plot!") return if not plot.PIL_available: logger.error("PIL is not installed, cannot display graph plot!") return agraph = AGraph(graph) agraph.layout(prog='dot') if filename is None: filename = tempfile.mktemp(suffix=".png") agraph.draw(filename) image = Image.open(filename) image.show()
[ "def", "plot_dot_graph", "(", "graph", ",", "filename", "=", "None", ")", ":", "if", "not", "plot", ".", "pygraphviz_available", ":", "logger", ".", "error", "(", "\"Pygraphviz is not installed, cannot generate graph plot!\"", ")", "return", "if", "not", "plot", ".", "PIL_available", ":", "logger", ".", "error", "(", "\"PIL is not installed, cannot display graph plot!\"", ")", "return", "agraph", "=", "AGraph", "(", "graph", ")", "agraph", ".", "layout", "(", "prog", "=", "'dot'", ")", "if", "filename", "is", "None", ":", "filename", "=", "tempfile", ".", "mktemp", "(", "suffix", "=", "\".png\"", ")", "agraph", ".", "draw", "(", "filename", ")", "image", "=", "Image", ".", "open", "(", "filename", ")", "image", ".", "show", "(", ")" ]
Plots a graph in graphviz dot notation. :param graph: the dot notation graph :type graph: str :param filename: the (optional) file to save the generated plot to. The extension determines the file format. :type filename: str
[ "Plots", "a", "graph", "in", "graphviz", "dot", "notation", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/plot/graph.py#L29-L51
1,604
fracpete/python-weka-wrapper3
python/weka/core/stemmers.py
Stemmer.stem
def stem(self, s): """ Performs stemming on the string. :param s: the string to stem :type s: str :return: the stemmed string :rtype: str """ return javabridge.get_env().get_string(self.__stem(javabridge.get_env().new_string_utf(s)))
python
def stem(self, s): return javabridge.get_env().get_string(self.__stem(javabridge.get_env().new_string_utf(s)))
[ "def", "stem", "(", "self", ",", "s", ")", ":", "return", "javabridge", ".", "get_env", "(", ")", ".", "get_string", "(", "self", ".", "__stem", "(", "javabridge", ".", "get_env", "(", ")", ".", "new_string_utf", "(", "s", ")", ")", ")" ]
Performs stemming on the string. :param s: the string to stem :type s: str :return: the stemmed string :rtype: str
[ "Performs", "stemming", "on", "the", "string", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/core/stemmers.py#L43-L52
1,605
fracpete/python-weka-wrapper3
python/weka/core/dataset.py
Instances.attribute_by_name
def attribute_by_name(self, name): """ Returns the specified attribute, None if not found. :param name: the name of the attribute :type name: str :return: the attribute or None :rtype: Attribute """ att = self.__attribute_by_name(javabridge.get_env().new_string(name)) if att is None: return None else: return Attribute(att)
python
def attribute_by_name(self, name): att = self.__attribute_by_name(javabridge.get_env().new_string(name)) if att is None: return None else: return Attribute(att)
[ "def", "attribute_by_name", "(", "self", ",", "name", ")", ":", "att", "=", "self", ".", "__attribute_by_name", "(", "javabridge", ".", "get_env", "(", ")", ".", "new_string", "(", "name", ")", ")", "if", "att", "is", "None", ":", "return", "None", "else", ":", "return", "Attribute", "(", "att", ")" ]
Returns the specified attribute, None if not found. :param name: the name of the attribute :type name: str :return: the attribute or None :rtype: Attribute
[ "Returns", "the", "specified", "attribute", "None", "if", "not", "found", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/core/dataset.py#L118-L131
1,606
fracpete/python-weka-wrapper3
python/weka/core/dataset.py
Instances.add_instance
def add_instance(self, inst, index=None): """ Adds the specified instance to the dataset. :param inst: the Instance to add :type inst: Instance :param index: the 0-based index where to add the Instance :type index: int """ if index is None: self.__append_instance(inst.jobject) else: self.__insert_instance(index, inst.jobject)
python
def add_instance(self, inst, index=None): if index is None: self.__append_instance(inst.jobject) else: self.__insert_instance(index, inst.jobject)
[ "def", "add_instance", "(", "self", ",", "inst", ",", "index", "=", "None", ")", ":", "if", "index", "is", "None", ":", "self", ".", "__append_instance", "(", "inst", ".", "jobject", ")", "else", ":", "self", ".", "__insert_instance", "(", "index", ",", "inst", ".", "jobject", ")" ]
Adds the specified instance to the dataset. :param inst: the Instance to add :type inst: Instance :param index: the 0-based index where to add the Instance :type index: int
[ "Adds", "the", "specified", "instance", "to", "the", "dataset", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/core/dataset.py#L235-L247
1,607
fracpete/python-weka-wrapper3
python/weka/core/dataset.py
Instances.set_instance
def set_instance(self, index, inst): """ Sets the Instance at the specified location in the dataset. :param index: the 0-based index of the instance to replace :type index: int :param inst: the Instance to set :type inst: Instance :return: the instance :rtype: Instance """ return Instance( self.__set_instance(index, inst.jobject))
python
def set_instance(self, index, inst): return Instance( self.__set_instance(index, inst.jobject))
[ "def", "set_instance", "(", "self", ",", "index", ",", "inst", ")", ":", "return", "Instance", "(", "self", ".", "__set_instance", "(", "index", ",", "inst", ".", "jobject", ")", ")" ]
Sets the Instance at the specified location in the dataset. :param index: the 0-based index of the instance to replace :type index: int :param inst: the Instance to set :type inst: Instance :return: the instance :rtype: Instance
[ "Sets", "the", "Instance", "at", "the", "specified", "location", "in", "the", "dataset", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/core/dataset.py#L249-L261
1,608
fracpete/python-weka-wrapper3
python/weka/core/dataset.py
Instances.delete
def delete(self, index=None): """ Removes either the specified Instance or all Instance objects. :param index: the 0-based index of the instance to remove :type index: int """ if index is None: javabridge.call(self.jobject, "delete", "()V") else: javabridge.call(self.jobject, "delete", "(I)V", index)
python
def delete(self, index=None): if index is None: javabridge.call(self.jobject, "delete", "()V") else: javabridge.call(self.jobject, "delete", "(I)V", index)
[ "def", "delete", "(", "self", ",", "index", "=", "None", ")", ":", "if", "index", "is", "None", ":", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"delete\"", ",", "\"()V\"", ")", "else", ":", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"delete\"", ",", "\"(I)V\"", ",", "index", ")" ]
Removes either the specified Instance or all Instance objects. :param index: the 0-based index of the instance to remove :type index: int
[ "Removes", "either", "the", "specified", "Instance", "or", "all", "Instance", "objects", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/core/dataset.py#L263-L273
1,609
fracpete/python-weka-wrapper3
python/weka/core/dataset.py
Instances.insert_attribute
def insert_attribute(self, att, index): """ Inserts the attribute at the specified location. :param att: the attribute to insert :type att: Attribute :param index: the index to insert the attribute at :type index: int """ javabridge.call(self.jobject, "insertAttributeAt", "(Lweka/core/Attribute;I)V", att.jobject, index)
python
def insert_attribute(self, att, index): javabridge.call(self.jobject, "insertAttributeAt", "(Lweka/core/Attribute;I)V", att.jobject, index)
[ "def", "insert_attribute", "(", "self", ",", "att", ",", "index", ")", ":", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"insertAttributeAt\"", ",", "\"(Lweka/core/Attribute;I)V\"", ",", "att", ".", "jobject", ",", "index", ")" ]
Inserts the attribute at the specified location. :param att: the attribute to insert :type att: Attribute :param index: the index to insert the attribute at :type index: int
[ "Inserts", "the", "attribute", "at", "the", "specified", "location", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/core/dataset.py#L314-L323
1,610
fracpete/python-weka-wrapper3
python/weka/core/dataset.py
Instances.train_cv
def train_cv(self, num_folds, fold, random=None): """ Generates a training fold for cross-validation. :param num_folds: the number of folds of cross-validation, eg 10 :type num_folds: int :param fold: the current fold (0-based) :type fold: int :param random: the random number generator :type random: Random :return: the training fold :rtype: Instances """ if random is None: return Instances( javabridge.call(self.jobject, "trainCV", "(II)Lweka/core/Instances;", num_folds, fold)) else: return Instances( javabridge.call(self.jobject, "trainCV", "(IILjava/util/Random;)Lweka/core/Instances;", num_folds, fold, random.jobject))
python
def train_cv(self, num_folds, fold, random=None): if random is None: return Instances( javabridge.call(self.jobject, "trainCV", "(II)Lweka/core/Instances;", num_folds, fold)) else: return Instances( javabridge.call(self.jobject, "trainCV", "(IILjava/util/Random;)Lweka/core/Instances;", num_folds, fold, random.jobject))
[ "def", "train_cv", "(", "self", ",", "num_folds", ",", "fold", ",", "random", "=", "None", ")", ":", "if", "random", "is", "None", ":", "return", "Instances", "(", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"trainCV\"", ",", "\"(II)Lweka/core/Instances;\"", ",", "num_folds", ",", "fold", ")", ")", "else", ":", "return", "Instances", "(", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"trainCV\"", ",", "\"(IILjava/util/Random;)Lweka/core/Instances;\"", ",", "num_folds", ",", "fold", ",", "random", ".", "jobject", ")", ")" ]
Generates a training fold for cross-validation. :param num_folds: the number of folds of cross-validation, eg 10 :type num_folds: int :param fold: the current fold (0-based) :type fold: int :param random: the random number generator :type random: Random :return: the training fold :rtype: Instances
[ "Generates", "a", "training", "fold", "for", "cross", "-", "validation", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/core/dataset.py#L358-L378
1,611
fracpete/python-weka-wrapper3
python/weka/core/dataset.py
Instances.copy_instances
def copy_instances(cls, dataset, from_row=None, num_rows=None): """ Creates a copy of the Instances. If either from_row or num_rows are None, then all of the data is being copied. :param dataset: the original dataset :type dataset: Instances :param from_row: the 0-based start index of the rows to copy :type from_row: int :param num_rows: the number of rows to copy :type num_rows: int :return: the copy of the data :rtype: Instances """ if from_row is None or num_rows is None: return Instances( javabridge.make_instance( "weka/core/Instances", "(Lweka/core/Instances;)V", dataset.jobject)) else: dataset = cls.copy_instances(dataset) return Instances( javabridge.make_instance( "weka/core/Instances", "(Lweka/core/Instances;II)V", dataset.jobject, from_row, num_rows))
python
def copy_instances(cls, dataset, from_row=None, num_rows=None): if from_row is None or num_rows is None: return Instances( javabridge.make_instance( "weka/core/Instances", "(Lweka/core/Instances;)V", dataset.jobject)) else: dataset = cls.copy_instances(dataset) return Instances( javabridge.make_instance( "weka/core/Instances", "(Lweka/core/Instances;II)V", dataset.jobject, from_row, num_rows))
[ "def", "copy_instances", "(", "cls", ",", "dataset", ",", "from_row", "=", "None", ",", "num_rows", "=", "None", ")", ":", "if", "from_row", "is", "None", "or", "num_rows", "is", "None", ":", "return", "Instances", "(", "javabridge", ".", "make_instance", "(", "\"weka/core/Instances\"", ",", "\"(Lweka/core/Instances;)V\"", ",", "dataset", ".", "jobject", ")", ")", "else", ":", "dataset", "=", "cls", ".", "copy_instances", "(", "dataset", ")", "return", "Instances", "(", "javabridge", ".", "make_instance", "(", "\"weka/core/Instances\"", ",", "\"(Lweka/core/Instances;II)V\"", ",", "dataset", ".", "jobject", ",", "from_row", ",", "num_rows", ")", ")" ]
Creates a copy of the Instances. If either from_row or num_rows are None, then all of the data is being copied. :param dataset: the original dataset :type dataset: Instances :param from_row: the 0-based start index of the rows to copy :type from_row: int :param num_rows: the number of rows to copy :type num_rows: int :return: the copy of the data :rtype: Instances
[ "Creates", "a", "copy", "of", "the", "Instances", ".", "If", "either", "from_row", "or", "num_rows", "are", "None", "then", "all", "of", "the", "data", "is", "being", "copied", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/core/dataset.py#L408-L432
1,612
fracpete/python-weka-wrapper3
python/weka/core/dataset.py
Instances.template_instances
def template_instances(cls, dataset, capacity=0): """ Uses the Instances as template to create an empty dataset. :param dataset: the original dataset :type dataset: Instances :param capacity: how many data rows to reserve initially (see compactify) :type capacity: int :return: the empty dataset :rtype: Instances """ return Instances( javabridge.make_instance( "weka/core/Instances", "(Lweka/core/Instances;I)V", dataset.jobject, capacity))
python
def template_instances(cls, dataset, capacity=0): return Instances( javabridge.make_instance( "weka/core/Instances", "(Lweka/core/Instances;I)V", dataset.jobject, capacity))
[ "def", "template_instances", "(", "cls", ",", "dataset", ",", "capacity", "=", "0", ")", ":", "return", "Instances", "(", "javabridge", ".", "make_instance", "(", "\"weka/core/Instances\"", ",", "\"(Lweka/core/Instances;I)V\"", ",", "dataset", ".", "jobject", ",", "capacity", ")", ")" ]
Uses the Instances as template to create an empty dataset. :param dataset: the original dataset :type dataset: Instances :param capacity: how many data rows to reserve initially (see compactify) :type capacity: int :return: the empty dataset :rtype: Instances
[ "Uses", "the", "Instances", "as", "template", "to", "create", "an", "empty", "dataset", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/core/dataset.py#L435-L448
1,613
fracpete/python-weka-wrapper3
python/weka/core/dataset.py
Instances.create_instances
def create_instances(cls, name, atts, capacity): """ Creates a new Instances. :param name: the relation name :type name: str :param atts: the list of attributes to use for the dataset :type atts: list of Attribute :param capacity: how many data rows to reserve initially (see compactify) :type capacity: int :return: the dataset :rtype: Instances """ attributes = [] for att in atts: attributes.append(att.jobject) return Instances( javabridge.make_instance( "weka/core/Instances", "(Ljava/lang/String;Ljava/util/ArrayList;I)V", name, javabridge.make_list(attributes), capacity))
python
def create_instances(cls, name, atts, capacity): attributes = [] for att in atts: attributes.append(att.jobject) return Instances( javabridge.make_instance( "weka/core/Instances", "(Ljava/lang/String;Ljava/util/ArrayList;I)V", name, javabridge.make_list(attributes), capacity))
[ "def", "create_instances", "(", "cls", ",", "name", ",", "atts", ",", "capacity", ")", ":", "attributes", "=", "[", "]", "for", "att", "in", "atts", ":", "attributes", ".", "append", "(", "att", ".", "jobject", ")", "return", "Instances", "(", "javabridge", ".", "make_instance", "(", "\"weka/core/Instances\"", ",", "\"(Ljava/lang/String;Ljava/util/ArrayList;I)V\"", ",", "name", ",", "javabridge", ".", "make_list", "(", "attributes", ")", ",", "capacity", ")", ")" ]
Creates a new Instances. :param name: the relation name :type name: str :param atts: the list of attributes to use for the dataset :type atts: list of Attribute :param capacity: how many data rows to reserve initially (see compactify) :type capacity: int :return: the dataset :rtype: Instances
[ "Creates", "a", "new", "Instances", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/core/dataset.py#L451-L470
1,614
fracpete/python-weka-wrapper3
python/weka/core/dataset.py
Instance.dataset
def dataset(self): """ Returns the dataset that this instance belongs to. :return: the dataset or None if no dataset set :rtype: Instances """ dataset = javabridge.call(self.jobject, "dataset", "()Lweka/core/Instances;") if dataset is None: return None else: return Instances(dataset)
python
def dataset(self): dataset = javabridge.call(self.jobject, "dataset", "()Lweka/core/Instances;") if dataset is None: return None else: return Instances(dataset)
[ "def", "dataset", "(", "self", ")", ":", "dataset", "=", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"dataset\"", ",", "\"()Lweka/core/Instances;\"", ")", "if", "dataset", "is", "None", ":", "return", "None", "else", ":", "return", "Instances", "(", "dataset", ")" ]
Returns the dataset that this instance belongs to. :return: the dataset or None if no dataset set :rtype: Instances
[ "Returns", "the", "dataset", "that", "this", "instance", "belongs", "to", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/core/dataset.py#L577-L588
1,615
fracpete/python-weka-wrapper3
python/weka/core/dataset.py
Instance.create_sparse_instance
def create_sparse_instance(cls, values, max_values, classname="weka.core.SparseInstance", weight=1.0): """ Creates a new sparse instance. :param values: the list of tuples (0-based index and internal format float). The indices of the tuples must be in ascending order and "max_values" must be set to the maximum number of attributes in the dataset. :type values: list :param max_values: the maximum number of attributes :type max_values: int :param classname: the classname of the instance (eg weka.core.SparseInstance). :type classname: str :param weight: the weight of the instance :type weight: float """ jni_classname = classname.replace(".", "/") indices = [] vals = [] for (i, v) in values: indices.append(i) vals.append(float(v)) indices = numpy.array(indices, dtype=numpy.int32) vals = numpy.array(vals) return Instance( javabridge.make_instance( jni_classname, "(D[D[II)V", weight, javabridge.get_env().make_double_array(vals), javabridge.get_env().make_int_array(indices), max_values))
python
def create_sparse_instance(cls, values, max_values, classname="weka.core.SparseInstance", weight=1.0): jni_classname = classname.replace(".", "/") indices = [] vals = [] for (i, v) in values: indices.append(i) vals.append(float(v)) indices = numpy.array(indices, dtype=numpy.int32) vals = numpy.array(vals) return Instance( javabridge.make_instance( jni_classname, "(D[D[II)V", weight, javabridge.get_env().make_double_array(vals), javabridge.get_env().make_int_array(indices), max_values))
[ "def", "create_sparse_instance", "(", "cls", ",", "values", ",", "max_values", ",", "classname", "=", "\"weka.core.SparseInstance\"", ",", "weight", "=", "1.0", ")", ":", "jni_classname", "=", "classname", ".", "replace", "(", "\".\"", ",", "\"/\"", ")", "indices", "=", "[", "]", "vals", "=", "[", "]", "for", "(", "i", ",", "v", ")", "in", "values", ":", "indices", ".", "append", "(", "i", ")", "vals", ".", "append", "(", "float", "(", "v", ")", ")", "indices", "=", "numpy", ".", "array", "(", "indices", ",", "dtype", "=", "numpy", ".", "int32", ")", "vals", "=", "numpy", ".", "array", "(", "vals", ")", "return", "Instance", "(", "javabridge", ".", "make_instance", "(", "jni_classname", ",", "\"(D[D[II)V\"", ",", "weight", ",", "javabridge", ".", "get_env", "(", ")", ".", "make_double_array", "(", "vals", ")", ",", "javabridge", ".", "get_env", "(", ")", ".", "make_int_array", "(", "indices", ")", ",", "max_values", ")", ")" ]
Creates a new sparse instance. :param values: the list of tuples (0-based index and internal format float). The indices of the tuples must be in ascending order and "max_values" must be set to the maximum number of attributes in the dataset. :type values: list :param max_values: the maximum number of attributes :type max_values: int :param classname: the classname of the instance (eg weka.core.SparseInstance). :type classname: str :param weight: the weight of the instance :type weight: float
[ "Creates", "a", "new", "sparse", "instance", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/core/dataset.py#L786-L813
1,616
fracpete/python-weka-wrapper3
python/weka/core/dataset.py
Attribute.type_str
def type_str(self, short=False): """ Returns the type of the attribute as string. :return: the type :rtype: str """ if short: return javabridge.static_call( "weka/core/Attribute", "typeToStringShort", "(Lweka/core/Attribute;)Ljava/lang/String;", self.jobject) else: return javabridge.static_call( "weka/core/Attribute", "typeToString", "(Lweka/core/Attribute;)Ljava/lang/String;", self.jobject)
python
def type_str(self, short=False): if short: return javabridge.static_call( "weka/core/Attribute", "typeToStringShort", "(Lweka/core/Attribute;)Ljava/lang/String;", self.jobject) else: return javabridge.static_call( "weka/core/Attribute", "typeToString", "(Lweka/core/Attribute;)Ljava/lang/String;", self.jobject)
[ "def", "type_str", "(", "self", ",", "short", "=", "False", ")", ":", "if", "short", ":", "return", "javabridge", ".", "static_call", "(", "\"weka/core/Attribute\"", ",", "\"typeToStringShort\"", ",", "\"(Lweka/core/Attribute;)Ljava/lang/String;\"", ",", "self", ".", "jobject", ")", "else", ":", "return", "javabridge", ".", "static_call", "(", "\"weka/core/Attribute\"", ",", "\"typeToString\"", ",", "\"(Lweka/core/Attribute;)Ljava/lang/String;\"", ",", "self", ".", "jobject", ")" ]
Returns the type of the attribute as string. :return: the type :rtype: str
[ "Returns", "the", "type", "of", "the", "attribute", "as", "string", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/core/dataset.py#L946-L960
1,617
fracpete/python-weka-wrapper3
python/weka/core/dataset.py
Attribute.copy
def copy(self, name=None): """ Creates a copy of this attribute. :param name: the new name, uses the old one if None :type name: str :return: the copy of the attribute :rtype: Attribute """ if name is None: return Attribute( javabridge.call(self.jobject, "copy", "()Ljava/lang/Object;")) else: return Attribute( javabridge.call(self.jobject, "copy", "(Ljava/lang/String;)Lweka/core/Attribute;", name))
python
def copy(self, name=None): if name is None: return Attribute( javabridge.call(self.jobject, "copy", "()Ljava/lang/Object;")) else: return Attribute( javabridge.call(self.jobject, "copy", "(Ljava/lang/String;)Lweka/core/Attribute;", name))
[ "def", "copy", "(", "self", ",", "name", "=", "None", ")", ":", "if", "name", "is", "None", ":", "return", "Attribute", "(", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"copy\"", ",", "\"()Ljava/lang/Object;\"", ")", ")", "else", ":", "return", "Attribute", "(", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"copy\"", ",", "\"(Ljava/lang/String;)Lweka/core/Attribute;\"", ",", "name", ")", ")" ]
Creates a copy of this attribute. :param name: the new name, uses the old one if None :type name: str :return: the copy of the attribute :rtype: Attribute
[ "Creates", "a", "copy", "of", "this", "attribute", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/core/dataset.py#L1119-L1133
1,618
fracpete/python-weka-wrapper3
python/weka/core/dataset.py
Attribute.create_nominal
def create_nominal(cls, name, labels): """ Creates a nominal attribute. :param name: the name of the attribute :type name: str :param labels: the list of string labels to use :type labels: list """ return Attribute( javabridge.make_instance( "weka/core/Attribute", "(Ljava/lang/String;Ljava/util/List;)V", name, javabridge.make_list(labels)))
python
def create_nominal(cls, name, labels): return Attribute( javabridge.make_instance( "weka/core/Attribute", "(Ljava/lang/String;Ljava/util/List;)V", name, javabridge.make_list(labels)))
[ "def", "create_nominal", "(", "cls", ",", "name", ",", "labels", ")", ":", "return", "Attribute", "(", "javabridge", ".", "make_instance", "(", "\"weka/core/Attribute\"", ",", "\"(Ljava/lang/String;Ljava/util/List;)V\"", ",", "name", ",", "javabridge", ".", "make_list", "(", "labels", ")", ")", ")" ]
Creates a nominal attribute. :param name: the name of the attribute :type name: str :param labels: the list of string labels to use :type labels: list
[ "Creates", "a", "nominal", "attribute", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/core/dataset.py#L1162-L1173
1,619
fracpete/python-weka-wrapper3
python/weka/core/dataset.py
Attribute.create_relational
def create_relational(cls, name, inst): """ Creates a relational attribute. :param name: the name of the attribute :type name: str :param inst: the structure of the relational attribute :type inst: Instances """ return Attribute( javabridge.make_instance( "weka/core/Attribute", "(Ljava/lang/String;Lweka/core/Instances;)V", name, inst.jobject))
python
def create_relational(cls, name, inst): return Attribute( javabridge.make_instance( "weka/core/Attribute", "(Ljava/lang/String;Lweka/core/Instances;)V", name, inst.jobject))
[ "def", "create_relational", "(", "cls", ",", "name", ",", "inst", ")", ":", "return", "Attribute", "(", "javabridge", ".", "make_instance", "(", "\"weka/core/Attribute\"", ",", "\"(Ljava/lang/String;Lweka/core/Instances;)V\"", ",", "name", ",", "inst", ".", "jobject", ")", ")" ]
Creates a relational attribute. :param name: the name of the attribute :type name: str :param inst: the structure of the relational attribute :type inst: Instances
[ "Creates", "a", "relational", "attribute", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/core/dataset.py#L1188-L1199
1,620
fracpete/python-weka-wrapper3
python/weka/core/jvm.py
add_bundled_jars
def add_bundled_jars(): """ Adds the bundled jars to the JVM's classpath. """ # determine lib directory with jars rootdir = os.path.split(os.path.dirname(__file__))[0] libdir = rootdir + os.sep + "lib" # add jars from lib directory for l in glob.glob(libdir + os.sep + "*.jar"): if l.lower().find("-src.") == -1: javabridge.JARS.append(str(l))
python
def add_bundled_jars(): # determine lib directory with jars rootdir = os.path.split(os.path.dirname(__file__))[0] libdir = rootdir + os.sep + "lib" # add jars from lib directory for l in glob.glob(libdir + os.sep + "*.jar"): if l.lower().find("-src.") == -1: javabridge.JARS.append(str(l))
[ "def", "add_bundled_jars", "(", ")", ":", "# determine lib directory with jars", "rootdir", "=", "os", ".", "path", ".", "split", "(", "os", ".", "path", ".", "dirname", "(", "__file__", ")", ")", "[", "0", "]", "libdir", "=", "rootdir", "+", "os", ".", "sep", "+", "\"lib\"", "# add jars from lib directory", "for", "l", "in", "glob", ".", "glob", "(", "libdir", "+", "os", ".", "sep", "+", "\"*.jar\"", ")", ":", "if", "l", ".", "lower", "(", ")", ".", "find", "(", "\"-src.\"", ")", "==", "-", "1", ":", "javabridge", ".", "JARS", ".", "append", "(", "str", "(", "l", ")", ")" ]
Adds the bundled jars to the JVM's classpath.
[ "Adds", "the", "bundled", "jars", "to", "the", "JVM", "s", "classpath", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/core/jvm.py#L31-L42
1,621
fracpete/python-weka-wrapper3
python/weka/core/jvm.py
add_system_classpath
def add_system_classpath(): """ Adds the system's classpath to the JVM's classpath. """ if 'CLASSPATH' in os.environ: parts = os.environ['CLASSPATH'].split(os.pathsep) for part in parts: javabridge.JARS.append(part)
python
def add_system_classpath(): if 'CLASSPATH' in os.environ: parts = os.environ['CLASSPATH'].split(os.pathsep) for part in parts: javabridge.JARS.append(part)
[ "def", "add_system_classpath", "(", ")", ":", "if", "'CLASSPATH'", "in", "os", ".", "environ", ":", "parts", "=", "os", ".", "environ", "[", "'CLASSPATH'", "]", ".", "split", "(", "os", ".", "pathsep", ")", "for", "part", "in", "parts", ":", "javabridge", ".", "JARS", ".", "append", "(", "part", ")" ]
Adds the system's classpath to the JVM's classpath.
[ "Adds", "the", "system", "s", "classpath", "to", "the", "JVM", "s", "classpath", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/core/jvm.py#L45-L52
1,622
fracpete/python-weka-wrapper3
python/weka/core/classes.py
get_class
def get_class(classname): """ Returns the class object associated with the dot-notation classname. Taken from here: http://stackoverflow.com/a/452981 :param classname: the classname :type classname: str :return: the class object :rtype: object """ parts = classname.split('.') module = ".".join(parts[:-1]) m = __import__(module) for comp in parts[1:]: m = getattr(m, comp) return m
python
def get_class(classname): parts = classname.split('.') module = ".".join(parts[:-1]) m = __import__(module) for comp in parts[1:]: m = getattr(m, comp) return m
[ "def", "get_class", "(", "classname", ")", ":", "parts", "=", "classname", ".", "split", "(", "'.'", ")", "module", "=", "\".\"", ".", "join", "(", "parts", "[", ":", "-", "1", "]", ")", "m", "=", "__import__", "(", "module", ")", "for", "comp", "in", "parts", "[", "1", ":", "]", ":", "m", "=", "getattr", "(", "m", ",", "comp", ")", "return", "m" ]
Returns the class object associated with the dot-notation classname. Taken from here: http://stackoverflow.com/a/452981 :param classname: the classname :type classname: str :return: the class object :rtype: object
[ "Returns", "the", "class", "object", "associated", "with", "the", "dot", "-", "notation", "classname", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/core/classes.py#L33-L49
1,623
fracpete/python-weka-wrapper3
python/weka/core/classes.py
get_jclass
def get_jclass(classname): """ Returns the Java class object associated with the dot-notation classname. :param classname: the classname :type classname: str :return: the class object :rtype: JB_Object """ try: return javabridge.class_for_name(classname) except: return javabridge.static_call( "Lweka/core/ClassHelper;", "forName", "(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/Class;", javabridge.class_for_name("java.lang.Object"), classname)
python
def get_jclass(classname): try: return javabridge.class_for_name(classname) except: return javabridge.static_call( "Lweka/core/ClassHelper;", "forName", "(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/Class;", javabridge.class_for_name("java.lang.Object"), classname)
[ "def", "get_jclass", "(", "classname", ")", ":", "try", ":", "return", "javabridge", ".", "class_for_name", "(", "classname", ")", "except", ":", "return", "javabridge", ".", "static_call", "(", "\"Lweka/core/ClassHelper;\"", ",", "\"forName\"", ",", "\"(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/Class;\"", ",", "javabridge", ".", "class_for_name", "(", "\"java.lang.Object\"", ")", ",", "classname", ")" ]
Returns the Java class object associated with the dot-notation classname. :param classname: the classname :type classname: str :return: the class object :rtype: JB_Object
[ "Returns", "the", "Java", "class", "object", "associated", "with", "the", "dot", "-", "notation", "classname", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/core/classes.py#L52-L67
1,624
fracpete/python-weka-wrapper3
python/weka/core/classes.py
get_static_field
def get_static_field(classname, fieldname, signature): """ Returns the Java object associated with the static field of the specified class. :param classname: the classname of the class to get the field from :type classname: str :param fieldname: the name of the field to retriev :type fieldname: str :return: the object :rtype: JB_Object """ try: return javabridge.get_static_field(classname, fieldname, signature) except: return javabridge.static_call( "Lweka/core/ClassHelper;", "getStaticField", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/Object;", classname, fieldname)
python
def get_static_field(classname, fieldname, signature): try: return javabridge.get_static_field(classname, fieldname, signature) except: return javabridge.static_call( "Lweka/core/ClassHelper;", "getStaticField", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/Object;", classname, fieldname)
[ "def", "get_static_field", "(", "classname", ",", "fieldname", ",", "signature", ")", ":", "try", ":", "return", "javabridge", ".", "get_static_field", "(", "classname", ",", "fieldname", ",", "signature", ")", "except", ":", "return", "javabridge", ".", "static_call", "(", "\"Lweka/core/ClassHelper;\"", ",", "\"getStaticField\"", ",", "\"(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/Object;\"", ",", "classname", ",", "fieldname", ")" ]
Returns the Java object associated with the static field of the specified class. :param classname: the classname of the class to get the field from :type classname: str :param fieldname: the name of the field to retriev :type fieldname: str :return: the object :rtype: JB_Object
[ "Returns", "the", "Java", "object", "associated", "with", "the", "static", "field", "of", "the", "specified", "class", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/core/classes.py#L70-L87
1,625
fracpete/python-weka-wrapper3
python/weka/core/classes.py
get_classname
def get_classname(obj): """ Returns the classname of the JB_Object, Python class or object. :param obj: the java object or Python class/object to get the classname for :type obj: object :return: the classname :rtype: str """ if isinstance(obj, javabridge.JB_Object): cls = javabridge.call(obj, "getClass", "()Ljava/lang/Class;") return javabridge.call(cls, "getName", "()Ljava/lang/String;") elif inspect.isclass(obj): return obj.__module__ + "." + obj.__name__ else: return get_classname(obj.__class__)
python
def get_classname(obj): if isinstance(obj, javabridge.JB_Object): cls = javabridge.call(obj, "getClass", "()Ljava/lang/Class;") return javabridge.call(cls, "getName", "()Ljava/lang/String;") elif inspect.isclass(obj): return obj.__module__ + "." + obj.__name__ else: return get_classname(obj.__class__)
[ "def", "get_classname", "(", "obj", ")", ":", "if", "isinstance", "(", "obj", ",", "javabridge", ".", "JB_Object", ")", ":", "cls", "=", "javabridge", ".", "call", "(", "obj", ",", "\"getClass\"", ",", "\"()Ljava/lang/Class;\"", ")", "return", "javabridge", ".", "call", "(", "cls", ",", "\"getName\"", ",", "\"()Ljava/lang/String;\"", ")", "elif", "inspect", ".", "isclass", "(", "obj", ")", ":", "return", "obj", ".", "__module__", "+", "\".\"", "+", "obj", ".", "__name__", "else", ":", "return", "get_classname", "(", "obj", ".", "__class__", ")" ]
Returns the classname of the JB_Object, Python class or object. :param obj: the java object or Python class/object to get the classname for :type obj: object :return: the classname :rtype: str
[ "Returns", "the", "classname", "of", "the", "JB_Object", "Python", "class", "or", "object", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/core/classes.py#L90-L105
1,626
fracpete/python-weka-wrapper3
python/weka/core/classes.py
is_instance_of
def is_instance_of(obj, class_or_intf_name): """ Checks whether the Java object implements the specified interface or is a subclass of the superclass. :param obj: the Java object to check :type obj: JB_Object :param class_or_intf_name: the superclass or interface to check, dot notation or with forward slashes :type class_or_intf_name: str :return: true if either implements interface or subclass of superclass :rtype: bool """ class_or_intf_name = class_or_intf_name.replace("/", ".") classname = get_classname(obj) # array? retrieve component type and check that if is_array(obj): jarray = JavaArray(jobject=obj) classname = jarray.component_type() result = javabridge.static_call( "Lweka/core/InheritanceUtils;", "isSubclass", "(Ljava/lang/String;Ljava/lang/String;)Z", class_or_intf_name, classname) if result: return True return javabridge.static_call( "Lweka/core/InheritanceUtils;", "hasInterface", "(Ljava/lang/String;Ljava/lang/String;)Z", class_or_intf_name, classname)
python
def is_instance_of(obj, class_or_intf_name): class_or_intf_name = class_or_intf_name.replace("/", ".") classname = get_classname(obj) # array? retrieve component type and check that if is_array(obj): jarray = JavaArray(jobject=obj) classname = jarray.component_type() result = javabridge.static_call( "Lweka/core/InheritanceUtils;", "isSubclass", "(Ljava/lang/String;Ljava/lang/String;)Z", class_or_intf_name, classname) if result: return True return javabridge.static_call( "Lweka/core/InheritanceUtils;", "hasInterface", "(Ljava/lang/String;Ljava/lang/String;)Z", class_or_intf_name, classname)
[ "def", "is_instance_of", "(", "obj", ",", "class_or_intf_name", ")", ":", "class_or_intf_name", "=", "class_or_intf_name", ".", "replace", "(", "\"/\"", ",", "\".\"", ")", "classname", "=", "get_classname", "(", "obj", ")", "# array? retrieve component type and check that", "if", "is_array", "(", "obj", ")", ":", "jarray", "=", "JavaArray", "(", "jobject", "=", "obj", ")", "classname", "=", "jarray", ".", "component_type", "(", ")", "result", "=", "javabridge", ".", "static_call", "(", "\"Lweka/core/InheritanceUtils;\"", ",", "\"isSubclass\"", ",", "\"(Ljava/lang/String;Ljava/lang/String;)Z\"", ",", "class_or_intf_name", ",", "classname", ")", "if", "result", ":", "return", "True", "return", "javabridge", ".", "static_call", "(", "\"Lweka/core/InheritanceUtils;\"", ",", "\"hasInterface\"", ",", "\"(Ljava/lang/String;Ljava/lang/String;)Z\"", ",", "class_or_intf_name", ",", "classname", ")" ]
Checks whether the Java object implements the specified interface or is a subclass of the superclass. :param obj: the Java object to check :type obj: JB_Object :param class_or_intf_name: the superclass or interface to check, dot notation or with forward slashes :type class_or_intf_name: str :return: true if either implements interface or subclass of superclass :rtype: bool
[ "Checks", "whether", "the", "Java", "object", "implements", "the", "specified", "interface", "or", "is", "a", "subclass", "of", "the", "superclass", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/core/classes.py#L108-L134
1,627
fracpete/python-weka-wrapper3
python/weka/core/classes.py
from_commandline
def from_commandline(cmdline, classname=None): """ Creates an OptionHandler based on the provided commandline string. :param cmdline: the commandline string to use :type cmdline: str :param classname: the classname of the wrapper to return other than OptionHandler (in dot-notation) :type classname: str :return: the generated option handler instance :rtype: object """ params = split_options(cmdline) cls = params[0] params = params[1:] handler = OptionHandler(javabridge.static_call( "Lweka/core/Utils;", "forName", "(Ljava/lang/Class;Ljava/lang/String;[Ljava/lang/String;)Ljava/lang/Object;", javabridge.class_for_name("java.lang.Object"), cls, params)) if classname is None: return handler else: c = get_class(classname) return c(jobject=handler.jobject)
python
def from_commandline(cmdline, classname=None): params = split_options(cmdline) cls = params[0] params = params[1:] handler = OptionHandler(javabridge.static_call( "Lweka/core/Utils;", "forName", "(Ljava/lang/Class;Ljava/lang/String;[Ljava/lang/String;)Ljava/lang/Object;", javabridge.class_for_name("java.lang.Object"), cls, params)) if classname is None: return handler else: c = get_class(classname) return c(jobject=handler.jobject)
[ "def", "from_commandline", "(", "cmdline", ",", "classname", "=", "None", ")", ":", "params", "=", "split_options", "(", "cmdline", ")", "cls", "=", "params", "[", "0", "]", "params", "=", "params", "[", "1", ":", "]", "handler", "=", "OptionHandler", "(", "javabridge", ".", "static_call", "(", "\"Lweka/core/Utils;\"", ",", "\"forName\"", ",", "\"(Ljava/lang/Class;Ljava/lang/String;[Ljava/lang/String;)Ljava/lang/Object;\"", ",", "javabridge", ".", "class_for_name", "(", "\"java.lang.Object\"", ")", ",", "cls", ",", "params", ")", ")", "if", "classname", "is", "None", ":", "return", "handler", "else", ":", "c", "=", "get_class", "(", "classname", ")", "return", "c", "(", "jobject", "=", "handler", ".", "jobject", ")" ]
Creates an OptionHandler based on the provided commandline string. :param cmdline: the commandline string to use :type cmdline: str :param classname: the classname of the wrapper to return other than OptionHandler (in dot-notation) :type classname: str :return: the generated option handler instance :rtype: object
[ "Creates", "an", "OptionHandler", "based", "on", "the", "provided", "commandline", "string", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/core/classes.py#L1683-L1705
1,628
fracpete/python-weka-wrapper3
python/weka/core/classes.py
complete_classname
def complete_classname(classname): """ Attempts to complete a partial classname like '.J48' and returns the full classname if a single match was found, otherwise an exception is raised. :param classname: the partial classname to expand :type classname: str :return: the full classname :rtype: str """ result = javabridge.get_collection_wrapper( javabridge.static_call( "Lweka/Run;", "findSchemeMatch", "(Ljava/lang/String;Z)Ljava/util/List;", classname, True)) if len(result) == 1: return str(result[0]) elif len(result) == 0: raise Exception("No classname matches found for: " + classname) else: matches = [] for i in range(len(result)): matches.append(str(result[i])) raise Exception("Found multiple matches for '" + classname + "':\n" + '\n'.join(matches))
python
def complete_classname(classname): result = javabridge.get_collection_wrapper( javabridge.static_call( "Lweka/Run;", "findSchemeMatch", "(Ljava/lang/String;Z)Ljava/util/List;", classname, True)) if len(result) == 1: return str(result[0]) elif len(result) == 0: raise Exception("No classname matches found for: " + classname) else: matches = [] for i in range(len(result)): matches.append(str(result[i])) raise Exception("Found multiple matches for '" + classname + "':\n" + '\n'.join(matches))
[ "def", "complete_classname", "(", "classname", ")", ":", "result", "=", "javabridge", ".", "get_collection_wrapper", "(", "javabridge", ".", "static_call", "(", "\"Lweka/Run;\"", ",", "\"findSchemeMatch\"", ",", "\"(Ljava/lang/String;Z)Ljava/util/List;\"", ",", "classname", ",", "True", ")", ")", "if", "len", "(", "result", ")", "==", "1", ":", "return", "str", "(", "result", "[", "0", "]", ")", "elif", "len", "(", "result", ")", "==", "0", ":", "raise", "Exception", "(", "\"No classname matches found for: \"", "+", "classname", ")", "else", ":", "matches", "=", "[", "]", "for", "i", "in", "range", "(", "len", "(", "result", ")", ")", ":", "matches", ".", "append", "(", "str", "(", "result", "[", "i", "]", ")", ")", "raise", "Exception", "(", "\"Found multiple matches for '\"", "+", "classname", "+", "\"':\\n\"", "+", "'\\n'", ".", "join", "(", "matches", ")", ")" ]
Attempts to complete a partial classname like '.J48' and returns the full classname if a single match was found, otherwise an exception is raised. :param classname: the partial classname to expand :type classname: str :return: the full classname :rtype: str
[ "Attempts", "to", "complete", "a", "partial", "classname", "like", ".", "J48", "and", "returns", "the", "full", "classname", "if", "a", "single", "match", "was", "found", "otherwise", "an", "exception", "is", "raised", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/core/classes.py#L1708-L1732
1,629
fracpete/python-weka-wrapper3
python/weka/core/classes.py
JSONObject.to_json
def to_json(self): """ Returns the options as JSON. :return: the object as string :rtype: str """ return json.dumps(self.to_dict(), sort_keys=True, indent=2, separators=(',', ': '))
python
def to_json(self): return json.dumps(self.to_dict(), sort_keys=True, indent=2, separators=(',', ': '))
[ "def", "to_json", "(", "self", ")", ":", "return", "json", ".", "dumps", "(", "self", ".", "to_dict", "(", ")", ",", "sort_keys", "=", "True", ",", "indent", "=", "2", ",", "separators", "=", "(", "','", ",", "': '", ")", ")" ]
Returns the options as JSON. :return: the object as string :rtype: str
[ "Returns", "the", "options", "as", "JSON", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/core/classes.py#L250-L257
1,630
fracpete/python-weka-wrapper3
python/weka/core/classes.py
JSONObject.from_json
def from_json(cls, s): """ Restores the object from the given JSON. :param s: the JSON string to parse :type s: str :return: the """ d = json.loads(s) return get_dict_handler(d["type"])(d)
python
def from_json(cls, s): d = json.loads(s) return get_dict_handler(d["type"])(d)
[ "def", "from_json", "(", "cls", ",", "s", ")", ":", "d", "=", "json", ".", "loads", "(", "s", ")", "return", "get_dict_handler", "(", "d", "[", "\"type\"", "]", ")", "(", "d", ")" ]
Restores the object from the given JSON. :param s: the JSON string to parse :type s: str :return: the
[ "Restores", "the", "object", "from", "the", "given", "JSON", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/core/classes.py#L260-L269
1,631
fracpete/python-weka-wrapper3
python/weka/core/classes.py
Configurable.from_dict
def from_dict(cls, d): """ Restores its state from a dictionary, used in de-JSONification. :param d: the object dictionary :type d: dict """ conf = {} for k in d["config"]: v = d["config"][k] if isinstance(v, dict): conf[str(k)] = get_dict_handler(d["config"]["type"])(v) else: conf[str(k)] = v return get_class(str(d["class"]))(config=conf)
python
def from_dict(cls, d): conf = {} for k in d["config"]: v = d["config"][k] if isinstance(v, dict): conf[str(k)] = get_dict_handler(d["config"]["type"])(v) else: conf[str(k)] = v return get_class(str(d["class"]))(config=conf)
[ "def", "from_dict", "(", "cls", ",", "d", ")", ":", "conf", "=", "{", "}", "for", "k", "in", "d", "[", "\"config\"", "]", ":", "v", "=", "d", "[", "\"config\"", "]", "[", "k", "]", "if", "isinstance", "(", "v", ",", "dict", ")", ":", "conf", "[", "str", "(", "k", ")", "]", "=", "get_dict_handler", "(", "d", "[", "\"config\"", "]", "[", "\"type\"", "]", ")", "(", "v", ")", "else", ":", "conf", "[", "str", "(", "k", ")", "]", "=", "v", "return", "get_class", "(", "str", "(", "d", "[", "\"class\"", "]", ")", ")", "(", "config", "=", "conf", ")" ]
Restores its state from a dictionary, used in de-JSONification. :param d: the object dictionary :type d: dict
[ "Restores", "its", "state", "from", "a", "dictionary", "used", "in", "de", "-", "JSONification", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/core/classes.py#L372-L386
1,632
fracpete/python-weka-wrapper3
python/weka/core/classes.py
Configurable.logger
def logger(self): """ Returns the logger object. :return: the logger :rtype: logger """ if self._logger is None: self._logger = self.new_logger() return self._logger
python
def logger(self): if self._logger is None: self._logger = self.new_logger() return self._logger
[ "def", "logger", "(", "self", ")", ":", "if", "self", ".", "_logger", "is", "None", ":", "self", ".", "_logger", "=", "self", ".", "new_logger", "(", ")", "return", "self", ".", "_logger" ]
Returns the logger object. :return: the logger :rtype: logger
[ "Returns", "the", "logger", "object", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/core/classes.py#L398-L407
1,633
fracpete/python-weka-wrapper3
python/weka/core/classes.py
Configurable.generate_help
def generate_help(self): """ Generates a help string for this actor. :return: the help string :rtype: str """ result = [] result.append(self.__class__.__name__) result.append(re.sub(r'.', '=', self.__class__.__name__)) result.append("") result.append("DESCRIPTION") result.append(self.description()) result.append("") result.append("OPTIONS") opts = sorted(self.config.keys()) for opt in opts: result.append(opt) helpstr = self.help[opt] if helpstr is None: helpstr = "-missing help-" result.append("\t" + helpstr) result.append("") return '\n'.join(result)
python
def generate_help(self): result = [] result.append(self.__class__.__name__) result.append(re.sub(r'.', '=', self.__class__.__name__)) result.append("") result.append("DESCRIPTION") result.append(self.description()) result.append("") result.append("OPTIONS") opts = sorted(self.config.keys()) for opt in opts: result.append(opt) helpstr = self.help[opt] if helpstr is None: helpstr = "-missing help-" result.append("\t" + helpstr) result.append("") return '\n'.join(result)
[ "def", "generate_help", "(", "self", ")", ":", "result", "=", "[", "]", "result", ".", "append", "(", "self", ".", "__class__", ".", "__name__", ")", "result", ".", "append", "(", "re", ".", "sub", "(", "r'.'", ",", "'='", ",", "self", ".", "__class__", ".", "__name__", ")", ")", "result", ".", "append", "(", "\"\"", ")", "result", ".", "append", "(", "\"DESCRIPTION\"", ")", "result", ".", "append", "(", "self", ".", "description", "(", ")", ")", "result", ".", "append", "(", "\"\"", ")", "result", ".", "append", "(", "\"OPTIONS\"", ")", "opts", "=", "sorted", "(", "self", ".", "config", ".", "keys", "(", ")", ")", "for", "opt", "in", "opts", ":", "result", ".", "append", "(", "opt", ")", "helpstr", "=", "self", ".", "help", "[", "opt", "]", "if", "helpstr", "is", "None", ":", "helpstr", "=", "\"-missing help-\"", "result", ".", "append", "(", "\"\\t\"", "+", "helpstr", ")", "result", ".", "append", "(", "\"\"", ")", "return", "'\\n'", ".", "join", "(", "result", ")" ]
Generates a help string for this actor. :return: the help string :rtype: str
[ "Generates", "a", "help", "string", "for", "this", "actor", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/core/classes.py#L419-L442
1,634
fracpete/python-weka-wrapper3
python/weka/core/classes.py
JavaObject.classname
def classname(self): """ Returns the Java classname in dot-notation. :return: the Java classname :rtype: str """ cls = javabridge.call(self.jobject, "getClass", "()Ljava/lang/Class;") return javabridge.call(cls, "getName", "()Ljava/lang/String;")
python
def classname(self): cls = javabridge.call(self.jobject, "getClass", "()Ljava/lang/Class;") return javabridge.call(cls, "getName", "()Ljava/lang/String;")
[ "def", "classname", "(", "self", ")", ":", "cls", "=", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"getClass\"", ",", "\"()Ljava/lang/Class;\"", ")", "return", "javabridge", ".", "call", "(", "cls", ",", "\"getName\"", ",", "\"()Ljava/lang/String;\"", ")" ]
Returns the Java classname in dot-notation. :return: the Java classname :rtype: str
[ "Returns", "the", "Java", "classname", "in", "dot", "-", "notation", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/core/classes.py#L494-L502
1,635
fracpete/python-weka-wrapper3
python/weka/core/classes.py
JavaObject.enforce_type
def enforce_type(cls, jobject, intf_or_class): """ Raises an exception if the object does not implement the specified interface or is not a subclass. :param jobject: the Java object to check :type jobject: JB_Object :param intf_or_class: the classname in Java notation (eg "weka.core.DenseInstance") :type intf_or_class: str """ if not cls.check_type(jobject, intf_or_class): raise TypeError("Object does not implement or subclass " + intf_or_class + ": " + get_classname(jobject))
python
def enforce_type(cls, jobject, intf_or_class): if not cls.check_type(jobject, intf_or_class): raise TypeError("Object does not implement or subclass " + intf_or_class + ": " + get_classname(jobject))
[ "def", "enforce_type", "(", "cls", ",", "jobject", ",", "intf_or_class", ")", ":", "if", "not", "cls", ".", "check_type", "(", "jobject", ",", "intf_or_class", ")", ":", "raise", "TypeError", "(", "\"Object does not implement or subclass \"", "+", "intf_or_class", "+", "\": \"", "+", "get_classname", "(", "jobject", ")", ")" ]
Raises an exception if the object does not implement the specified interface or is not a subclass. :param jobject: the Java object to check :type jobject: JB_Object :param intf_or_class: the classname in Java notation (eg "weka.core.DenseInstance") :type intf_or_class: str
[ "Raises", "an", "exception", "if", "the", "object", "does", "not", "implement", "the", "specified", "interface", "or", "is", "not", "a", "subclass", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/core/classes.py#L621-L631
1,636
fracpete/python-weka-wrapper3
python/weka/core/classes.py
JavaObject.new_instance
def new_instance(cls, classname): """ Creates a new object from the given classname using the default constructor, None in case of error. :param classname: the classname in Java notation (eg "weka.core.DenseInstance") :type classname: str :return: the Java object :rtype: JB_Object """ try: return javabridge.static_call( "Lweka/core/Utils;", "forName", "(Ljava/lang/Class;Ljava/lang/String;[Ljava/lang/String;)Ljava/lang/Object;", javabridge.class_for_name("java.lang.Object"), classname, []) except JavaException as e: print("Failed to instantiate " + classname + ": " + str(e)) return None
python
def new_instance(cls, classname): try: return javabridge.static_call( "Lweka/core/Utils;", "forName", "(Ljava/lang/Class;Ljava/lang/String;[Ljava/lang/String;)Ljava/lang/Object;", javabridge.class_for_name("java.lang.Object"), classname, []) except JavaException as e: print("Failed to instantiate " + classname + ": " + str(e)) return None
[ "def", "new_instance", "(", "cls", ",", "classname", ")", ":", "try", ":", "return", "javabridge", ".", "static_call", "(", "\"Lweka/core/Utils;\"", ",", "\"forName\"", ",", "\"(Ljava/lang/Class;Ljava/lang/String;[Ljava/lang/String;)Ljava/lang/Object;\"", ",", "javabridge", ".", "class_for_name", "(", "\"java.lang.Object\"", ")", ",", "classname", ",", "[", "]", ")", "except", "JavaException", "as", "e", ":", "print", "(", "\"Failed to instantiate \"", "+", "classname", "+", "\": \"", "+", "str", "(", "e", ")", ")", "return", "None" ]
Creates a new object from the given classname using the default constructor, None in case of error. :param classname: the classname in Java notation (eg "weka.core.DenseInstance") :type classname: str :return: the Java object :rtype: JB_Object
[ "Creates", "a", "new", "object", "from", "the", "given", "classname", "using", "the", "default", "constructor", "None", "in", "case", "of", "error", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/core/classes.py#L634-L650
1,637
fracpete/python-weka-wrapper3
python/weka/core/classes.py
Environment.add_variable
def add_variable(self, key, value, system_wide=False): """ Adds the environment variable. :param key: the name of the variable :type key: str :param value: the value :type value: str :param system_wide: whether to add the variable system wide :type system_wide: bool """ if system_wide: javabridge.call(self.jobject, "addVariableSystemWide", "(Ljava/lang/String;Ljava/lang/String;)V", key, value) else: javabridge.call(self.jobject, "addVariable", "(Ljava/lang/String;Ljava/lang/String;)V", key, value)
python
def add_variable(self, key, value, system_wide=False): if system_wide: javabridge.call(self.jobject, "addVariableSystemWide", "(Ljava/lang/String;Ljava/lang/String;)V", key, value) else: javabridge.call(self.jobject, "addVariable", "(Ljava/lang/String;Ljava/lang/String;)V", key, value)
[ "def", "add_variable", "(", "self", ",", "key", ",", "value", ",", "system_wide", "=", "False", ")", ":", "if", "system_wide", ":", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"addVariableSystemWide\"", ",", "\"(Ljava/lang/String;Ljava/lang/String;)V\"", ",", "key", ",", "value", ")", "else", ":", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"addVariable\"", ",", "\"(Ljava/lang/String;Ljava/lang/String;)V\"", ",", "key", ",", "value", ")" ]
Adds the environment variable. :param key: the name of the variable :type key: str :param value: the value :type value: str :param system_wide: whether to add the variable system wide :type system_wide: bool
[ "Adds", "the", "environment", "variable", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/core/classes.py#L671-L685
1,638
fracpete/python-weka-wrapper3
python/weka/core/classes.py
Environment.variable_names
def variable_names(self): """ Returns the names of all environment variables. :return: the names of the variables :rtype: list """ result = [] names = javabridge.call(self.jobject, "getVariableNames", "()Ljava/util/Set;") for name in javabridge.iterate_collection(names): result.append(javabridge.to_string(name)) return result
python
def variable_names(self): result = [] names = javabridge.call(self.jobject, "getVariableNames", "()Ljava/util/Set;") for name in javabridge.iterate_collection(names): result.append(javabridge.to_string(name)) return result
[ "def", "variable_names", "(", "self", ")", ":", "result", "=", "[", "]", "names", "=", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"getVariableNames\"", ",", "\"()Ljava/util/Set;\"", ")", "for", "name", "in", "javabridge", ".", "iterate_collection", "(", "names", ")", ":", "result", ".", "append", "(", "javabridge", ".", "to_string", "(", "name", ")", ")", "return", "result" ]
Returns the names of all environment variables. :return: the names of the variables :rtype: list
[ "Returns", "the", "names", "of", "all", "environment", "variables", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/core/classes.py#L707-L718
1,639
fracpete/python-weka-wrapper3
python/weka/core/classes.py
JavaArray.component_type
def component_type(self): """ Returns the classname of the elements. :return: the class of the elements :rtype: str """ cls = javabridge.call(self.jobject, "getClass", "()Ljava/lang/Class;") comptype = javabridge.call(cls, "getComponentType", "()Ljava/lang/Class;") return javabridge.call(comptype, "getName", "()Ljava/lang/String;")
python
def component_type(self): cls = javabridge.call(self.jobject, "getClass", "()Ljava/lang/Class;") comptype = javabridge.call(cls, "getComponentType", "()Ljava/lang/Class;") return javabridge.call(comptype, "getName", "()Ljava/lang/String;")
[ "def", "component_type", "(", "self", ")", ":", "cls", "=", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"getClass\"", ",", "\"()Ljava/lang/Class;\"", ")", "comptype", "=", "javabridge", ".", "call", "(", "cls", ",", "\"getComponentType\"", ",", "\"()Ljava/lang/Class;\"", ")", "return", "javabridge", ".", "call", "(", "comptype", ",", "\"getName\"", ",", "\"()Ljava/lang/String;\"", ")" ]
Returns the classname of the elements. :return: the class of the elements :rtype: str
[ "Returns", "the", "classname", "of", "the", "elements", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/core/classes.py#L843-L852
1,640
fracpete/python-weka-wrapper3
python/weka/core/classes.py
JavaArray.new_instance
def new_instance(cls, classname, length): """ Creates a new array with the given classname and length; initial values are null. :param classname: the classname in Java notation (eg "weka.core.DenseInstance") :type classname: str :param length: the length of the array :type length: int :return: the Java array :rtype: JB_Object """ return javabridge.static_call( "Ljava/lang/reflect/Array;", "newInstance", "(Ljava/lang/Class;I)Ljava/lang/Object;", get_jclass(classname=classname), length)
python
def new_instance(cls, classname, length): return javabridge.static_call( "Ljava/lang/reflect/Array;", "newInstance", "(Ljava/lang/Class;I)Ljava/lang/Object;", get_jclass(classname=classname), length)
[ "def", "new_instance", "(", "cls", ",", "classname", ",", "length", ")", ":", "return", "javabridge", ".", "static_call", "(", "\"Ljava/lang/reflect/Array;\"", ",", "\"newInstance\"", ",", "\"(Ljava/lang/Class;I)Ljava/lang/Object;\"", ",", "get_jclass", "(", "classname", "=", "classname", ")", ",", "length", ")" ]
Creates a new array with the given classname and length; initial values are null. :param classname: the classname in Java notation (eg "weka.core.DenseInstance") :type classname: str :param length: the length of the array :type length: int :return: the Java array :rtype: JB_Object
[ "Creates", "a", "new", "array", "with", "the", "given", "classname", "and", "length", ";", "initial", "values", "are", "null", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/core/classes.py#L855-L870
1,641
fracpete/python-weka-wrapper3
python/weka/core/classes.py
Enum.values
def values(self): """ Returns list of all enum members. :return: all enum members :rtype: list """ cls = javabridge.call(self.jobject, "getClass", "()Ljava/lang/Class;") clsname = javabridge.call(cls, "getName", "()Ljava/lang/String;") l = javabridge.static_call(clsname.replace(".", "/"), "values", "()[L" + clsname.replace(".", "/") + ";") l = javabridge.get_env().get_object_array_elements(l) result = [] for item in l: result.append(Enum(jobject=item)) return result
python
def values(self): cls = javabridge.call(self.jobject, "getClass", "()Ljava/lang/Class;") clsname = javabridge.call(cls, "getName", "()Ljava/lang/String;") l = javabridge.static_call(clsname.replace(".", "/"), "values", "()[L" + clsname.replace(".", "/") + ";") l = javabridge.get_env().get_object_array_elements(l) result = [] for item in l: result.append(Enum(jobject=item)) return result
[ "def", "values", "(", "self", ")", ":", "cls", "=", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"getClass\"", ",", "\"()Ljava/lang/Class;\"", ")", "clsname", "=", "javabridge", ".", "call", "(", "cls", ",", "\"getName\"", ",", "\"()Ljava/lang/String;\"", ")", "l", "=", "javabridge", ".", "static_call", "(", "clsname", ".", "replace", "(", "\".\"", ",", "\"/\"", ")", ",", "\"values\"", ",", "\"()[L\"", "+", "clsname", ".", "replace", "(", "\".\"", ",", "\"/\"", ")", "+", "\";\"", ")", "l", "=", "javabridge", ".", "get_env", "(", ")", ".", "get_object_array_elements", "(", "l", ")", "result", "=", "[", "]", "for", "item", "in", "l", ":", "result", ".", "append", "(", "Enum", "(", "jobject", "=", "item", ")", ")", "return", "result" ]
Returns list of all enum members. :return: all enum members :rtype: list
[ "Returns", "list", "of", "all", "enum", "members", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/core/classes.py#L918-L932
1,642
fracpete/python-weka-wrapper3
python/weka/core/classes.py
Random.next_int
def next_int(self, n=None): """ Next random integer. if n is provided, then between 0 and n-1. :param n: the upper limit (minus 1) for the random integer :type n: int :return: the next random integer :rtype: int """ if n is None: return javabridge.call(self.jobject, "nextInt", "()I") else: return javabridge.call(self.jobject, "nextInt", "(I)I", n)
python
def next_int(self, n=None): if n is None: return javabridge.call(self.jobject, "nextInt", "()I") else: return javabridge.call(self.jobject, "nextInt", "(I)I", n)
[ "def", "next_int", "(", "self", ",", "n", "=", "None", ")", ":", "if", "n", "is", "None", ":", "return", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"nextInt\"", ",", "\"()I\"", ")", "else", ":", "return", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"nextInt\"", ",", "\"(I)I\"", ",", "n", ")" ]
Next random integer. if n is provided, then between 0 and n-1. :param n: the upper limit (minus 1) for the random integer :type n: int :return: the next random integer :rtype: int
[ "Next", "random", "integer", ".", "if", "n", "is", "provided", "then", "between", "0", "and", "n", "-", "1", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/core/classes.py#L949-L961
1,643
fracpete/python-weka-wrapper3
python/weka/core/classes.py
OptionHandler.to_help
def to_help(self): """ Returns a string that contains the 'global_info' text and the options. :return: the generated help string :rtype: str """ result = [] result.append(self.classname) result.append("=" * len(self.classname)) result.append("") result.append("DESCRIPTION") result.append("") result.append(self.global_info()) result.append("") result.append("OPTIONS") result.append("") options = javabridge.call(self.jobject, "listOptions", "()Ljava/util/Enumeration;") enum = javabridge.get_enumeration_wrapper(options) while enum.hasMoreElements(): opt = Option(enum.nextElement()) result.append(opt.synopsis) result.append(opt.description) result.append("") return '\n'.join(result)
python
def to_help(self): result = [] result.append(self.classname) result.append("=" * len(self.classname)) result.append("") result.append("DESCRIPTION") result.append("") result.append(self.global_info()) result.append("") result.append("OPTIONS") result.append("") options = javabridge.call(self.jobject, "listOptions", "()Ljava/util/Enumeration;") enum = javabridge.get_enumeration_wrapper(options) while enum.hasMoreElements(): opt = Option(enum.nextElement()) result.append(opt.synopsis) result.append(opt.description) result.append("") return '\n'.join(result)
[ "def", "to_help", "(", "self", ")", ":", "result", "=", "[", "]", "result", ".", "append", "(", "self", ".", "classname", ")", "result", ".", "append", "(", "\"=\"", "*", "len", "(", "self", ".", "classname", ")", ")", "result", ".", "append", "(", "\"\"", ")", "result", ".", "append", "(", "\"DESCRIPTION\"", ")", "result", ".", "append", "(", "\"\"", ")", "result", ".", "append", "(", "self", ".", "global_info", "(", ")", ")", "result", ".", "append", "(", "\"\"", ")", "result", ".", "append", "(", "\"OPTIONS\"", ")", "result", ".", "append", "(", "\"\"", ")", "options", "=", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"listOptions\"", ",", "\"()Ljava/util/Enumeration;\"", ")", "enum", "=", "javabridge", ".", "get_enumeration_wrapper", "(", "options", ")", "while", "enum", ".", "hasMoreElements", "(", ")", ":", "opt", "=", "Option", "(", "enum", ".", "nextElement", "(", ")", ")", "result", ".", "append", "(", "opt", ".", "synopsis", ")", "result", ".", "append", "(", "opt", ".", "description", ")", "result", ".", "append", "(", "\"\"", ")", "return", "'\\n'", ".", "join", "(", "result", ")" ]
Returns a string that contains the 'global_info' text and the options. :return: the generated help string :rtype: str
[ "Returns", "a", "string", "that", "contains", "the", "global_info", "text", "and", "the", "options", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/core/classes.py#L1112-L1136
1,644
fracpete/python-weka-wrapper3
python/weka/core/classes.py
Tags.find
def find(self, name): """ Returns the Tag that matches the name. :param name: the string representation of the tag :type name: str :return: the tag, None if not found :rtype: Tag """ result = None for t in self.array: if str(t) == name: result = Tag(t.jobject) break return result
python
def find(self, name): result = None for t in self.array: if str(t) == name: result = Tag(t.jobject) break return result
[ "def", "find", "(", "self", ",", "name", ")", ":", "result", "=", "None", "for", "t", "in", "self", ".", "array", ":", "if", "str", "(", "t", ")", "==", "name", ":", "result", "=", "Tag", "(", "t", ".", "jobject", ")", "break", "return", "result" ]
Returns the Tag that matches the name. :param name: the string representation of the tag :type name: str :return: the tag, None if not found :rtype: Tag
[ "Returns", "the", "Tag", "that", "matches", "the", "name", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/core/classes.py#L1471-L1485
1,645
fracpete/python-weka-wrapper3
python/weka/core/classes.py
Tags.get_object_tags
def get_object_tags(cls, javaobject, methodname): """ Instantiates the Tag array obtained from the object using the specified method name. Example: cls = Classifier(classname="weka.classifiers.meta.MultiSearch") tags = Tags.get_object_tags(cls, "getMetricsTags") :param javaobject: the javaobject to obtain the tags from :type javaobject: JavaObject :param methodname: the method name returning the Tag array :type methodname: str :return: the Tags objects :rtype: Tags """ return Tags(jobject=javabridge.call(javaobject.jobject, methodname, "()[Lweka/core/Tag;"))
python
def get_object_tags(cls, javaobject, methodname): return Tags(jobject=javabridge.call(javaobject.jobject, methodname, "()[Lweka/core/Tag;"))
[ "def", "get_object_tags", "(", "cls", ",", "javaobject", ",", "methodname", ")", ":", "return", "Tags", "(", "jobject", "=", "javabridge", ".", "call", "(", "javaobject", ".", "jobject", ",", "methodname", ",", "\"()[Lweka/core/Tag;\"", ")", ")" ]
Instantiates the Tag array obtained from the object using the specified method name. Example: cls = Classifier(classname="weka.classifiers.meta.MultiSearch") tags = Tags.get_object_tags(cls, "getMetricsTags") :param javaobject: the javaobject to obtain the tags from :type javaobject: JavaObject :param methodname: the method name returning the Tag array :type methodname: str :return: the Tags objects :rtype: Tags
[ "Instantiates", "the", "Tag", "array", "obtained", "from", "the", "object", "using", "the", "specified", "method", "name", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/core/classes.py#L1505-L1520
1,646
fracpete/python-weka-wrapper3
python/weka/core/classes.py
SelectedTag.tags
def tags(self): """ Returns the associated tags. :return: the list of Tag objects :rtype: list """ result = [] a = javabridge.call(self.jobject, "getTags", "()Lweka/core/Tag;]") length = javabridge.get_env().get_array_length(a) wrapped = javabridge.get_env().get_object_array_elements(a) for i in range(length): result.append(Tag(javabridge.get_env().get_string(wrapped[i]))) return result
python
def tags(self): result = [] a = javabridge.call(self.jobject, "getTags", "()Lweka/core/Tag;]") length = javabridge.get_env().get_array_length(a) wrapped = javabridge.get_env().get_object_array_elements(a) for i in range(length): result.append(Tag(javabridge.get_env().get_string(wrapped[i]))) return result
[ "def", "tags", "(", "self", ")", ":", "result", "=", "[", "]", "a", "=", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"getTags\"", ",", "\"()Lweka/core/Tag;]\"", ")", "length", "=", "javabridge", ".", "get_env", "(", ")", ".", "get_array_length", "(", "a", ")", "wrapped", "=", "javabridge", ".", "get_env", "(", ")", ".", "get_object_array_elements", "(", "a", ")", "for", "i", "in", "range", "(", "length", ")", ":", "result", ".", "append", "(", "Tag", "(", "javabridge", ".", "get_env", "(", ")", ".", "get_string", "(", "wrapped", "[", "i", "]", ")", ")", ")", "return", "result" ]
Returns the associated tags. :return: the list of Tag objects :rtype: list
[ "Returns", "the", "associated", "tags", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/core/classes.py#L1569-L1582
1,647
fracpete/python-weka-wrapper3
python/weka/core/classes.py
SetupGenerator.base_object
def base_object(self): """ Returns the base object to apply the setups to. :return: the base object :rtype: JavaObject or OptionHandler """ jobj = javabridge.call(self.jobject, "getBaseObject", "()Ljava/io/Serializable;") if OptionHandler.check_type(jobj, "weka.core.OptionHandler"): return OptionHandler(jobj) else: return JavaObject(jobj)
python
def base_object(self): jobj = javabridge.call(self.jobject, "getBaseObject", "()Ljava/io/Serializable;") if OptionHandler.check_type(jobj, "weka.core.OptionHandler"): return OptionHandler(jobj) else: return JavaObject(jobj)
[ "def", "base_object", "(", "self", ")", ":", "jobj", "=", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"getBaseObject\"", ",", "\"()Ljava/io/Serializable;\"", ")", "if", "OptionHandler", ".", "check_type", "(", "jobj", ",", "\"weka.core.OptionHandler\"", ")", ":", "return", "OptionHandler", "(", "jobj", ")", "else", ":", "return", "JavaObject", "(", "jobj", ")" ]
Returns the base object to apply the setups to. :return: the base object :rtype: JavaObject or OptionHandler
[ "Returns", "the", "base", "object", "to", "apply", "the", "setups", "to", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/core/classes.py#L1961-L1972
1,648
fracpete/python-weka-wrapper3
python/weka/core/classes.py
SetupGenerator.base_object
def base_object(self, obj): """ Sets the base object to apply the setups to. :param obj: the object to use (must be serializable!) :type obj: JavaObject """ if not obj.is_serializable: raise Exception("Base object must be serializable: " + obj.classname) javabridge.call(self.jobject, "setBaseObject", "(Ljava/io/Serializable;)V", obj.jobject)
python
def base_object(self, obj): if not obj.is_serializable: raise Exception("Base object must be serializable: " + obj.classname) javabridge.call(self.jobject, "setBaseObject", "(Ljava/io/Serializable;)V", obj.jobject)
[ "def", "base_object", "(", "self", ",", "obj", ")", ":", "if", "not", "obj", ".", "is_serializable", ":", "raise", "Exception", "(", "\"Base object must be serializable: \"", "+", "obj", ".", "classname", ")", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"setBaseObject\"", ",", "\"(Ljava/io/Serializable;)V\"", ",", "obj", ".", "jobject", ")" ]
Sets the base object to apply the setups to. :param obj: the object to use (must be serializable!) :type obj: JavaObject
[ "Sets", "the", "base", "object", "to", "apply", "the", "setups", "to", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/core/classes.py#L1975-L1984
1,649
fracpete/python-weka-wrapper3
python/weka/core/classes.py
SetupGenerator.parameters
def parameters(self): """ Returns the list of currently set search parameters. :return: the list of AbstractSearchParameter objects :rtype: list """ array = JavaArray(javabridge.call(self.jobject, "getParameters", "()[Lweka/core/setupgenerator/AbstractParameter;")) result = [] for item in array: result.append(AbstractParameter(jobject=item.jobject)) return result
python
def parameters(self): array = JavaArray(javabridge.call(self.jobject, "getParameters", "()[Lweka/core/setupgenerator/AbstractParameter;")) result = [] for item in array: result.append(AbstractParameter(jobject=item.jobject)) return result
[ "def", "parameters", "(", "self", ")", ":", "array", "=", "JavaArray", "(", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"getParameters\"", ",", "\"()[Lweka/core/setupgenerator/AbstractParameter;\"", ")", ")", "result", "=", "[", "]", "for", "item", "in", "array", ":", "result", ".", "append", "(", "AbstractParameter", "(", "jobject", "=", "item", ".", "jobject", ")", ")", "return", "result" ]
Returns the list of currently set search parameters. :return: the list of AbstractSearchParameter objects :rtype: list
[ "Returns", "the", "list", "of", "currently", "set", "search", "parameters", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/core/classes.py#L1987-L1998
1,650
fracpete/python-weka-wrapper3
python/weka/core/classes.py
SetupGenerator.parameters
def parameters(self, params): """ Sets the list of search parameters to use. :param params: list of AbstractSearchParameter objects :type params: list """ array = JavaArray(jobject=JavaArray.new_instance("weka.core.setupgenerator.AbstractParameter", len(params))) for idx, obj in enumerate(params): array[idx] = obj.jobject javabridge.call(self.jobject, "setParameters", "([Lweka/core/setupgenerator/AbstractParameter;)V", array.jobject)
python
def parameters(self, params): array = JavaArray(jobject=JavaArray.new_instance("weka.core.setupgenerator.AbstractParameter", len(params))) for idx, obj in enumerate(params): array[idx] = obj.jobject javabridge.call(self.jobject, "setParameters", "([Lweka/core/setupgenerator/AbstractParameter;)V", array.jobject)
[ "def", "parameters", "(", "self", ",", "params", ")", ":", "array", "=", "JavaArray", "(", "jobject", "=", "JavaArray", ".", "new_instance", "(", "\"weka.core.setupgenerator.AbstractParameter\"", ",", "len", "(", "params", ")", ")", ")", "for", "idx", ",", "obj", "in", "enumerate", "(", "params", ")", ":", "array", "[", "idx", "]", "=", "obj", ".", "jobject", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"setParameters\"", ",", "\"([Lweka/core/setupgenerator/AbstractParameter;)V\"", ",", "array", ".", "jobject", ")" ]
Sets the list of search parameters to use. :param params: list of AbstractSearchParameter objects :type params: list
[ "Sets", "the", "list", "of", "search", "parameters", "to", "use", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/core/classes.py#L2001-L2011
1,651
fracpete/python-weka-wrapper3
python/weka/core/classes.py
SetupGenerator.setups
def setups(self): """ Generates and returns all the setups according to the parameter search space. :return: the list of configured objects (of type JavaObject) :rtype: list """ result = [] has_options = self.base_object.is_optionhandler enm = javabridge.get_enumeration_wrapper(javabridge.call(self.jobject, "setups", "()Ljava/util/Enumeration;")) while enm.hasMoreElements(): if has_options: result.append(OptionHandler(enm.nextElement())) else: result.append(JavaObject(enm.nextElement())) return result
python
def setups(self): result = [] has_options = self.base_object.is_optionhandler enm = javabridge.get_enumeration_wrapper(javabridge.call(self.jobject, "setups", "()Ljava/util/Enumeration;")) while enm.hasMoreElements(): if has_options: result.append(OptionHandler(enm.nextElement())) else: result.append(JavaObject(enm.nextElement())) return result
[ "def", "setups", "(", "self", ")", ":", "result", "=", "[", "]", "has_options", "=", "self", ".", "base_object", ".", "is_optionhandler", "enm", "=", "javabridge", ".", "get_enumeration_wrapper", "(", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"setups\"", ",", "\"()Ljava/util/Enumeration;\"", ")", ")", "while", "enm", ".", "hasMoreElements", "(", ")", ":", "if", "has_options", ":", "result", ".", "append", "(", "OptionHandler", "(", "enm", ".", "nextElement", "(", ")", ")", ")", "else", ":", "result", ".", "append", "(", "JavaObject", "(", "enm", ".", "nextElement", "(", ")", ")", ")", "return", "result" ]
Generates and returns all the setups according to the parameter search space. :return: the list of configured objects (of type JavaObject) :rtype: list
[ "Generates", "and", "returns", "all", "the", "setups", "according", "to", "the", "parameter", "search", "space", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/core/classes.py#L2013-L2028
1,652
fracpete/python-weka-wrapper3
python/weka/flow/base.py
Actor.unique_name
def unique_name(self, name): """ Generates a unique name. :param name: the name to check :type name: str :return: the unique name :rtype: str """ result = name if self.parent is not None: index = self.index bname = re.sub(r'-[0-9]+$', '', name) names = [] for idx, actor in enumerate(self.parent.actors): if idx != index: names.append(actor.name) result = bname count = 0 while result in names: count += 1 result = bname + "-" + str(count) return result
python
def unique_name(self, name): result = name if self.parent is not None: index = self.index bname = re.sub(r'-[0-9]+$', '', name) names = [] for idx, actor in enumerate(self.parent.actors): if idx != index: names.append(actor.name) result = bname count = 0 while result in names: count += 1 result = bname + "-" + str(count) return result
[ "def", "unique_name", "(", "self", ",", "name", ")", ":", "result", "=", "name", "if", "self", ".", "parent", "is", "not", "None", ":", "index", "=", "self", ".", "index", "bname", "=", "re", ".", "sub", "(", "r'-[0-9]+$'", ",", "''", ",", "name", ")", "names", "=", "[", "]", "for", "idx", ",", "actor", "in", "enumerate", "(", "self", ".", "parent", ".", "actors", ")", ":", "if", "idx", "!=", "index", ":", "names", ".", "append", "(", "actor", ".", "name", ")", "result", "=", "bname", "count", "=", "0", "while", "result", "in", "names", ":", "count", "+=", "1", "result", "=", "bname", "+", "\"-\"", "+", "str", "(", "count", ")", "return", "result" ]
Generates a unique name. :param name: the name to check :type name: str :return: the unique name :rtype: str
[ "Generates", "a", "unique", "name", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/base.py#L99-L123
1,653
fracpete/python-weka-wrapper3
python/weka/flow/base.py
Actor.parent
def parent(self, parent): """ Sets the parent of the actor. :param parent: the parent :type parent: Actor """ self._name = self.unique_name(self._name) self._full_name = None self._logger = None self._parent = parent
python
def parent(self, parent): self._name = self.unique_name(self._name) self._full_name = None self._logger = None self._parent = parent
[ "def", "parent", "(", "self", ",", "parent", ")", ":", "self", ".", "_name", "=", "self", ".", "unique_name", "(", "self", ".", "_name", ")", "self", ".", "_full_name", "=", "None", "self", ".", "_logger", "=", "None", "self", ".", "_parent", "=", "parent" ]
Sets the parent of the actor. :param parent: the parent :type parent: Actor
[ "Sets", "the", "parent", "of", "the", "actor", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/base.py#L136-L146
1,654
fracpete/python-weka-wrapper3
python/weka/flow/base.py
Actor.full_name
def full_name(self): """ Obtains the full name of the actor. :return: the full name :rtype: str """ if self._full_name is None: fn = self.name.replace(".", "\\.") parent = self._parent if parent is not None: fn = parent.full_name + "." + fn self._full_name = fn return self._full_name
python
def full_name(self): if self._full_name is None: fn = self.name.replace(".", "\\.") parent = self._parent if parent is not None: fn = parent.full_name + "." + fn self._full_name = fn return self._full_name
[ "def", "full_name", "(", "self", ")", ":", "if", "self", ".", "_full_name", "is", "None", ":", "fn", "=", "self", ".", "name", ".", "replace", "(", "\".\"", ",", "\"\\\\.\"", ")", "parent", "=", "self", ".", "_parent", "if", "parent", "is", "not", "None", ":", "fn", "=", "parent", ".", "full_name", "+", "\".\"", "+", "fn", "self", ".", "_full_name", "=", "fn", "return", "self", ".", "_full_name" ]
Obtains the full name of the actor. :return: the full name :rtype: str
[ "Obtains", "the", "full", "name", "of", "the", "actor", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/base.py#L162-L176
1,655
fracpete/python-weka-wrapper3
python/weka/flow/base.py
Actor.storagehandler
def storagehandler(self): """ Returns the storage handler available to thise actor. :return: the storage handler, None if not available """ if isinstance(self, StorageHandler): return self elif self.parent is not None: return self.parent.storagehandler else: return None
python
def storagehandler(self): if isinstance(self, StorageHandler): return self elif self.parent is not None: return self.parent.storagehandler else: return None
[ "def", "storagehandler", "(", "self", ")", ":", "if", "isinstance", "(", "self", ",", "StorageHandler", ")", ":", "return", "self", "elif", "self", ".", "parent", "is", "not", "None", ":", "return", "self", ".", "parent", ".", "storagehandler", "else", ":", "return", "None" ]
Returns the storage handler available to thise actor. :return: the storage handler, None if not available
[ "Returns", "the", "storage", "handler", "available", "to", "thise", "actor", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/base.py#L294-L305
1,656
fracpete/python-weka-wrapper3
python/weka/flow/base.py
Actor.execute
def execute(self): """ Executes the actor. :return: None if successful, otherwise error message :rtype: str """ if self.skip: return None result = self.pre_execute() if result is None: try: result = self.do_execute() except Exception as e: result = traceback.format_exc() print(self.full_name + "\n" + result) if result is None: result = self.post_execute() return result
python
def execute(self): if self.skip: return None result = self.pre_execute() if result is None: try: result = self.do_execute() except Exception as e: result = traceback.format_exc() print(self.full_name + "\n" + result) if result is None: result = self.post_execute() return result
[ "def", "execute", "(", "self", ")", ":", "if", "self", ".", "skip", ":", "return", "None", "result", "=", "self", ".", "pre_execute", "(", ")", "if", "result", "is", "None", ":", "try", ":", "result", "=", "self", ".", "do_execute", "(", ")", "except", "Exception", "as", "e", ":", "result", "=", "traceback", ".", "format_exc", "(", ")", "print", "(", "self", ".", "full_name", "+", "\"\\n\"", "+", "result", ")", "if", "result", "is", "None", ":", "result", "=", "self", ".", "post_execute", "(", ")", "return", "result" ]
Executes the actor. :return: None if successful, otherwise error message :rtype: str
[ "Executes", "the", "actor", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/base.py#L384-L403
1,657
fracpete/python-weka-wrapper3
python/weka/flow/control.py
ActorHandler.actors
def actors(self, actors): """ Sets the sub-actors of the actor. :param actors: the sub-actors :type actors: list """ if actors is None: actors = self.default_actors() self.check_actors(actors) self.config["actors"] = actors
python
def actors(self, actors): if actors is None: actors = self.default_actors() self.check_actors(actors) self.config["actors"] = actors
[ "def", "actors", "(", "self", ",", "actors", ")", ":", "if", "actors", "is", "None", ":", "actors", "=", "self", ".", "default_actors", "(", ")", "self", ".", "check_actors", "(", "actors", ")", "self", ".", "config", "[", "\"actors\"", "]", "=", "actors" ]
Sets the sub-actors of the actor. :param actors: the sub-actors :type actors: list
[ "Sets", "the", "sub", "-", "actors", "of", "the", "actor", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/control.py#L139-L149
1,658
fracpete/python-weka-wrapper3
python/weka/flow/control.py
ActorHandler.active
def active(self): """ Returns the count of non-skipped actors. :return: the count :rtype: int """ result = 0 for actor in self.actors: if not actor.skip: result += 1 return result
python
def active(self): result = 0 for actor in self.actors: if not actor.skip: result += 1 return result
[ "def", "active", "(", "self", ")", ":", "result", "=", "0", "for", "actor", "in", "self", ".", "actors", ":", "if", "not", "actor", ".", "skip", ":", "result", "+=", "1", "return", "result" ]
Returns the count of non-skipped actors. :return: the count :rtype: int
[ "Returns", "the", "count", "of", "non", "-", "skipped", "actors", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/control.py#L152-L163
1,659
fracpete/python-weka-wrapper3
python/weka/flow/control.py
ActorHandler.first_active
def first_active(self): """ Returns the first non-skipped actor. :return: the first active actor, None if not available :rtype: Actor """ result = None for actor in self.actors: if not actor.skip: result = actor break return result
python
def first_active(self): result = None for actor in self.actors: if not actor.skip: result = actor break return result
[ "def", "first_active", "(", "self", ")", ":", "result", "=", "None", "for", "actor", "in", "self", ".", "actors", ":", "if", "not", "actor", ".", "skip", ":", "result", "=", "actor", "break", "return", "result" ]
Returns the first non-skipped actor. :return: the first active actor, None if not available :rtype: Actor
[ "Returns", "the", "first", "non", "-", "skipped", "actor", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/control.py#L166-L178
1,660
fracpete/python-weka-wrapper3
python/weka/flow/control.py
ActorHandler.last_active
def last_active(self): """ Returns the last non-skipped actor. :return: the last active actor, None if not available :rtype: Actor """ result = None for actor in reversed(self.actors): if not actor.skip: result = actor break return result
python
def last_active(self): result = None for actor in reversed(self.actors): if not actor.skip: result = actor break return result
[ "def", "last_active", "(", "self", ")", ":", "result", "=", "None", "for", "actor", "in", "reversed", "(", "self", ".", "actors", ")", ":", "if", "not", "actor", ".", "skip", ":", "result", "=", "actor", "break", "return", "result" ]
Returns the last non-skipped actor. :return: the last active actor, None if not available :rtype: Actor
[ "Returns", "the", "last", "non", "-", "skipped", "actor", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/control.py#L181-L193
1,661
fracpete/python-weka-wrapper3
python/weka/flow/control.py
ActorHandler.index_of
def index_of(self, name): """ Returns the index of the actor with the given name. :param name: the name of the Actor to find :type name: str :return: the index, -1 if not found :rtype: int """ result = -1 for index, actor in enumerate(self.actors): if actor.name == name: result = index break return result
python
def index_of(self, name): result = -1 for index, actor in enumerate(self.actors): if actor.name == name: result = index break return result
[ "def", "index_of", "(", "self", ",", "name", ")", ":", "result", "=", "-", "1", "for", "index", ",", "actor", "in", "enumerate", "(", "self", ".", "actors", ")", ":", "if", "actor", ".", "name", "==", "name", ":", "result", "=", "index", "break", "return", "result" ]
Returns the index of the actor with the given name. :param name: the name of the Actor to find :type name: str :return: the index, -1 if not found :rtype: int
[ "Returns", "the", "index", "of", "the", "actor", "with", "the", "given", "name", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/control.py#L195-L209
1,662
fracpete/python-weka-wrapper3
python/weka/flow/control.py
ActorHandler.setup
def setup(self): """ Configures the actor before execution. :return: None if successful, otherwise error message :rtype: str """ result = super(ActorHandler, self).setup() if result is None: self.update_parent() try: self.check_actors(self.actors) except Exception as e: result = str(e) if result is None: for actor in self.actors: name = actor.name newname = actor.unique_name(actor.name) if name != newname: actor.name = newname if result is None: for actor in self.actors: if actor.skip: continue result = actor.setup() if result is not None: break if result is None: result = self._director.setup() return result
python
def setup(self): result = super(ActorHandler, self).setup() if result is None: self.update_parent() try: self.check_actors(self.actors) except Exception as e: result = str(e) if result is None: for actor in self.actors: name = actor.name newname = actor.unique_name(actor.name) if name != newname: actor.name = newname if result is None: for actor in self.actors: if actor.skip: continue result = actor.setup() if result is not None: break if result is None: result = self._director.setup() return result
[ "def", "setup", "(", "self", ")", ":", "result", "=", "super", "(", "ActorHandler", ",", "self", ")", ".", "setup", "(", ")", "if", "result", "is", "None", ":", "self", ".", "update_parent", "(", ")", "try", ":", "self", ".", "check_actors", "(", "self", ".", "actors", ")", "except", "Exception", "as", "e", ":", "result", "=", "str", "(", "e", ")", "if", "result", "is", "None", ":", "for", "actor", "in", "self", ".", "actors", ":", "name", "=", "actor", ".", "name", "newname", "=", "actor", ".", "unique_name", "(", "actor", ".", "name", ")", "if", "name", "!=", "newname", ":", "actor", ".", "name", "=", "newname", "if", "result", "is", "None", ":", "for", "actor", "in", "self", ".", "actors", ":", "if", "actor", ".", "skip", ":", "continue", "result", "=", "actor", ".", "setup", "(", ")", "if", "result", "is", "not", "None", ":", "break", "if", "result", "is", "None", ":", "result", "=", "self", ".", "_director", ".", "setup", "(", ")", "return", "result" ]
Configures the actor before execution. :return: None if successful, otherwise error message :rtype: str
[ "Configures", "the", "actor", "before", "execution", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/control.py#L218-L247
1,663
fracpete/python-weka-wrapper3
python/weka/flow/control.py
ActorHandler.cleanup
def cleanup(self): """ Destructive finishing up after execution stopped. """ for actor in self.actors: if actor.skip: continue actor.cleanup() super(ActorHandler, self).cleanup()
python
def cleanup(self): for actor in self.actors: if actor.skip: continue actor.cleanup() super(ActorHandler, self).cleanup()
[ "def", "cleanup", "(", "self", ")", ":", "for", "actor", "in", "self", ".", "actors", ":", "if", "actor", ".", "skip", ":", "continue", "actor", ".", "cleanup", "(", ")", "super", "(", "ActorHandler", ",", "self", ")", ".", "cleanup", "(", ")" ]
Destructive finishing up after execution stopped.
[ "Destructive", "finishing", "up", "after", "execution", "stopped", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/control.py#L274-L282
1,664
fracpete/python-weka-wrapper3
python/weka/flow/control.py
Flow.load
def load(cls, fname): """ Loads the flow from a JSON file. :param fname: the file to load :type fname: str :return: the flow :rtype: Flow """ with open(fname) as f: content = f.readlines() return Flow.from_json(''.join(content))
python
def load(cls, fname): with open(fname) as f: content = f.readlines() return Flow.from_json(''.join(content))
[ "def", "load", "(", "cls", ",", "fname", ")", ":", "with", "open", "(", "fname", ")", "as", "f", ":", "content", "=", "f", ".", "readlines", "(", ")", "return", "Flow", ".", "from_json", "(", "''", ".", "join", "(", "content", ")", ")" ]
Loads the flow from a JSON file. :param fname: the file to load :type fname: str :return: the flow :rtype: Flow
[ "Loads", "the", "flow", "from", "a", "JSON", "file", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/control.py#L695-L706
1,665
fracpete/python-weka-wrapper3
python/weka/flow/control.py
Sequence.new_director
def new_director(self): """ Creates the director to use for handling the sub-actors. :return: the director instance :rtype: Director """ result = SequentialDirector(self) result.record_output = False result.allow_source = False return result
python
def new_director(self): result = SequentialDirector(self) result.record_output = False result.allow_source = False return result
[ "def", "new_director", "(", "self", ")", ":", "result", "=", "SequentialDirector", "(", "self", ")", "result", ".", "record_output", "=", "False", "result", ".", "allow_source", "=", "False", "return", "result" ]
Creates the director to use for handling the sub-actors. :return: the director instance :rtype: Director
[ "Creates", "the", "director", "to", "use", "for", "handling", "the", "sub", "-", "actors", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/control.py#L756-L766
1,666
fracpete/python-weka-wrapper3
python/weka/flow/conversion.py
CommandlineToAny.check_input
def check_input(self, obj): """ Performs checks on the input object. Raises an exception if unsupported. :param obj: the object to check :type obj: object """ if isinstance(obj, str): return if isinstance(obj, unicode): return raise Exception("Unsupported class: " + self._input.__class__.__name__)
python
def check_input(self, obj): if isinstance(obj, str): return if isinstance(obj, unicode): return raise Exception("Unsupported class: " + self._input.__class__.__name__)
[ "def", "check_input", "(", "self", ",", "obj", ")", ":", "if", "isinstance", "(", "obj", ",", "str", ")", ":", "return", "if", "isinstance", "(", "obj", ",", "unicode", ")", ":", "return", "raise", "Exception", "(", "\"Unsupported class: \"", "+", "self", ".", "_input", ".", "__class__", ".", "__name__", ")" ]
Performs checks on the input object. Raises an exception if unsupported. :param obj: the object to check :type obj: object
[ "Performs", "checks", "on", "the", "input", "object", ".", "Raises", "an", "exception", "if", "unsupported", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/conversion.py#L207-L218
1,667
fracpete/python-weka-wrapper3
python/weka/flow/conversion.py
CommandlineToAny.convert
def convert(self): """ Performs the actual conversion. :return: None if successful, otherwise errors message :rtype: str """ cname = str(self.config["wrapper"]) self._output = classes.from_commandline(self._input, classname=cname) return None
python
def convert(self): cname = str(self.config["wrapper"]) self._output = classes.from_commandline(self._input, classname=cname) return None
[ "def", "convert", "(", "self", ")", ":", "cname", "=", "str", "(", "self", ".", "config", "[", "\"wrapper\"", "]", ")", "self", ".", "_output", "=", "classes", ".", "from_commandline", "(", "self", ".", "_input", ",", "classname", "=", "cname", ")", "return", "None" ]
Performs the actual conversion. :return: None if successful, otherwise errors message :rtype: str
[ "Performs", "the", "actual", "conversion", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/conversion.py#L220-L229
1,668
fracpete/python-weka-wrapper3
python/weka/plot/experiments.py
plot_experiment
def plot_experiment(mat, title="Experiment", axes_swapped=False, measure="Statistic", show_stdev=False, key_loc="lower right", outfile=None, wait=True): """ Plots the results from an experiment. :param mat: the result matrix to plot :type mat: ResultMatrix :param title: the title for the experiment :type title: str :param axes_swapped: whether the axes whether swapped ("sets x cls" or "cls x sets") :type axes_swapped: bool :param measure: the measure that is being displayed :type measure: str :param show_stdev: whether to show the standard deviation as error bar :type show_stdev: bool :param key_loc: the location string for the key :type key_loc: str :param outfile: the output file, ignored if None :type outfile: str :param wait: whether to wait for the user to close the plot :type wait: bool """ if not plot.matplotlib_available: logger.error("Matplotlib is not installed, plotting unavailable!") return if not isinstance(mat, ResultMatrix): logger.error("Need to supply a result matrix!") return fig, ax = plt.subplots() if axes_swapped: ax.set_xlabel(measure) ax.set_ylabel("Classifiers") else: ax.set_xlabel("Classifiers") ax.set_ylabel(measure) ax.set_title(title) fig.canvas.set_window_title(title) ax.grid(True) ticksx = [] ticks = [] inc = 1.0 / float(mat.columns) for i in range(mat.columns): ticksx.append((i + 0.5) * inc) ticks.append("[" + str(i+1) + "]") plt.xticks(ticksx, ticks) plt.xlim([0.0, 1.0]) for r in range(mat.rows): x = [] means = [] stdevs = [] for c in range(mat.columns): mean = mat.get_mean(c, r) stdev = mat.get_stdev(c, r) if not math.isnan(mean): x.append((c + 0.5) * inc) means.append(mean) if not math.isnan(stdev): stdevs.append(stdev) plot_label = mat.get_row_name(r) if show_stdev: ax.errorbar(x, means, yerr=stdevs, fmt='-o', ls="-", label=plot_label) else: ax.plot(x, means, "o-", label=plot_label) plt.draw() plt.legend(loc=key_loc, shadow=True) if outfile is not None: plt.savefig(outfile) if wait: plt.show()
python
def plot_experiment(mat, title="Experiment", axes_swapped=False, measure="Statistic", show_stdev=False, key_loc="lower right", outfile=None, wait=True): if not plot.matplotlib_available: logger.error("Matplotlib is not installed, plotting unavailable!") return if not isinstance(mat, ResultMatrix): logger.error("Need to supply a result matrix!") return fig, ax = plt.subplots() if axes_swapped: ax.set_xlabel(measure) ax.set_ylabel("Classifiers") else: ax.set_xlabel("Classifiers") ax.set_ylabel(measure) ax.set_title(title) fig.canvas.set_window_title(title) ax.grid(True) ticksx = [] ticks = [] inc = 1.0 / float(mat.columns) for i in range(mat.columns): ticksx.append((i + 0.5) * inc) ticks.append("[" + str(i+1) + "]") plt.xticks(ticksx, ticks) plt.xlim([0.0, 1.0]) for r in range(mat.rows): x = [] means = [] stdevs = [] for c in range(mat.columns): mean = mat.get_mean(c, r) stdev = mat.get_stdev(c, r) if not math.isnan(mean): x.append((c + 0.5) * inc) means.append(mean) if not math.isnan(stdev): stdevs.append(stdev) plot_label = mat.get_row_name(r) if show_stdev: ax.errorbar(x, means, yerr=stdevs, fmt='-o', ls="-", label=plot_label) else: ax.plot(x, means, "o-", label=plot_label) plt.draw() plt.legend(loc=key_loc, shadow=True) if outfile is not None: plt.savefig(outfile) if wait: plt.show()
[ "def", "plot_experiment", "(", "mat", ",", "title", "=", "\"Experiment\"", ",", "axes_swapped", "=", "False", ",", "measure", "=", "\"Statistic\"", ",", "show_stdev", "=", "False", ",", "key_loc", "=", "\"lower right\"", ",", "outfile", "=", "None", ",", "wait", "=", "True", ")", ":", "if", "not", "plot", ".", "matplotlib_available", ":", "logger", ".", "error", "(", "\"Matplotlib is not installed, plotting unavailable!\"", ")", "return", "if", "not", "isinstance", "(", "mat", ",", "ResultMatrix", ")", ":", "logger", ".", "error", "(", "\"Need to supply a result matrix!\"", ")", "return", "fig", ",", "ax", "=", "plt", ".", "subplots", "(", ")", "if", "axes_swapped", ":", "ax", ".", "set_xlabel", "(", "measure", ")", "ax", ".", "set_ylabel", "(", "\"Classifiers\"", ")", "else", ":", "ax", ".", "set_xlabel", "(", "\"Classifiers\"", ")", "ax", ".", "set_ylabel", "(", "measure", ")", "ax", ".", "set_title", "(", "title", ")", "fig", ".", "canvas", ".", "set_window_title", "(", "title", ")", "ax", ".", "grid", "(", "True", ")", "ticksx", "=", "[", "]", "ticks", "=", "[", "]", "inc", "=", "1.0", "/", "float", "(", "mat", ".", "columns", ")", "for", "i", "in", "range", "(", "mat", ".", "columns", ")", ":", "ticksx", ".", "append", "(", "(", "i", "+", "0.5", ")", "*", "inc", ")", "ticks", ".", "append", "(", "\"[\"", "+", "str", "(", "i", "+", "1", ")", "+", "\"]\"", ")", "plt", ".", "xticks", "(", "ticksx", ",", "ticks", ")", "plt", ".", "xlim", "(", "[", "0.0", ",", "1.0", "]", ")", "for", "r", "in", "range", "(", "mat", ".", "rows", ")", ":", "x", "=", "[", "]", "means", "=", "[", "]", "stdevs", "=", "[", "]", "for", "c", "in", "range", "(", "mat", ".", "columns", ")", ":", "mean", "=", "mat", ".", "get_mean", "(", "c", ",", "r", ")", "stdev", "=", "mat", ".", "get_stdev", "(", "c", ",", "r", ")", "if", "not", "math", ".", "isnan", "(", "mean", ")", ":", "x", ".", "append", "(", "(", "c", "+", "0.5", ")", "*", "inc", ")", "means", ".", "append", "(", "mean", ")", "if", "not", "math", ".", "isnan", "(", "stdev", ")", ":", "stdevs", ".", "append", "(", "stdev", ")", "plot_label", "=", "mat", ".", "get_row_name", "(", "r", ")", "if", "show_stdev", ":", "ax", ".", "errorbar", "(", "x", ",", "means", ",", "yerr", "=", "stdevs", ",", "fmt", "=", "'-o'", ",", "ls", "=", "\"-\"", ",", "label", "=", "plot_label", ")", "else", ":", "ax", ".", "plot", "(", "x", ",", "means", ",", "\"o-\"", ",", "label", "=", "plot_label", ")", "plt", ".", "draw", "(", ")", "plt", ".", "legend", "(", "loc", "=", "key_loc", ",", "shadow", "=", "True", ")", "if", "outfile", "is", "not", "None", ":", "plt", ".", "savefig", "(", "outfile", ")", "if", "wait", ":", "plt", ".", "show", "(", ")" ]
Plots the results from an experiment. :param mat: the result matrix to plot :type mat: ResultMatrix :param title: the title for the experiment :type title: str :param axes_swapped: whether the axes whether swapped ("sets x cls" or "cls x sets") :type axes_swapped: bool :param measure: the measure that is being displayed :type measure: str :param show_stdev: whether to show the standard deviation as error bar :type show_stdev: bool :param key_loc: the location string for the key :type key_loc: str :param outfile: the output file, ignored if None :type outfile: str :param wait: whether to wait for the user to close the plot :type wait: bool
[ "Plots", "the", "results", "from", "an", "experiment", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/plot/experiments.py#L28-L99
1,669
fracpete/python-weka-wrapper3
python/weka/classifiers.py
predictions_to_instances
def predictions_to_instances(data, preds): """ Turns the predictions turned into an Instances object. :param data: the original dataset format :type data: Instances :param preds: the predictions to convert :type preds: list :return: the predictions, None if no predictions present :rtype: Instances """ if len(preds) == 0: return None is_numeric = isinstance(preds[0], NumericPrediction) # create header atts = [] if is_numeric: atts.append(Attribute.create_numeric("index")) atts.append(Attribute.create_numeric("weight")) atts.append(Attribute.create_numeric("actual")) atts.append(Attribute.create_numeric("predicted")) atts.append(Attribute.create_numeric("error")) else: atts.append(Attribute.create_numeric("index")) atts.append(Attribute.create_numeric("weight")) atts.append(data.class_attribute.copy(name="actual")) atts.append(data.class_attribute.copy(name="predicted")) atts.append(Attribute.create_nominal("error", ["no", "yes"])) atts.append(Attribute.create_numeric("classification")) for i in range(data.class_attribute.num_values): atts.append(Attribute.create_numeric("distribution-" + data.class_attribute.value(i))) result = Instances.create_instances("Predictions", atts, len(preds)) count = 0 for pred in preds: count += 1 if is_numeric: values = array([count, pred.weight, pred.actual, pred.predicted, pred.error]) else: if pred.actual == pred.predicted: error = 0.0 else: error = 1.0 l = [count, pred.weight, pred.actual, pred.predicted, error, max(pred.distribution)] for i in range(data.class_attribute.num_values): l.append(pred.distribution[i]) values = array(l) inst = Instance.create_instance(values) result.add_instance(inst) return result
python
def predictions_to_instances(data, preds): if len(preds) == 0: return None is_numeric = isinstance(preds[0], NumericPrediction) # create header atts = [] if is_numeric: atts.append(Attribute.create_numeric("index")) atts.append(Attribute.create_numeric("weight")) atts.append(Attribute.create_numeric("actual")) atts.append(Attribute.create_numeric("predicted")) atts.append(Attribute.create_numeric("error")) else: atts.append(Attribute.create_numeric("index")) atts.append(Attribute.create_numeric("weight")) atts.append(data.class_attribute.copy(name="actual")) atts.append(data.class_attribute.copy(name="predicted")) atts.append(Attribute.create_nominal("error", ["no", "yes"])) atts.append(Attribute.create_numeric("classification")) for i in range(data.class_attribute.num_values): atts.append(Attribute.create_numeric("distribution-" + data.class_attribute.value(i))) result = Instances.create_instances("Predictions", atts, len(preds)) count = 0 for pred in preds: count += 1 if is_numeric: values = array([count, pred.weight, pred.actual, pred.predicted, pred.error]) else: if pred.actual == pred.predicted: error = 0.0 else: error = 1.0 l = [count, pred.weight, pred.actual, pred.predicted, error, max(pred.distribution)] for i in range(data.class_attribute.num_values): l.append(pred.distribution[i]) values = array(l) inst = Instance.create_instance(values) result.add_instance(inst) return result
[ "def", "predictions_to_instances", "(", "data", ",", "preds", ")", ":", "if", "len", "(", "preds", ")", "==", "0", ":", "return", "None", "is_numeric", "=", "isinstance", "(", "preds", "[", "0", "]", ",", "NumericPrediction", ")", "# create header", "atts", "=", "[", "]", "if", "is_numeric", ":", "atts", ".", "append", "(", "Attribute", ".", "create_numeric", "(", "\"index\"", ")", ")", "atts", ".", "append", "(", "Attribute", ".", "create_numeric", "(", "\"weight\"", ")", ")", "atts", ".", "append", "(", "Attribute", ".", "create_numeric", "(", "\"actual\"", ")", ")", "atts", ".", "append", "(", "Attribute", ".", "create_numeric", "(", "\"predicted\"", ")", ")", "atts", ".", "append", "(", "Attribute", ".", "create_numeric", "(", "\"error\"", ")", ")", "else", ":", "atts", ".", "append", "(", "Attribute", ".", "create_numeric", "(", "\"index\"", ")", ")", "atts", ".", "append", "(", "Attribute", ".", "create_numeric", "(", "\"weight\"", ")", ")", "atts", ".", "append", "(", "data", ".", "class_attribute", ".", "copy", "(", "name", "=", "\"actual\"", ")", ")", "atts", ".", "append", "(", "data", ".", "class_attribute", ".", "copy", "(", "name", "=", "\"predicted\"", ")", ")", "atts", ".", "append", "(", "Attribute", ".", "create_nominal", "(", "\"error\"", ",", "[", "\"no\"", ",", "\"yes\"", "]", ")", ")", "atts", ".", "append", "(", "Attribute", ".", "create_numeric", "(", "\"classification\"", ")", ")", "for", "i", "in", "range", "(", "data", ".", "class_attribute", ".", "num_values", ")", ":", "atts", ".", "append", "(", "Attribute", ".", "create_numeric", "(", "\"distribution-\"", "+", "data", ".", "class_attribute", ".", "value", "(", "i", ")", ")", ")", "result", "=", "Instances", ".", "create_instances", "(", "\"Predictions\"", ",", "atts", ",", "len", "(", "preds", ")", ")", "count", "=", "0", "for", "pred", "in", "preds", ":", "count", "+=", "1", "if", "is_numeric", ":", "values", "=", "array", "(", "[", "count", ",", "pred", ".", "weight", ",", "pred", ".", "actual", ",", "pred", ".", "predicted", ",", "pred", ".", "error", "]", ")", "else", ":", "if", "pred", ".", "actual", "==", "pred", ".", "predicted", ":", "error", "=", "0.0", "else", ":", "error", "=", "1.0", "l", "=", "[", "count", ",", "pred", ".", "weight", ",", "pred", ".", "actual", ",", "pred", ".", "predicted", ",", "error", ",", "max", "(", "pred", ".", "distribution", ")", "]", "for", "i", "in", "range", "(", "data", ".", "class_attribute", ".", "num_values", ")", ":", "l", ".", "append", "(", "pred", ".", "distribution", "[", "i", "]", ")", "values", "=", "array", "(", "l", ")", "inst", "=", "Instance", ".", "create_instance", "(", "values", ")", "result", ".", "add_instance", "(", "inst", ")", "return", "result" ]
Turns the predictions turned into an Instances object. :param data: the original dataset format :type data: Instances :param preds: the predictions to convert :type preds: list :return: the predictions, None if no predictions present :rtype: Instances
[ "Turns", "the", "predictions", "turned", "into", "an", "Instances", "object", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/classifiers.py#L2061-L2114
1,670
fracpete/python-weka-wrapper3
python/weka/classifiers.py
Classifier.batch_size
def batch_size(self, size): """ Sets the batch size, in case this classifier is a batch predictor. :param size: the size of the batch :type size: str """ if self.is_batchpredictor: javabridge.call(self.jobject, "setBatchSize", "(Ljava/lang/String;)V", size)
python
def batch_size(self, size): if self.is_batchpredictor: javabridge.call(self.jobject, "setBatchSize", "(Ljava/lang/String;)V", size)
[ "def", "batch_size", "(", "self", ",", "size", ")", ":", "if", "self", ".", "is_batchpredictor", ":", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"setBatchSize\"", ",", "\"(Ljava/lang/String;)V\"", ",", "size", ")" ]
Sets the batch size, in case this classifier is a batch predictor. :param size: the size of the batch :type size: str
[ "Sets", "the", "batch", "size", "in", "case", "this", "classifier", "is", "a", "batch", "predictor", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/classifiers.py#L148-L156
1,671
fracpete/python-weka-wrapper3
python/weka/classifiers.py
Classifier.to_source
def to_source(self, classname): """ Returns the model as Java source code if the classifier implements weka.classifiers.Sourcable. :param classname: the classname for the generated Java code :type classname: str :return: the model as source code string :rtype: str """ if not self.check_type(self.jobject, "weka.classifiers.Sourcable"): return None return javabridge.call(self.jobject, "toSource", "(Ljava/lang/String;)Ljava/lang/String;", classname)
python
def to_source(self, classname): if not self.check_type(self.jobject, "weka.classifiers.Sourcable"): return None return javabridge.call(self.jobject, "toSource", "(Ljava/lang/String;)Ljava/lang/String;", classname)
[ "def", "to_source", "(", "self", ",", "classname", ")", ":", "if", "not", "self", ".", "check_type", "(", "self", ".", "jobject", ",", "\"weka.classifiers.Sourcable\"", ")", ":", "return", "None", "return", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"toSource\"", ",", "\"(Ljava/lang/String;)Ljava/lang/String;\"", ",", "classname", ")" ]
Returns the model as Java source code if the classifier implements weka.classifiers.Sourcable. :param classname: the classname for the generated Java code :type classname: str :return: the model as source code string :rtype: str
[ "Returns", "the", "model", "as", "Java", "source", "code", "if", "the", "classifier", "implements", "weka", ".", "classifiers", ".", "Sourcable", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/classifiers.py#L196-L207
1,672
fracpete/python-weka-wrapper3
python/weka/classifiers.py
GridSearch.evaluation
def evaluation(self, evl): """ Sets the statistic to use for evaluation. :param evl: the statistic :type evl: SelectedTag, Tag or str """ if isinstance(evl, str): evl = self.tags_evaluation.find(evl) if isinstance(evl, Tag): evl = SelectedTag(tag_id=evl.ident, tags=self.tags_evaluation) javabridge.call(self.jobject, "setEvaluation", "(Lweka/core/SelectedTag;)V", evl.jobject)
python
def evaluation(self, evl): if isinstance(evl, str): evl = self.tags_evaluation.find(evl) if isinstance(evl, Tag): evl = SelectedTag(tag_id=evl.ident, tags=self.tags_evaluation) javabridge.call(self.jobject, "setEvaluation", "(Lweka/core/SelectedTag;)V", evl.jobject)
[ "def", "evaluation", "(", "self", ",", "evl", ")", ":", "if", "isinstance", "(", "evl", ",", "str", ")", ":", "evl", "=", "self", ".", "tags_evaluation", ".", "find", "(", "evl", ")", "if", "isinstance", "(", "evl", ",", "Tag", ")", ":", "evl", "=", "SelectedTag", "(", "tag_id", "=", "evl", ".", "ident", ",", "tags", "=", "self", ".", "tags_evaluation", ")", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"setEvaluation\"", ",", "\"(Lweka/core/SelectedTag;)V\"", ",", "evl", ".", "jobject", ")" ]
Sets the statistic to use for evaluation. :param evl: the statistic :type evl: SelectedTag, Tag or str
[ "Sets", "the", "statistic", "to", "use", "for", "evaluation", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/classifiers.py#L355-L366
1,673
fracpete/python-weka-wrapper3
python/weka/classifiers.py
MultipleClassifiersCombiner.classifiers
def classifiers(self): """ Returns the list of base classifiers. :return: the classifier list :rtype: list """ objects = javabridge.get_env().get_object_array_elements( javabridge.call(self.jobject, "getClassifiers", "()[Lweka/classifiers/Classifier;")) result = [] for obj in objects: result.append(Classifier(jobject=obj)) return result
python
def classifiers(self): objects = javabridge.get_env().get_object_array_elements( javabridge.call(self.jobject, "getClassifiers", "()[Lweka/classifiers/Classifier;")) result = [] for obj in objects: result.append(Classifier(jobject=obj)) return result
[ "def", "classifiers", "(", "self", ")", ":", "objects", "=", "javabridge", ".", "get_env", "(", ")", ".", "get_object_array_elements", "(", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"getClassifiers\"", ",", "\"()[Lweka/classifiers/Classifier;\"", ")", ")", "result", "=", "[", "]", "for", "obj", "in", "objects", ":", "result", ".", "append", "(", "Classifier", "(", "jobject", "=", "obj", ")", ")", "return", "result" ]
Returns the list of base classifiers. :return: the classifier list :rtype: list
[ "Returns", "the", "list", "of", "base", "classifiers", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/classifiers.py#L573-L585
1,674
fracpete/python-weka-wrapper3
python/weka/classifiers.py
MultipleClassifiersCombiner.classifiers
def classifiers(self, classifiers): """ Sets the base classifiers. :param classifiers: the list of base classifiers to use :type classifiers: list """ obj = [] for classifier in classifiers: obj.append(classifier.jobject) javabridge.call(self.jobject, "setClassifiers", "([Lweka/classifiers/Classifier;)V", obj)
python
def classifiers(self, classifiers): obj = [] for classifier in classifiers: obj.append(classifier.jobject) javabridge.call(self.jobject, "setClassifiers", "([Lweka/classifiers/Classifier;)V", obj)
[ "def", "classifiers", "(", "self", ",", "classifiers", ")", ":", "obj", "=", "[", "]", "for", "classifier", "in", "classifiers", ":", "obj", ".", "append", "(", "classifier", ".", "jobject", ")", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"setClassifiers\"", ",", "\"([Lweka/classifiers/Classifier;)V\"", ",", "obj", ")" ]
Sets the base classifiers. :param classifiers: the list of base classifiers to use :type classifiers: list
[ "Sets", "the", "base", "classifiers", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/classifiers.py#L588-L598
1,675
fracpete/python-weka-wrapper3
python/weka/classifiers.py
Kernel.eval
def eval(self, id1, id2, inst1): """ Computes the result of the kernel function for two instances. If id1 == -1, eval use inst1 instead of an instance in the dataset. :param id1: the index of the first instance in the dataset :type id1: int :param id2: the index of the second instance in the dataset :type id2: int :param inst1: the instance corresponding to id1 (used if id1 == -1) :type inst1: Instance """ jinst1 = None if inst1 is not None: jinst1 = inst1.jobject return javabridge.call(self.jobject, "eval", "(IILweka/core/Instance;)D", id1, id2, jinst1)
python
def eval(self, id1, id2, inst1): jinst1 = None if inst1 is not None: jinst1 = inst1.jobject return javabridge.call(self.jobject, "eval", "(IILweka/core/Instance;)D", id1, id2, jinst1)
[ "def", "eval", "(", "self", ",", "id1", ",", "id2", ",", "inst1", ")", ":", "jinst1", "=", "None", "if", "inst1", "is", "not", "None", ":", "jinst1", "=", "inst1", ".", "jobject", "return", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"eval\"", ",", "\"(IILweka/core/Instance;)D\"", ",", "id1", ",", "id2", ",", "jinst1", ")" ]
Computes the result of the kernel function for two instances. If id1 == -1, eval use inst1 instead of an instance in the dataset. :param id1: the index of the first instance in the dataset :type id1: int :param id2: the index of the second instance in the dataset :type id2: int :param inst1: the instance corresponding to id1 (used if id1 == -1) :type inst1: Instance
[ "Computes", "the", "result", "of", "the", "kernel", "function", "for", "two", "instances", ".", "If", "id1", "==", "-", "1", "eval", "use", "inst1", "instead", "of", "an", "instance", "in", "the", "dataset", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/classifiers.py#L666-L681
1,676
fracpete/python-weka-wrapper3
python/weka/classifiers.py
KernelClassifier.kernel
def kernel(self): """ Returns the current kernel. :return: the kernel or None if none found :rtype: Kernel """ result = javabridge.static_call( "weka/classifiers/KernelHelper", "getKernel", "(Ljava/lang/Object;)Lweka/classifiers/functions/supportVector/Kernel;", self.jobject) if result is None: return None else: return Kernel(jobject=result)
python
def kernel(self): result = javabridge.static_call( "weka/classifiers/KernelHelper", "getKernel", "(Ljava/lang/Object;)Lweka/classifiers/functions/supportVector/Kernel;", self.jobject) if result is None: return None else: return Kernel(jobject=result)
[ "def", "kernel", "(", "self", ")", ":", "result", "=", "javabridge", ".", "static_call", "(", "\"weka/classifiers/KernelHelper\"", ",", "\"getKernel\"", ",", "\"(Ljava/lang/Object;)Lweka/classifiers/functions/supportVector/Kernel;\"", ",", "self", ".", "jobject", ")", "if", "result", "is", "None", ":", "return", "None", "else", ":", "return", "Kernel", "(", "jobject", "=", "result", ")" ]
Returns the current kernel. :return: the kernel or None if none found :rtype: Kernel
[ "Returns", "the", "current", "kernel", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/classifiers.py#L727-L741
1,677
fracpete/python-weka-wrapper3
python/weka/classifiers.py
KernelClassifier.kernel
def kernel(self, kernel): """ Sets the kernel. :param kernel: the kernel to set :type kernel: Kernel """ result = javabridge.static_call( "weka/classifiers/KernelHelper", "setKernel", "(Ljava/lang/Object;Lweka/classifiers/functions/supportVector/Kernel;)Z", self.jobject, kernel.jobject) if not result: raise Exception("Failed to set kernel!")
python
def kernel(self, kernel): result = javabridge.static_call( "weka/classifiers/KernelHelper", "setKernel", "(Ljava/lang/Object;Lweka/classifiers/functions/supportVector/Kernel;)Z", self.jobject, kernel.jobject) if not result: raise Exception("Failed to set kernel!")
[ "def", "kernel", "(", "self", ",", "kernel", ")", ":", "result", "=", "javabridge", ".", "static_call", "(", "\"weka/classifiers/KernelHelper\"", ",", "\"setKernel\"", ",", "\"(Ljava/lang/Object;Lweka/classifiers/functions/supportVector/Kernel;)Z\"", ",", "self", ".", "jobject", ",", "kernel", ".", "jobject", ")", "if", "not", "result", ":", "raise", "Exception", "(", "\"Failed to set kernel!\"", ")" ]
Sets the kernel. :param kernel: the kernel to set :type kernel: Kernel
[ "Sets", "the", "kernel", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/classifiers.py#L744-L756
1,678
fracpete/python-weka-wrapper3
python/weka/classifiers.py
CostMatrix.apply_cost_matrix
def apply_cost_matrix(self, data, rnd): """ Applies the cost matrix to the data. :param data: the data to apply to :type data: Instances :param rnd: the random number generator :type rnd: Random """ return Instances( javabridge.call( self.jobject, "applyCostMatrix", "(Lweka/core/Instances;Ljava/util/Random;)Lweka/core/Instances;", data.jobject, rnd.jobject))
python
def apply_cost_matrix(self, data, rnd): return Instances( javabridge.call( self.jobject, "applyCostMatrix", "(Lweka/core/Instances;Ljava/util/Random;)Lweka/core/Instances;", data.jobject, rnd.jobject))
[ "def", "apply_cost_matrix", "(", "self", ",", "data", ",", "rnd", ")", ":", "return", "Instances", "(", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"applyCostMatrix\"", ",", "\"(Lweka/core/Instances;Ljava/util/Random;)Lweka/core/Instances;\"", ",", "data", ".", "jobject", ",", "rnd", ".", "jobject", ")", ")" ]
Applies the cost matrix to the data. :param data: the data to apply to :type data: Instances :param rnd: the random number generator :type rnd: Random
[ "Applies", "the", "cost", "matrix", "to", "the", "data", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/classifiers.py#L924-L936
1,679
fracpete/python-weka-wrapper3
python/weka/classifiers.py
CostMatrix.expected_costs
def expected_costs(self, class_probs, inst=None): """ Calculates the expected misclassification cost for each possible class value, given class probability estimates. :param class_probs: the class probabilities :type class_probs: ndarray :return: the calculated costs :rtype: ndarray """ if inst is None: costs = javabridge.call( self.jobject, "expectedCosts", "([D)[D", javabridge.get_env().make_double_array(class_probs)) return javabridge.get_env().get_double_array_elements(costs) else: costs = javabridge.call( self.jobject, "expectedCosts", "([DLweka/core/Instance;)[D", javabridge.get_env().make_double_array(class_probs), inst.jobject) return javabridge.get_env().get_double_array_elements(costs)
python
def expected_costs(self, class_probs, inst=None): if inst is None: costs = javabridge.call( self.jobject, "expectedCosts", "([D)[D", javabridge.get_env().make_double_array(class_probs)) return javabridge.get_env().get_double_array_elements(costs) else: costs = javabridge.call( self.jobject, "expectedCosts", "([DLweka/core/Instance;)[D", javabridge.get_env().make_double_array(class_probs), inst.jobject) return javabridge.get_env().get_double_array_elements(costs)
[ "def", "expected_costs", "(", "self", ",", "class_probs", ",", "inst", "=", "None", ")", ":", "if", "inst", "is", "None", ":", "costs", "=", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"expectedCosts\"", ",", "\"([D)[D\"", ",", "javabridge", ".", "get_env", "(", ")", ".", "make_double_array", "(", "class_probs", ")", ")", "return", "javabridge", ".", "get_env", "(", ")", ".", "get_double_array_elements", "(", "costs", ")", "else", ":", "costs", "=", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"expectedCosts\"", ",", "\"([DLweka/core/Instance;)[D\"", ",", "javabridge", ".", "get_env", "(", ")", ".", "make_double_array", "(", "class_probs", ")", ",", "inst", ".", "jobject", ")", "return", "javabridge", ".", "get_env", "(", ")", ".", "get_double_array_elements", "(", "costs", ")" ]
Calculates the expected misclassification cost for each possible class value, given class probability estimates. :param class_probs: the class probabilities :type class_probs: ndarray :return: the calculated costs :rtype: ndarray
[ "Calculates", "the", "expected", "misclassification", "cost", "for", "each", "possible", "class", "value", "given", "class", "probability", "estimates", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/classifiers.py#L938-L956
1,680
fracpete/python-weka-wrapper3
python/weka/classifiers.py
CostMatrix.get_cell
def get_cell(self, row, col): """ Returns the JB_Object at the specified location. :param row: the 0-based index of the row :type row: int :param col: the 0-based index of the column :type col: int :return: the object in that cell :rtype: JB_Object """ return javabridge.call( self.jobject, "getCell", "(II)Ljava/lang/Object;", row, col)
python
def get_cell(self, row, col): return javabridge.call( self.jobject, "getCell", "(II)Ljava/lang/Object;", row, col)
[ "def", "get_cell", "(", "self", ",", "row", ",", "col", ")", ":", "return", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"getCell\"", ",", "\"(II)Ljava/lang/Object;\"", ",", "row", ",", "col", ")" ]
Returns the JB_Object at the specified location. :param row: the 0-based index of the row :type row: int :param col: the 0-based index of the column :type col: int :return: the object in that cell :rtype: JB_Object
[ "Returns", "the", "JB_Object", "at", "the", "specified", "location", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/classifiers.py#L958-L970
1,681
fracpete/python-weka-wrapper3
python/weka/classifiers.py
CostMatrix.set_cell
def set_cell(self, row, col, obj): """ Sets the JB_Object at the specified location. Automatically unwraps JavaObject. :param row: the 0-based index of the row :type row: int :param col: the 0-based index of the column :type col: int :param obj: the object for that cell :type obj: object """ if isinstance(obj, JavaObject): obj = obj.jobject javabridge.call( self.jobject, "setCell", "(IILjava/lang/Object;)V", row, col, obj)
python
def set_cell(self, row, col, obj): if isinstance(obj, JavaObject): obj = obj.jobject javabridge.call( self.jobject, "setCell", "(IILjava/lang/Object;)V", row, col, obj)
[ "def", "set_cell", "(", "self", ",", "row", ",", "col", ",", "obj", ")", ":", "if", "isinstance", "(", "obj", ",", "JavaObject", ")", ":", "obj", "=", "obj", ".", "jobject", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"setCell\"", ",", "\"(IILjava/lang/Object;)V\"", ",", "row", ",", "col", ",", "obj", ")" ]
Sets the JB_Object at the specified location. Automatically unwraps JavaObject. :param row: the 0-based index of the row :type row: int :param col: the 0-based index of the column :type col: int :param obj: the object for that cell :type obj: object
[ "Sets", "the", "JB_Object", "at", "the", "specified", "location", ".", "Automatically", "unwraps", "JavaObject", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/classifiers.py#L972-L986
1,682
fracpete/python-weka-wrapper3
python/weka/classifiers.py
CostMatrix.get_element
def get_element(self, row, col, inst=None): """ Returns the value at the specified location. :param row: the 0-based index of the row :type row: int :param col: the 0-based index of the column :type col: int :param inst: the Instace :type inst: Instance :return: the value in that cell :rtype: float """ if inst is None: return javabridge.call( self.jobject, "getElement", "(II)D", row, col) else: return javabridge.call( self.jobject, "getElement", "(IILweka/core/Instance;)D", row, col, inst.jobject)
python
def get_element(self, row, col, inst=None): if inst is None: return javabridge.call( self.jobject, "getElement", "(II)D", row, col) else: return javabridge.call( self.jobject, "getElement", "(IILweka/core/Instance;)D", row, col, inst.jobject)
[ "def", "get_element", "(", "self", ",", "row", ",", "col", ",", "inst", "=", "None", ")", ":", "if", "inst", "is", "None", ":", "return", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"getElement\"", ",", "\"(II)D\"", ",", "row", ",", "col", ")", "else", ":", "return", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"getElement\"", ",", "\"(IILweka/core/Instance;)D\"", ",", "row", ",", "col", ",", "inst", ".", "jobject", ")" ]
Returns the value at the specified location. :param row: the 0-based index of the row :type row: int :param col: the 0-based index of the column :type col: int :param inst: the Instace :type inst: Instance :return: the value in that cell :rtype: float
[ "Returns", "the", "value", "at", "the", "specified", "location", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/classifiers.py#L988-L1006
1,683
fracpete/python-weka-wrapper3
python/weka/classifiers.py
CostMatrix.set_element
def set_element(self, row, col, value): """ Sets the float value at the specified location. :param row: the 0-based index of the row :type row: int :param col: the 0-based index of the column :type col: int :param value: the float value for that cell :type value: float """ javabridge.call( self.jobject, "setElement", "(IID)V", row, col, value)
python
def set_element(self, row, col, value): javabridge.call( self.jobject, "setElement", "(IID)V", row, col, value)
[ "def", "set_element", "(", "self", ",", "row", ",", "col", ",", "value", ")", ":", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"setElement\"", ",", "\"(IID)V\"", ",", "row", ",", "col", ",", "value", ")" ]
Sets the float value at the specified location. :param row: the 0-based index of the row :type row: int :param col: the 0-based index of the column :type col: int :param value: the float value for that cell :type value: float
[ "Sets", "the", "float", "value", "at", "the", "specified", "location", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/classifiers.py#L1008-L1020
1,684
fracpete/python-weka-wrapper3
python/weka/classifiers.py
CostMatrix.get_max_cost
def get_max_cost(self, class_value, inst=None): """ Gets the maximum cost for a particular class value. :param class_value: the class value to get the maximum cost for :type class_value: int :param inst: the Instance :type inst: Instance :return: the cost :rtype: float """ if inst is None: return javabridge.call( self.jobject, "getMaxCost", "(I)D", class_value) else: return javabridge.call( self.jobject, "getElement", "(ILweka/core/Instance;)D", class_value, inst.jobject)
python
def get_max_cost(self, class_value, inst=None): if inst is None: return javabridge.call( self.jobject, "getMaxCost", "(I)D", class_value) else: return javabridge.call( self.jobject, "getElement", "(ILweka/core/Instance;)D", class_value, inst.jobject)
[ "def", "get_max_cost", "(", "self", ",", "class_value", ",", "inst", "=", "None", ")", ":", "if", "inst", "is", "None", ":", "return", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"getMaxCost\"", ",", "\"(I)D\"", ",", "class_value", ")", "else", ":", "return", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"getElement\"", ",", "\"(ILweka/core/Instance;)D\"", ",", "class_value", ",", "inst", ".", "jobject", ")" ]
Gets the maximum cost for a particular class value. :param class_value: the class value to get the maximum cost for :type class_value: int :param inst: the Instance :type inst: Instance :return: the cost :rtype: float
[ "Gets", "the", "maximum", "cost", "for", "a", "particular", "class", "value", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/classifiers.py#L1022-L1038
1,685
fracpete/python-weka-wrapper3
python/weka/classifiers.py
Evaluation.crossvalidate_model
def crossvalidate_model(self, classifier, data, num_folds, rnd, output=None): """ Crossvalidates the model using the specified data, number of folds and random number generator wrapper. :param classifier: the classifier to cross-validate :type classifier: Classifier :param data: the data to evaluate on :type data: Instances :param num_folds: the number of folds :type num_folds: int :param rnd: the random number generator to use :type rnd: Random :param output: the output generator to use :type output: PredictionOutput """ if output is None: generator = [] else: generator = [output.jobject] javabridge.call( self.jobject, "crossValidateModel", "(Lweka/classifiers/Classifier;Lweka/core/Instances;ILjava/util/Random;[Ljava/lang/Object;)V", classifier.jobject, data.jobject, num_folds, rnd.jobject, generator)
python
def crossvalidate_model(self, classifier, data, num_folds, rnd, output=None): if output is None: generator = [] else: generator = [output.jobject] javabridge.call( self.jobject, "crossValidateModel", "(Lweka/classifiers/Classifier;Lweka/core/Instances;ILjava/util/Random;[Ljava/lang/Object;)V", classifier.jobject, data.jobject, num_folds, rnd.jobject, generator)
[ "def", "crossvalidate_model", "(", "self", ",", "classifier", ",", "data", ",", "num_folds", ",", "rnd", ",", "output", "=", "None", ")", ":", "if", "output", "is", "None", ":", "generator", "=", "[", "]", "else", ":", "generator", "=", "[", "output", ".", "jobject", "]", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"crossValidateModel\"", ",", "\"(Lweka/classifiers/Classifier;Lweka/core/Instances;ILjava/util/Random;[Ljava/lang/Object;)V\"", ",", "classifier", ".", "jobject", ",", "data", ".", "jobject", ",", "num_folds", ",", "rnd", ".", "jobject", ",", "generator", ")" ]
Crossvalidates the model using the specified data, number of folds and random number generator wrapper. :param classifier: the classifier to cross-validate :type classifier: Classifier :param data: the data to evaluate on :type data: Instances :param num_folds: the number of folds :type num_folds: int :param rnd: the random number generator to use :type rnd: Random :param output: the output generator to use :type output: PredictionOutput
[ "Crossvalidates", "the", "model", "using", "the", "specified", "data", "number", "of", "folds", "and", "random", "number", "generator", "wrapper", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/classifiers.py#L1133-L1155
1,686
fracpete/python-weka-wrapper3
python/weka/classifiers.py
Evaluation.summary
def summary(self, title=None, complexity=False): """ Generates a summary. :param title: optional title :type title: str :param complexity: whether to print the complexity information as well :type complexity: bool :return: the summary :rtype: str """ if title is None: return javabridge.call( self.jobject, "toSummaryString", "()Ljava/lang/String;") else: return javabridge.call( self.jobject, "toSummaryString", "(Ljava/lang/String;Z)Ljava/lang/String;", title, complexity)
python
def summary(self, title=None, complexity=False): if title is None: return javabridge.call( self.jobject, "toSummaryString", "()Ljava/lang/String;") else: return javabridge.call( self.jobject, "toSummaryString", "(Ljava/lang/String;Z)Ljava/lang/String;", title, complexity)
[ "def", "summary", "(", "self", ",", "title", "=", "None", ",", "complexity", "=", "False", ")", ":", "if", "title", "is", "None", ":", "return", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"toSummaryString\"", ",", "\"()Ljava/lang/String;\"", ")", "else", ":", "return", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"toSummaryString\"", ",", "\"(Ljava/lang/String;Z)Ljava/lang/String;\"", ",", "title", ",", "complexity", ")" ]
Generates a summary. :param title: optional title :type title: str :param complexity: whether to print the complexity information as well :type complexity: bool :return: the summary :rtype: str
[ "Generates", "a", "summary", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/classifiers.py#L1221-L1237
1,687
fracpete/python-weka-wrapper3
python/weka/classifiers.py
Evaluation.class_details
def class_details(self, title=None): """ Generates the class details. :param title: optional title :type title: str :return: the details :rtype: str """ if title is None: return javabridge.call( self.jobject, "toClassDetailsString", "()Ljava/lang/String;") else: return javabridge.call( self.jobject, "toClassDetailsString", "(Ljava/lang/String;)Ljava/lang/String;", title)
python
def class_details(self, title=None): if title is None: return javabridge.call( self.jobject, "toClassDetailsString", "()Ljava/lang/String;") else: return javabridge.call( self.jobject, "toClassDetailsString", "(Ljava/lang/String;)Ljava/lang/String;", title)
[ "def", "class_details", "(", "self", ",", "title", "=", "None", ")", ":", "if", "title", "is", "None", ":", "return", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"toClassDetailsString\"", ",", "\"()Ljava/lang/String;\"", ")", "else", ":", "return", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"toClassDetailsString\"", ",", "\"(Ljava/lang/String;)Ljava/lang/String;\"", ",", "title", ")" ]
Generates the class details. :param title: optional title :type title: str :return: the details :rtype: str
[ "Generates", "the", "class", "details", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/classifiers.py#L1239-L1253
1,688
fracpete/python-weka-wrapper3
python/weka/classifiers.py
Evaluation.matrix
def matrix(self, title=None): """ Generates the confusion matrix. :param title: optional title :type title: str :return: the matrix :rtype: str """ if title is None: return javabridge.call(self.jobject, "toMatrixString", "()Ljava/lang/String;") else: return javabridge.call(self.jobject, "toMatrixString", "(Ljava/lang/String;)Ljava/lang/String;", title)
python
def matrix(self, title=None): if title is None: return javabridge.call(self.jobject, "toMatrixString", "()Ljava/lang/String;") else: return javabridge.call(self.jobject, "toMatrixString", "(Ljava/lang/String;)Ljava/lang/String;", title)
[ "def", "matrix", "(", "self", ",", "title", "=", "None", ")", ":", "if", "title", "is", "None", ":", "return", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"toMatrixString\"", ",", "\"()Ljava/lang/String;\"", ")", "else", ":", "return", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"toMatrixString\"", ",", "\"(Ljava/lang/String;)Ljava/lang/String;\"", ",", "title", ")" ]
Generates the confusion matrix. :param title: optional title :type title: str :return: the matrix :rtype: str
[ "Generates", "the", "confusion", "matrix", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/classifiers.py#L1255-L1267
1,689
fracpete/python-weka-wrapper3
python/weka/classifiers.py
Evaluation.predictions
def predictions(self): """ Returns the predictions. :return: the predictions. None if not available :rtype: list """ preds = javabridge.get_collection_wrapper( javabridge.call(self.jobject, "predictions", "()Ljava/util/ArrayList;")) if self.discard_predictions: result = None else: result = [] for pred in preds: if is_instance_of(pred, "weka.classifiers.evaluation.NominalPrediction"): result.append(NominalPrediction(pred)) elif is_instance_of(pred, "weka.classifiers.evaluation.NumericPrediction"): result.append(NumericPrediction(pred)) else: result.append(Prediction(pred)) return result
python
def predictions(self): preds = javabridge.get_collection_wrapper( javabridge.call(self.jobject, "predictions", "()Ljava/util/ArrayList;")) if self.discard_predictions: result = None else: result = [] for pred in preds: if is_instance_of(pred, "weka.classifiers.evaluation.NominalPrediction"): result.append(NominalPrediction(pred)) elif is_instance_of(pred, "weka.classifiers.evaluation.NumericPrediction"): result.append(NumericPrediction(pred)) else: result.append(Prediction(pred)) return result
[ "def", "predictions", "(", "self", ")", ":", "preds", "=", "javabridge", ".", "get_collection_wrapper", "(", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"predictions\"", ",", "\"()Ljava/util/ArrayList;\"", ")", ")", "if", "self", ".", "discard_predictions", ":", "result", "=", "None", "else", ":", "result", "=", "[", "]", "for", "pred", "in", "preds", ":", "if", "is_instance_of", "(", "pred", ",", "\"weka.classifiers.evaluation.NominalPrediction\"", ")", ":", "result", ".", "append", "(", "NominalPrediction", "(", "pred", ")", ")", "elif", "is_instance_of", "(", "pred", ",", "\"weka.classifiers.evaluation.NumericPrediction\"", ")", ":", "result", ".", "append", "(", "NumericPrediction", "(", "pred", ")", ")", "else", ":", "result", ".", "append", "(", "Prediction", "(", "pred", ")", ")", "return", "result" ]
Returns the predictions. :return: the predictions. None if not available :rtype: list
[ "Returns", "the", "predictions", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/classifiers.py#L1905-L1925
1,690
fracpete/python-weka-wrapper3
python/weka/classifiers.py
PredictionOutput.print_all
def print_all(self, cls, data): """ Prints the header, classifications and footer to the buffer. :param cls: the classifier :type cls: Classifier :param data: the test data :type data: Instances """ javabridge.call( self.jobject, "print", "(Lweka/classifiers/Classifier;Lweka/core/Instances;)V", cls.jobject, data.jobject)
python
def print_all(self, cls, data): javabridge.call( self.jobject, "print", "(Lweka/classifiers/Classifier;Lweka/core/Instances;)V", cls.jobject, data.jobject)
[ "def", "print_all", "(", "self", ",", "cls", ",", "data", ")", ":", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"print\"", ",", "\"(Lweka/classifiers/Classifier;Lweka/core/Instances;)V\"", ",", "cls", ".", "jobject", ",", "data", ".", "jobject", ")" ]
Prints the header, classifications and footer to the buffer. :param cls: the classifier :type cls: Classifier :param data: the test data :type data: Instances
[ "Prints", "the", "header", "classifications", "and", "footer", "to", "the", "buffer", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/classifiers.py#L2001-L2012
1,691
fracpete/python-weka-wrapper3
python/weka/classifiers.py
PredictionOutput.print_classifications
def print_classifications(self, cls, data): """ Prints the classifications to the buffer. :param cls: the classifier :type cls: Classifier :param data: the test data :type data: Instances """ javabridge.call( self.jobject, "printClassifications", "(Lweka/classifiers/Classifier;Lweka/core/Instances;)V", cls.jobject, data.jobject)
python
def print_classifications(self, cls, data): javabridge.call( self.jobject, "printClassifications", "(Lweka/classifiers/Classifier;Lweka/core/Instances;)V", cls.jobject, data.jobject)
[ "def", "print_classifications", "(", "self", ",", "cls", ",", "data", ")", ":", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"printClassifications\"", ",", "\"(Lweka/classifiers/Classifier;Lweka/core/Instances;)V\"", ",", "cls", ".", "jobject", ",", "data", ".", "jobject", ")" ]
Prints the classifications to the buffer. :param cls: the classifier :type cls: Classifier :param data: the test data :type data: Instances
[ "Prints", "the", "classifications", "to", "the", "buffer", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/classifiers.py#L2014-L2025
1,692
fracpete/python-weka-wrapper3
python/weka/classifiers.py
PredictionOutput.print_classification
def print_classification(self, cls, inst, index): """ Prints the classification to the buffer. :param cls: the classifier :type cls: Classifier :param inst: the test instance :type inst: Instance :param index: the 0-based index of the test instance :type index: int """ javabridge.call( self.jobject, "printClassification", "(Lweka/classifiers/Classifier;Lweka/core/Instance;I)V", cls.jobject, inst.jobject, index)
python
def print_classification(self, cls, inst, index): javabridge.call( self.jobject, "printClassification", "(Lweka/classifiers/Classifier;Lweka/core/Instance;I)V", cls.jobject, inst.jobject, index)
[ "def", "print_classification", "(", "self", ",", "cls", ",", "inst", ",", "index", ")", ":", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"printClassification\"", ",", "\"(Lweka/classifiers/Classifier;Lweka/core/Instance;I)V\"", ",", "cls", ".", "jobject", ",", "inst", ".", "jobject", ",", "index", ")" ]
Prints the classification to the buffer. :param cls: the classifier :type cls: Classifier :param inst: the test instance :type inst: Instance :param index: the 0-based index of the test instance :type index: int
[ "Prints", "the", "classification", "to", "the", "buffer", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/classifiers.py#L2027-L2040
1,693
fracpete/python-weka-wrapper3
python/weka/core/tokenizers.py
Tokenizer.tokenize
def tokenize(self, s): """ Tokenizes the string. :param s: the string to tokenize :type s: str :return: the iterator :rtype: TokenIterator """ javabridge.call(self.jobject, "tokenize", "(Ljava/lang/String;)V", s) return TokenIterator(self)
python
def tokenize(self, s): javabridge.call(self.jobject, "tokenize", "(Ljava/lang/String;)V", s) return TokenIterator(self)
[ "def", "tokenize", "(", "self", ",", "s", ")", ":", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"tokenize\"", ",", "\"(Ljava/lang/String;)V\"", ",", "s", ")", "return", "TokenIterator", "(", "self", ")" ]
Tokenizes the string. :param s: the string to tokenize :type s: str :return: the iterator :rtype: TokenIterator
[ "Tokenizes", "the", "string", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/core/tokenizers.py#L76-L86
1,694
fracpete/python-weka-wrapper3
python/weka/datagenerators.py
DataGenerator.define_data_format
def define_data_format(self): """ Returns the data format. :return: the data format :rtype: Instances """ data = javabridge.call(self.jobject, "defineDataFormat", "()Lweka/core/Instances;") if data is None: return None else: return Instances(data)
python
def define_data_format(self): data = javabridge.call(self.jobject, "defineDataFormat", "()Lweka/core/Instances;") if data is None: return None else: return Instances(data)
[ "def", "define_data_format", "(", "self", ")", ":", "data", "=", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"defineDataFormat\"", ",", "\"()Lweka/core/Instances;\"", ")", "if", "data", "is", "None", ":", "return", "None", "else", ":", "return", "Instances", "(", "data", ")" ]
Returns the data format. :return: the data format :rtype: Instances
[ "Returns", "the", "data", "format", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/datagenerators.py#L50-L61
1,695
fracpete/python-weka-wrapper3
python/weka/datagenerators.py
DataGenerator.dataset_format
def dataset_format(self): """ Returns the dataset format. :return: the format :rtype: Instances """ data = javabridge.call(self.jobject, "getDatasetFormat", "()Lweka/core/Instances;") if data is None: return None else: return Instances(data)
python
def dataset_format(self): data = javabridge.call(self.jobject, "getDatasetFormat", "()Lweka/core/Instances;") if data is None: return None else: return Instances(data)
[ "def", "dataset_format", "(", "self", ")", ":", "data", "=", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"getDatasetFormat\"", ",", "\"()Lweka/core/Instances;\"", ")", "if", "data", "is", "None", ":", "return", "None", "else", ":", "return", "Instances", "(", "data", ")" ]
Returns the dataset format. :return: the format :rtype: Instances
[ "Returns", "the", "dataset", "format", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/datagenerators.py#L74-L85
1,696
fracpete/python-weka-wrapper3
python/weka/datagenerators.py
DataGenerator.generate_example
def generate_example(self): """ Returns a single Instance. :return: the next example :rtype: Instance """ data = javabridge.call(self.jobject, "generateExample", "()Lweka/core/Instance;") if data is None: return None else: return Instance(data)
python
def generate_example(self): data = javabridge.call(self.jobject, "generateExample", "()Lweka/core/Instance;") if data is None: return None else: return Instance(data)
[ "def", "generate_example", "(", "self", ")", ":", "data", "=", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"generateExample\"", ",", "\"()Lweka/core/Instance;\"", ")", "if", "data", "is", "None", ":", "return", "None", "else", ":", "return", "Instance", "(", "data", ")" ]
Returns a single Instance. :return: the next example :rtype: Instance
[ "Returns", "a", "single", "Instance", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/datagenerators.py#L116-L127
1,697
fracpete/python-weka-wrapper3
python/weka/datagenerators.py
DataGenerator.generate_examples
def generate_examples(self): """ Returns complete dataset. :return: the generated dataset :rtype: Instances """ data = javabridge.call(self.jobject, "generateExamples", "()Lweka/core/Instances;") if data is None: return None else: return Instances(data)
python
def generate_examples(self): data = javabridge.call(self.jobject, "generateExamples", "()Lweka/core/Instances;") if data is None: return None else: return Instances(data)
[ "def", "generate_examples", "(", "self", ")", ":", "data", "=", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"generateExamples\"", ",", "\"()Lweka/core/Instances;\"", ")", "if", "data", "is", "None", ":", "return", "None", "else", ":", "return", "Instances", "(", "data", ")" ]
Returns complete dataset. :return: the generated dataset :rtype: Instances
[ "Returns", "complete", "dataset", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/datagenerators.py#L129-L140
1,698
fracpete/python-weka-wrapper3
python/weka/datagenerators.py
DataGenerator.make_copy
def make_copy(cls, generator): """ Creates a copy of the generator. :param generator: the generator to copy :type generator: DataGenerator :return: the copy of the generator :rtype: DataGenerator """ return from_commandline( to_commandline(generator), classname=classes.get_classname(DataGenerator()))
python
def make_copy(cls, generator): return from_commandline( to_commandline(generator), classname=classes.get_classname(DataGenerator()))
[ "def", "make_copy", "(", "cls", ",", "generator", ")", ":", "return", "from_commandline", "(", "to_commandline", "(", "generator", ")", ",", "classname", "=", "classes", ".", "get_classname", "(", "DataGenerator", "(", ")", ")", ")" ]
Creates a copy of the generator. :param generator: the generator to copy :type generator: DataGenerator :return: the copy of the generator :rtype: DataGenerator
[ "Creates", "a", "copy", "of", "the", "generator", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/datagenerators.py#L167-L177
1,699
fracpete/python-weka-wrapper3
python/weka/flow/source.py
DataGenerator.to_config
def to_config(self, k, v): """ Hook method that allows conversion of individual options. :param k: the key of the option :type k: str :param v: the value :type v: object :return: the potentially processed value :rtype: object """ if k == "setup": return base.to_commandline(v) return super(DataGenerator, self).to_config(k, v)
python
def to_config(self, k, v): if k == "setup": return base.to_commandline(v) return super(DataGenerator, self).to_config(k, v)
[ "def", "to_config", "(", "self", ",", "k", ",", "v", ")", ":", "if", "k", "==", "\"setup\"", ":", "return", "base", ".", "to_commandline", "(", "v", ")", "return", "super", "(", "DataGenerator", ",", "self", ")", ".", "to_config", "(", "k", ",", "v", ")" ]
Hook method that allows conversion of individual options. :param k: the key of the option :type k: str :param v: the value :type v: object :return: the potentially processed value :rtype: object
[ "Hook", "method", "that", "allows", "conversion", "of", "individual", "options", "." ]
d850ab1bdb25fbd5a8d86e99f34a397975425838
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/source.py#L598-L611