repository_name
stringlengths
5
67
func_path_in_repository
stringlengths
4
234
func_name
stringlengths
0
314
whole_func_string
stringlengths
52
3.87M
language
stringclasses
6 values
func_code_string
stringlengths
52
3.87M
func_code_tokens
sequencelengths
15
672k
func_documentation_string
stringlengths
1
47.2k
func_documentation_tokens
sequencelengths
1
3.92k
split_name
stringclasses
1 value
func_code_url
stringlengths
85
339
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): """ 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
[ "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", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/base.py#L384-L403
fracpete/python-weka-wrapper3
python/weka/flow/base.py
OutputProducer.output
def output(self): """ Returns the next available output token. :return: the next token, None if none available :rtype: Token """ if (self._output is None) or (len(self._output) == 0): result = None else: result = self._output.pop(0) return result
python
def output(self): """ Returns the next available output token. :return: the next token, None if none available :rtype: Token """ if (self._output is None) or (len(self._output) == 0): result = None else: result = self._output.pop(0) return result
[ "def", "output", "(", "self", ")", ":", "if", "(", "self", ".", "_output", "is", "None", ")", "or", "(", "len", "(", "self", ".", "_output", ")", "==", "0", ")", ":", "result", "=", "None", "else", ":", "result", "=", "self", ".", "_output", ".", "pop", "(", "0", ")", "return", "result" ]
Returns the next available output token. :return: the next token, None if none available :rtype: Token
[ "Returns", "the", "next", "available", "output", "token", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/base.py#L544-L555
fracpete/python-weka-wrapper3
python/weka/flow/base.py
StorageHandler.expand
def expand(self, s): """ Expands all occurrences of "@{...}" within the string with the actual values currently stored in internal storage. :param s: the string to expand :type s: str :return: the expanded string :rtype: str """ result = s while result.find("@{") > -1: start = result.index("@{") end = result.index("}", start) name = result[start + 2:end] value = self.storage[name] if value is None: raise("Storage value '" + name + "' not present, failed to expand string: " + s) else: result = result[0:start] + str(value) + result[end + 1:] return result
python
def expand(self, s): """ Expands all occurrences of "@{...}" within the string with the actual values currently stored in internal storage. :param s: the string to expand :type s: str :return: the expanded string :rtype: str """ result = s while result.find("@{") > -1: start = result.index("@{") end = result.index("}", start) name = result[start + 2:end] value = self.storage[name] if value is None: raise("Storage value '" + name + "' not present, failed to expand string: " + s) else: result = result[0:start] + str(value) + result[end + 1:] return result
[ "def", "expand", "(", "self", ",", "s", ")", ":", "result", "=", "s", "while", "result", ".", "find", "(", "\"@{\"", ")", ">", "-", "1", ":", "start", "=", "result", ".", "index", "(", "\"@{\"", ")", "end", "=", "result", ".", "index", "(", "\"}\"", ",", "start", ")", "name", "=", "result", "[", "start", "+", "2", ":", "end", "]", "value", "=", "self", ".", "storage", "[", "name", "]", "if", "value", "is", "None", ":", "raise", "(", "\"Storage value '\"", "+", "name", "+", "\"' not present, failed to expand string: \"", "+", "s", ")", "else", ":", "result", "=", "result", "[", "0", ":", "start", "]", "+", "str", "(", "value", ")", "+", "result", "[", "end", "+", "1", ":", "]", "return", "result" ]
Expands all occurrences of "@{...}" within the string with the actual values currently stored in internal storage. :param s: the string to expand :type s: str :return: the expanded string :rtype: str
[ "Expands", "all", "occurrences", "of", "@", "{", "...", "}", "within", "the", "string", "with", "the", "actual", "values", "currently", "stored", "in", "internal", "storage", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/base.py#L573-L593
fracpete/python-weka-wrapper3
python/weka/flow/base.py
StorageHandler.extract
def extract(cls, padded): """ Removes the surrounding "@{...}" from the name. :param padded: the padded string :type padded: str :return: the extracted name :rtype: str """ if padded.startswith("@{") and padded.endswith("}"): return padded[2:len(padded)-1] else: return padded
python
def extract(cls, padded): """ Removes the surrounding "@{...}" from the name. :param padded: the padded string :type padded: str :return: the extracted name :rtype: str """ if padded.startswith("@{") and padded.endswith("}"): return padded[2:len(padded)-1] else: return padded
[ "def", "extract", "(", "cls", ",", "padded", ")", ":", "if", "padded", ".", "startswith", "(", "\"@{\"", ")", "and", "padded", ".", "endswith", "(", "\"}\"", ")", ":", "return", "padded", "[", "2", ":", "len", "(", "padded", ")", "-", "1", "]", "else", ":", "return", "padded" ]
Removes the surrounding "@{...}" from the name. :param padded: the padded string :type padded: str :return: the extracted name :rtype: str
[ "Removes", "the", "surrounding", "@", "{", "...", "}", "from", "the", "name", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/base.py#L611-L623
fracpete/python-weka-wrapper3
python/weka/flow/control.py
ActorHandler.fix_config
def fix_config(self, options): """ Fixes the options, if necessary. I.e., it adds all required elements to the dictionary. :param options: the options to fix :type options: dict :return: the (potentially) fixed options :rtype: dict """ options = super(ActorHandler, self).fix_config(options) opt = "actors" if opt not in options: options[opt] = self.default_actors() if opt not in self.help: self.help[opt] = "The list of sub-actors that this actor manages." return options
python
def fix_config(self, options): """ Fixes the options, if necessary. I.e., it adds all required elements to the dictionary. :param options: the options to fix :type options: dict :return: the (potentially) fixed options :rtype: dict """ options = super(ActorHandler, self).fix_config(options) opt = "actors" if opt not in options: options[opt] = self.default_actors() if opt not in self.help: self.help[opt] = "The list of sub-actors that this actor manages." return options
[ "def", "fix_config", "(", "self", ",", "options", ")", ":", "options", "=", "super", "(", "ActorHandler", ",", "self", ")", ".", "fix_config", "(", "options", ")", "opt", "=", "\"actors\"", "if", "opt", "not", "in", "options", ":", "options", "[", "opt", "]", "=", "self", ".", "default_actors", "(", ")", "if", "opt", "not", "in", "self", ".", "help", ":", "self", ".", "help", "[", "opt", "]", "=", "\"The list of sub-actors that this actor manages.\"", "return", "options" ]
Fixes the options, if necessary. I.e., it adds all required elements to the dictionary. :param options: the options to fix :type options: dict :return: the (potentially) fixed options :rtype: dict
[ "Fixes", "the", "options", "if", "necessary", ".", "I", ".", "e", ".", "it", "adds", "all", "required", "elements", "to", "the", "dictionary", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/control.py#L70-L87
fracpete/python-weka-wrapper3
python/weka/flow/control.py
ActorHandler.to_dict
def to_dict(self): """ Returns a dictionary that represents this object, to be used for JSONification. :return: the object dictionary :rtype: dict """ result = super(ActorHandler, self).to_dict() result["type"] = "ActorHandler" del result["config"]["actors"] result["actors"] = [] for actor in self.actors: result["actors"].append(actor.to_dict()) return result
python
def to_dict(self): """ Returns a dictionary that represents this object, to be used for JSONification. :return: the object dictionary :rtype: dict """ result = super(ActorHandler, self).to_dict() result["type"] = "ActorHandler" del result["config"]["actors"] result["actors"] = [] for actor in self.actors: result["actors"].append(actor.to_dict()) return result
[ "def", "to_dict", "(", "self", ")", ":", "result", "=", "super", "(", "ActorHandler", ",", "self", ")", ".", "to_dict", "(", ")", "result", "[", "\"type\"", "]", "=", "\"ActorHandler\"", "del", "result", "[", "\"config\"", "]", "[", "\"actors\"", "]", "result", "[", "\"actors\"", "]", "=", "[", "]", "for", "actor", "in", "self", ".", "actors", ":", "result", "[", "\"actors\"", "]", ".", "append", "(", "actor", ".", "to_dict", "(", ")", ")", "return", "result" ]
Returns a dictionary that represents this object, to be used for JSONification. :return: the object dictionary :rtype: dict
[ "Returns", "a", "dictionary", "that", "represents", "this", "object", "to", "be", "used", "for", "JSONification", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/control.py#L89-L102
fracpete/python-weka-wrapper3
python/weka/flow/control.py
ActorHandler.from_dict
def from_dict(cls, d): """ Restores an object state from a dictionary, used in de-JSONification. :param d: the object dictionary :type d: dict :return: the object :rtype: object """ result = super(ActorHandler, cls).from_dict(d) if "actors" in d: l = d["actors"] for e in l: if u"type" in e: typestr = e[u"type"] else: typestr = e["type"] result.actors.append(classes.get_dict_handler(typestr)(e)) return result
python
def from_dict(cls, d): """ Restores an object state from a dictionary, used in de-JSONification. :param d: the object dictionary :type d: dict :return: the object :rtype: object """ result = super(ActorHandler, cls).from_dict(d) if "actors" in d: l = d["actors"] for e in l: if u"type" in e: typestr = e[u"type"] else: typestr = e["type"] result.actors.append(classes.get_dict_handler(typestr)(e)) return result
[ "def", "from_dict", "(", "cls", ",", "d", ")", ":", "result", "=", "super", "(", "ActorHandler", ",", "cls", ")", ".", "from_dict", "(", "d", ")", "if", "\"actors\"", "in", "d", ":", "l", "=", "d", "[", "\"actors\"", "]", "for", "e", "in", "l", ":", "if", "u\"type\"", "in", "e", ":", "typestr", "=", "e", "[", "u\"type\"", "]", "else", ":", "typestr", "=", "e", "[", "\"type\"", "]", "result", ".", "actors", ".", "append", "(", "classes", ".", "get_dict_handler", "(", "typestr", ")", "(", "e", ")", ")", "return", "result" ]
Restores an object state from a dictionary, used in de-JSONification. :param d: the object dictionary :type d: dict :return: the object :rtype: object
[ "Restores", "an", "object", "state", "from", "a", "dictionary", "used", "in", "de", "-", "JSONification", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/control.py#L105-L123
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): """ 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
[ "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", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/control.py#L139-L149
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): """ 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
[ "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", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/control.py#L152-L163
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): """ 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
[ "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", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/control.py#L166-L178
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): """ 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
[ "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", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/control.py#L181-L193
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): """ 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
[ "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", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/control.py#L195-L209
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): """ 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
[ "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", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/control.py#L218-L247
fracpete/python-weka-wrapper3
python/weka/flow/control.py
ActorHandler.wrapup
def wrapup(self): """ Finishes up after execution finishes, does not remove any graphical output. """ for actor in self.actors: if actor.skip: continue actor.wrapup() super(ActorHandler, self).wrapup()
python
def wrapup(self): """ Finishes up after execution finishes, does not remove any graphical output. """ for actor in self.actors: if actor.skip: continue actor.wrapup() super(ActorHandler, self).wrapup()
[ "def", "wrapup", "(", "self", ")", ":", "for", "actor", "in", "self", ".", "actors", ":", "if", "actor", ".", "skip", ":", "continue", "actor", ".", "wrapup", "(", ")", "super", "(", "ActorHandler", ",", "self", ")", ".", "wrapup", "(", ")" ]
Finishes up after execution finishes, does not remove any graphical output.
[ "Finishes", "up", "after", "execution", "finishes", "does", "not", "remove", "any", "graphical", "output", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/control.py#L264-L272
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): """ Destructive finishing up after execution stopped. """ 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", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/control.py#L274-L282
fracpete/python-weka-wrapper3
python/weka/flow/control.py
SequentialDirector.stop_execution
def stop_execution(self): """ Triggers the stopping of the object. """ if not (self._stopping or self._stopped): for actor in self.owner.actors: actor.stop_execution() self._stopping = True
python
def stop_execution(self): """ Triggers the stopping of the object. """ if not (self._stopping or self._stopped): for actor in self.owner.actors: actor.stop_execution() self._stopping = True
[ "def", "stop_execution", "(", "self", ")", ":", "if", "not", "(", "self", ".", "_stopping", "or", "self", ".", "_stopped", ")", ":", "for", "actor", "in", "self", ".", "owner", ".", "actors", ":", "actor", ".", "stop_execution", "(", ")", "self", ".", "_stopping", "=", "True" ]
Triggers the stopping of the object.
[ "Triggers", "the", "stopping", "of", "the", "object", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/control.py#L472-L479
fracpete/python-weka-wrapper3
python/weka/flow/control.py
SequentialDirector.do_execute
def do_execute(self): """ Actual execution of the director. :return: None if successful, otherwise error message :rtype: str """ self._stopped = False self._stopping = False not_finished_actor = self.owner.first_active pending_actors = [] finished = False actor_result = None while not (self.is_stopping() or self.is_stopped()) and not finished: # determing starting point of next iteration if len(pending_actors) > 0: start_index = self.owner.index_of(pending_actors[-1].name) else: start_index = self.owner.index_of(not_finished_actor.name) not_finished_actor = None # iterate over actors token = None last_active = -1 if self.owner.active > 0: last_active = self.owner.last_active.index for i in range(start_index, last_active + 1): # do we have to stop the execution? if self.is_stopped() or self.is_stopping(): break curr = self.owner.actors[i] if curr.skip: continue # no token? get pending one or produce new one if token is None: if isinstance(curr, OutputProducer) and curr.has_output(): pending_actors.pop() else: actor_result = curr.execute() if actor_result is not None: self.owner.logger.error( curr.full_name + " generated following error output:\n" + actor_result) break if isinstance(curr, OutputProducer) and curr.has_output(): token = curr.output() else: token = None # still more to come? if isinstance(curr, OutputProducer) and curr.has_output(): pending_actors.append(curr) else: # process token curr.input = token actor_result = curr.execute() if actor_result is not None: self.owner.logger.error( curr.full_name + " generated following error output:\n" + actor_result) break # was a new token produced? if isinstance(curr, OutputProducer): if curr.has_output(): token = curr.output() else: token = None # still more to come? if curr.has_output(): pending_actors.append(curr) else: token = None # token from last actor generated? -> store if (i == self.owner.last_active.index) and (token is not None): if self._record_output: self._recorded_output.append(token) # no token produced, ignore rest of actors if isinstance(curr, OutputProducer) and (token is None): break # all actors finished? finished = (not_finished_actor is None) and (len(pending_actors) == 0) return actor_result
python
def do_execute(self): """ Actual execution of the director. :return: None if successful, otherwise error message :rtype: str """ self._stopped = False self._stopping = False not_finished_actor = self.owner.first_active pending_actors = [] finished = False actor_result = None while not (self.is_stopping() or self.is_stopped()) and not finished: # determing starting point of next iteration if len(pending_actors) > 0: start_index = self.owner.index_of(pending_actors[-1].name) else: start_index = self.owner.index_of(not_finished_actor.name) not_finished_actor = None # iterate over actors token = None last_active = -1 if self.owner.active > 0: last_active = self.owner.last_active.index for i in range(start_index, last_active + 1): # do we have to stop the execution? if self.is_stopped() or self.is_stopping(): break curr = self.owner.actors[i] if curr.skip: continue # no token? get pending one or produce new one if token is None: if isinstance(curr, OutputProducer) and curr.has_output(): pending_actors.pop() else: actor_result = curr.execute() if actor_result is not None: self.owner.logger.error( curr.full_name + " generated following error output:\n" + actor_result) break if isinstance(curr, OutputProducer) and curr.has_output(): token = curr.output() else: token = None # still more to come? if isinstance(curr, OutputProducer) and curr.has_output(): pending_actors.append(curr) else: # process token curr.input = token actor_result = curr.execute() if actor_result is not None: self.owner.logger.error( curr.full_name + " generated following error output:\n" + actor_result) break # was a new token produced? if isinstance(curr, OutputProducer): if curr.has_output(): token = curr.output() else: token = None # still more to come? if curr.has_output(): pending_actors.append(curr) else: token = None # token from last actor generated? -> store if (i == self.owner.last_active.index) and (token is not None): if self._record_output: self._recorded_output.append(token) # no token produced, ignore rest of actors if isinstance(curr, OutputProducer) and (token is None): break # all actors finished? finished = (not_finished_actor is None) and (len(pending_actors) == 0) return actor_result
[ "def", "do_execute", "(", "self", ")", ":", "self", ".", "_stopped", "=", "False", "self", ".", "_stopping", "=", "False", "not_finished_actor", "=", "self", ".", "owner", ".", "first_active", "pending_actors", "=", "[", "]", "finished", "=", "False", "actor_result", "=", "None", "while", "not", "(", "self", ".", "is_stopping", "(", ")", "or", "self", ".", "is_stopped", "(", ")", ")", "and", "not", "finished", ":", "# determing starting point of next iteration", "if", "len", "(", "pending_actors", ")", ">", "0", ":", "start_index", "=", "self", ".", "owner", ".", "index_of", "(", "pending_actors", "[", "-", "1", "]", ".", "name", ")", "else", ":", "start_index", "=", "self", ".", "owner", ".", "index_of", "(", "not_finished_actor", ".", "name", ")", "not_finished_actor", "=", "None", "# iterate over actors", "token", "=", "None", "last_active", "=", "-", "1", "if", "self", ".", "owner", ".", "active", ">", "0", ":", "last_active", "=", "self", ".", "owner", ".", "last_active", ".", "index", "for", "i", "in", "range", "(", "start_index", ",", "last_active", "+", "1", ")", ":", "# do we have to stop the execution?", "if", "self", ".", "is_stopped", "(", ")", "or", "self", ".", "is_stopping", "(", ")", ":", "break", "curr", "=", "self", ".", "owner", ".", "actors", "[", "i", "]", "if", "curr", ".", "skip", ":", "continue", "# no token? get pending one or produce new one", "if", "token", "is", "None", ":", "if", "isinstance", "(", "curr", ",", "OutputProducer", ")", "and", "curr", ".", "has_output", "(", ")", ":", "pending_actors", ".", "pop", "(", ")", "else", ":", "actor_result", "=", "curr", ".", "execute", "(", ")", "if", "actor_result", "is", "not", "None", ":", "self", ".", "owner", ".", "logger", ".", "error", "(", "curr", ".", "full_name", "+", "\" generated following error output:\\n\"", "+", "actor_result", ")", "break", "if", "isinstance", "(", "curr", ",", "OutputProducer", ")", "and", "curr", ".", "has_output", "(", ")", ":", "token", "=", "curr", ".", "output", "(", ")", "else", ":", "token", "=", "None", "# still more to come?", "if", "isinstance", "(", "curr", ",", "OutputProducer", ")", "and", "curr", ".", "has_output", "(", ")", ":", "pending_actors", ".", "append", "(", "curr", ")", "else", ":", "# process token", "curr", ".", "input", "=", "token", "actor_result", "=", "curr", ".", "execute", "(", ")", "if", "actor_result", "is", "not", "None", ":", "self", ".", "owner", ".", "logger", ".", "error", "(", "curr", ".", "full_name", "+", "\" generated following error output:\\n\"", "+", "actor_result", ")", "break", "# was a new token produced?", "if", "isinstance", "(", "curr", ",", "OutputProducer", ")", ":", "if", "curr", ".", "has_output", "(", ")", ":", "token", "=", "curr", ".", "output", "(", ")", "else", ":", "token", "=", "None", "# still more to come?", "if", "curr", ".", "has_output", "(", ")", ":", "pending_actors", ".", "append", "(", "curr", ")", "else", ":", "token", "=", "None", "# token from last actor generated? -> store", "if", "(", "i", "==", "self", ".", "owner", ".", "last_active", ".", "index", ")", "and", "(", "token", "is", "not", "None", ")", ":", "if", "self", ".", "_record_output", ":", "self", ".", "_recorded_output", ".", "append", "(", "token", ")", "# no token produced, ignore rest of actors", "if", "isinstance", "(", "curr", ",", "OutputProducer", ")", "and", "(", "token", "is", "None", ")", ":", "break", "# all actors finished?", "finished", "=", "(", "not_finished_actor", "is", "None", ")", "and", "(", "len", "(", "pending_actors", ")", "==", "0", ")", "return", "actor_result" ]
Actual execution of the director. :return: None if successful, otherwise error message :rtype: str
[ "Actual", "execution", "of", "the", "director", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/control.py#L540-L631
fracpete/python-weka-wrapper3
python/weka/flow/control.py
Flow.check_actors
def check_actors(self, actors): """ Performs checks on the actors that are to be used. Raises an exception if invalid setup. :param actors: the actors to check :type actors: list """ super(Flow, self).check_actors(actors) actor = self.first_active if (actor is not None) and not base.is_source(actor): raise Exception("First active actor is not a source: " + actor.full_name)
python
def check_actors(self, actors): """ Performs checks on the actors that are to be used. Raises an exception if invalid setup. :param actors: the actors to check :type actors: list """ super(Flow, self).check_actors(actors) actor = self.first_active if (actor is not None) and not base.is_source(actor): raise Exception("First active actor is not a source: " + actor.full_name)
[ "def", "check_actors", "(", "self", ",", "actors", ")", ":", "super", "(", "Flow", ",", "self", ")", ".", "check_actors", "(", "actors", ")", "actor", "=", "self", ".", "first_active", "if", "(", "actor", "is", "not", "None", ")", "and", "not", "base", ".", "is_source", "(", "actor", ")", ":", "raise", "Exception", "(", "\"First active actor is not a source: \"", "+", "actor", ".", "full_name", ")" ]
Performs checks on the actors that are to be used. Raises an exception if invalid setup. :param actors: the actors to check :type actors: list
[ "Performs", "checks", "on", "the", "actors", "that", "are", "to", "be", "used", ".", "Raises", "an", "exception", "if", "invalid", "setup", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/control.py#L672-L682
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): """ 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))
[ "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", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/control.py#L695-L706
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): """ 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
[ "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", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/control.py#L756-L766
fracpete/python-weka-wrapper3
python/weka/flow/control.py
Sequence.check_actors
def check_actors(self, actors): """ Performs checks on the actors that are to be used. Raises an exception if invalid setup. :param actors: the actors to check :type actors: list """ super(Sequence, self).check_actors(actors) actor = self.first_active if (actor is not None) and not isinstance(actor, InputConsumer): raise Exception("First active actor does not accept input: " + actor.full_name)
python
def check_actors(self, actors): """ Performs checks on the actors that are to be used. Raises an exception if invalid setup. :param actors: the actors to check :type actors: list """ super(Sequence, self).check_actors(actors) actor = self.first_active if (actor is not None) and not isinstance(actor, InputConsumer): raise Exception("First active actor does not accept input: " + actor.full_name)
[ "def", "check_actors", "(", "self", ",", "actors", ")", ":", "super", "(", "Sequence", ",", "self", ")", ".", "check_actors", "(", "actors", ")", "actor", "=", "self", ".", "first_active", "if", "(", "actor", "is", "not", "None", ")", "and", "not", "isinstance", "(", "actor", ",", "InputConsumer", ")", ":", "raise", "Exception", "(", "\"First active actor does not accept input: \"", "+", "actor", ".", "full_name", ")" ]
Performs checks on the actors that are to be used. Raises an exception if invalid setup. :param actors: the actors to check :type actors: list
[ "Performs", "checks", "on", "the", "actors", "that", "are", "to", "be", "used", ".", "Raises", "an", "exception", "if", "invalid", "setup", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/control.py#L768-L778
fracpete/python-weka-wrapper3
python/weka/flow/control.py
Sequence.do_execute
def do_execute(self): """ The actual execution of the actor. :return: None if successful, otherwise error message :rtype: str """ self.first_active.input = self.input result = self._director.execute() if result is None: self._output.append(self.input) return result
python
def do_execute(self): """ The actual execution of the actor. :return: None if successful, otherwise error message :rtype: str """ self.first_active.input = self.input result = self._director.execute() if result is None: self._output.append(self.input) return result
[ "def", "do_execute", "(", "self", ")", ":", "self", ".", "first_active", ".", "input", "=", "self", ".", "input", "result", "=", "self", ".", "_director", ".", "execute", "(", ")", "if", "result", "is", "None", ":", "self", ".", "_output", ".", "append", "(", "self", ".", "input", ")", "return", "result" ]
The actual execution of the actor. :return: None if successful, otherwise error message :rtype: str
[ "The", "actual", "execution", "of", "the", "actor", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/control.py#L780-L791
fracpete/python-weka-wrapper3
python/weka/flow/control.py
Tee.fix_config
def fix_config(self, options): """ Fixes the options, if necessary. I.e., it adds all required elements to the dictionary. :param options: the options to fix :type options: dict :return: the (potentially) fixed options :rtype: dict """ options = super(Tee, self).fix_config(options) opt = "condition" if opt not in options: options[opt] = "True" if opt not in self.help: self.help[opt] = "The (optional) condition for teeing off the tokens; uses the 'eval' method, "\ "ie the expression must evaluate to a boolean value; storage values placeholders "\ "'@{...}' get replaced with their string representations before evaluating the "\ "expression (string)." return options
python
def fix_config(self, options): """ Fixes the options, if necessary. I.e., it adds all required elements to the dictionary. :param options: the options to fix :type options: dict :return: the (potentially) fixed options :rtype: dict """ options = super(Tee, self).fix_config(options) opt = "condition" if opt not in options: options[opt] = "True" if opt not in self.help: self.help[opt] = "The (optional) condition for teeing off the tokens; uses the 'eval' method, "\ "ie the expression must evaluate to a boolean value; storage values placeholders "\ "'@{...}' get replaced with their string representations before evaluating the "\ "expression (string)." return options
[ "def", "fix_config", "(", "self", ",", "options", ")", ":", "options", "=", "super", "(", "Tee", ",", "self", ")", ".", "fix_config", "(", "options", ")", "opt", "=", "\"condition\"", "if", "opt", "not", "in", "options", ":", "options", "[", "opt", "]", "=", "\"True\"", "if", "opt", "not", "in", "self", ".", "help", ":", "self", ".", "help", "[", "opt", "]", "=", "\"The (optional) condition for teeing off the tokens; uses the 'eval' method, \"", "\"ie the expression must evaluate to a boolean value; storage values placeholders \"", "\"'@{...}' get replaced with their string representations before evaluating the \"", "\"expression (string).\"", "return", "options" ]
Fixes the options, if necessary. I.e., it adds all required elements to the dictionary. :param options: the options to fix :type options: dict :return: the (potentially) fixed options :rtype: dict
[ "Fixes", "the", "options", "if", "necessary", ".", "I", ".", "e", ".", "it", "adds", "all", "required", "elements", "to", "the", "dictionary", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/control.py#L834-L854
fracpete/python-weka-wrapper3
python/weka/flow/control.py
Tee.check_actors
def check_actors(self, actors): """ Performs checks on the actors that are to be used. Raises an exception if invalid setup. :param actors: the actors to check :type actors: list """ super(Tee, self).check_actors(actors) actor = self.first_active if actor is None: if self._requires_active_actors: raise Exception("No active actor!") elif not isinstance(actor, InputConsumer): raise Exception("First active actor does not accept input: " + actor.full_name)
python
def check_actors(self, actors): """ Performs checks on the actors that are to be used. Raises an exception if invalid setup. :param actors: the actors to check :type actors: list """ super(Tee, self).check_actors(actors) actor = self.first_active if actor is None: if self._requires_active_actors: raise Exception("No active actor!") elif not isinstance(actor, InputConsumer): raise Exception("First active actor does not accept input: " + actor.full_name)
[ "def", "check_actors", "(", "self", ",", "actors", ")", ":", "super", "(", "Tee", ",", "self", ")", ".", "check_actors", "(", "actors", ")", "actor", "=", "self", ".", "first_active", "if", "actor", "is", "None", ":", "if", "self", ".", "_requires_active_actors", ":", "raise", "Exception", "(", "\"No active actor!\"", ")", "elif", "not", "isinstance", "(", "actor", ",", "InputConsumer", ")", ":", "raise", "Exception", "(", "\"First active actor does not accept input: \"", "+", "actor", ".", "full_name", ")" ]
Performs checks on the actors that are to be used. Raises an exception if invalid setup. :param actors: the actors to check :type actors: list
[ "Performs", "checks", "on", "the", "actors", "that", "are", "to", "be", "used", ".", "Raises", "an", "exception", "if", "invalid", "setup", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/control.py#L868-L881
fracpete/python-weka-wrapper3
python/weka/flow/control.py
Tee.do_execute
def do_execute(self): """ The actual execution of the actor. :return: None if successful, otherwise error message :rtype: str """ result = None teeoff = True cond = self.storagehandler.expand(str(self.resolve_option("condition"))) if len(cond) > 0: teeoff = bool(eval(cond)) if teeoff: self.first_active.input = self.input result = self._director.execute() if result is None: self._output.append(self.input) return result
python
def do_execute(self): """ The actual execution of the actor. :return: None if successful, otherwise error message :rtype: str """ result = None teeoff = True cond = self.storagehandler.expand(str(self.resolve_option("condition"))) if len(cond) > 0: teeoff = bool(eval(cond)) if teeoff: self.first_active.input = self.input result = self._director.execute() if result is None: self._output.append(self.input) return result
[ "def", "do_execute", "(", "self", ")", ":", "result", "=", "None", "teeoff", "=", "True", "cond", "=", "self", ".", "storagehandler", ".", "expand", "(", "str", "(", "self", ".", "resolve_option", "(", "\"condition\"", ")", ")", ")", "if", "len", "(", "cond", ")", ">", "0", ":", "teeoff", "=", "bool", "(", "eval", "(", "cond", ")", ")", "if", "teeoff", ":", "self", ".", "first_active", ".", "input", "=", "self", ".", "input", "result", "=", "self", ".", "_director", ".", "execute", "(", ")", "if", "result", "is", "None", ":", "self", ".", "_output", ".", "append", "(", "self", ".", "input", ")", "return", "result" ]
The actual execution of the actor. :return: None if successful, otherwise error message :rtype: str
[ "The", "actual", "execution", "of", "the", "actor", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/control.py#L883-L900
fracpete/python-weka-wrapper3
python/weka/flow/control.py
Trigger.fix_config
def fix_config(self, options): """ Fixes the options, if necessary. I.e., it adds all required elements to the dictionary. :param options: the options to fix :type options: dict :return: the (potentially) fixed options :rtype: dict """ options = super(Trigger, self).fix_config(options) opt = "condition" if opt not in options: options[opt] = "True" if opt not in self.help: self.help[opt] = "The (optional) condition for teeing off the tokens; uses the 'eval' method, "\ "ie the expression must evaluate to a boolean value; storage values placeholders "\ "'@{...}' get replaced with their string representations before evaluating the "\ "expression (string)." return options
python
def fix_config(self, options): """ Fixes the options, if necessary. I.e., it adds all required elements to the dictionary. :param options: the options to fix :type options: dict :return: the (potentially) fixed options :rtype: dict """ options = super(Trigger, self).fix_config(options) opt = "condition" if opt not in options: options[opt] = "True" if opt not in self.help: self.help[opt] = "The (optional) condition for teeing off the tokens; uses the 'eval' method, "\ "ie the expression must evaluate to a boolean value; storage values placeholders "\ "'@{...}' get replaced with their string representations before evaluating the "\ "expression (string)." return options
[ "def", "fix_config", "(", "self", ",", "options", ")", ":", "options", "=", "super", "(", "Trigger", ",", "self", ")", ".", "fix_config", "(", "options", ")", "opt", "=", "\"condition\"", "if", "opt", "not", "in", "options", ":", "options", "[", "opt", "]", "=", "\"True\"", "if", "opt", "not", "in", "self", ".", "help", ":", "self", ".", "help", "[", "opt", "]", "=", "\"The (optional) condition for teeing off the tokens; uses the 'eval' method, \"", "\"ie the expression must evaluate to a boolean value; storage values placeholders \"", "\"'@{...}' get replaced with their string representations before evaluating the \"", "\"expression (string).\"", "return", "options" ]
Fixes the options, if necessary. I.e., it adds all required elements to the dictionary. :param options: the options to fix :type options: dict :return: the (potentially) fixed options :rtype: dict
[ "Fixes", "the", "options", "if", "necessary", ".", "I", ".", "e", ".", "it", "adds", "all", "required", "elements", "to", "the", "dictionary", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/control.py#L942-L962
fracpete/python-weka-wrapper3
python/weka/flow/control.py
BranchDirector.check_actors
def check_actors(self): """ Checks the actors of the owner. Raises an exception if invalid. """ actors = [] for actor in self.owner.actors: if actor.skip: continue actors.append(actor) if len(actors) == 0: return for actor in actors: if not isinstance(actor, InputConsumer): raise Exception("Actor does not accept any input: " + actor.full_name)
python
def check_actors(self): """ Checks the actors of the owner. Raises an exception if invalid. """ actors = [] for actor in self.owner.actors: if actor.skip: continue actors.append(actor) if len(actors) == 0: return for actor in actors: if not isinstance(actor, InputConsumer): raise Exception("Actor does not accept any input: " + actor.full_name)
[ "def", "check_actors", "(", "self", ")", ":", "actors", "=", "[", "]", "for", "actor", "in", "self", ".", "owner", ".", "actors", ":", "if", "actor", ".", "skip", ":", "continue", "actors", ".", "append", "(", "actor", ")", "if", "len", "(", "actors", ")", "==", "0", ":", "return", "for", "actor", "in", "actors", ":", "if", "not", "isinstance", "(", "actor", ",", "InputConsumer", ")", ":", "raise", "Exception", "(", "\"Actor does not accept any input: \"", "+", "actor", ".", "full_name", ")" ]
Checks the actors of the owner. Raises an exception if invalid.
[ "Checks", "the", "actors", "of", "the", "owner", ".", "Raises", "an", "exception", "if", "invalid", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/control.py#L1061-L1074
fracpete/python-weka-wrapper3
python/weka/flow/control.py
BranchDirector.do_execute
def do_execute(self): """ Actual execution of the director. :return: None if successful, otherwise error message :rtype: str """ result = None self._stopped = False self._stopping = False for actor in self.owner.actors: if self.is_stopping() or self.is_stopped(): break actor.input = self.owner.input result = actor.execute() if result is not None: break return result
python
def do_execute(self): """ Actual execution of the director. :return: None if successful, otherwise error message :rtype: str """ result = None self._stopped = False self._stopping = False for actor in self.owner.actors: if self.is_stopping() or self.is_stopped(): break actor.input = self.owner.input result = actor.execute() if result is not None: break return result
[ "def", "do_execute", "(", "self", ")", ":", "result", "=", "None", "self", ".", "_stopped", "=", "False", "self", ".", "_stopping", "=", "False", "for", "actor", "in", "self", ".", "owner", ".", "actors", ":", "if", "self", ".", "is_stopping", "(", ")", "or", "self", ".", "is_stopped", "(", ")", ":", "break", "actor", ".", "input", "=", "self", ".", "owner", ".", "input", "result", "=", "actor", ".", "execute", "(", ")", "if", "result", "is", "not", "None", ":", "break", "return", "result" ]
Actual execution of the director. :return: None if successful, otherwise error message :rtype: str
[ "Actual", "execution", "of", "the", "director", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/control.py#L1091-L1111
fracpete/python-weka-wrapper3
python/weka/flow/control.py
ContainerValuePicker.fix_config
def fix_config(self, options): """ Fixes the options, if necessary. I.e., it adds all required elements to the dictionary. :param options: the options to fix :type options: dict :return: the (potentially) fixed options :rtype: dict """ options = super(ContainerValuePicker, self).fix_config(options) opt = "value" if opt not in options: options[opt] = "Model" if opt not in self.help: self.help[opt] = "The name of the container value to pick from the container (string)." opt = "switch" if opt not in options: options[opt] = False if opt not in self.help: self.help[opt] = "Whether to switch the ouputs, i.e., forward the container to the sub-flow and the " \ + "container value to the following actor instead (bool)." return options
python
def fix_config(self, options): """ Fixes the options, if necessary. I.e., it adds all required elements to the dictionary. :param options: the options to fix :type options: dict :return: the (potentially) fixed options :rtype: dict """ options = super(ContainerValuePicker, self).fix_config(options) opt = "value" if opt not in options: options[opt] = "Model" if opt not in self.help: self.help[opt] = "The name of the container value to pick from the container (string)." opt = "switch" if opt not in options: options[opt] = False if opt not in self.help: self.help[opt] = "Whether to switch the ouputs, i.e., forward the container to the sub-flow and the " \ + "container value to the following actor instead (bool)." return options
[ "def", "fix_config", "(", "self", ",", "options", ")", ":", "options", "=", "super", "(", "ContainerValuePicker", ",", "self", ")", ".", "fix_config", "(", "options", ")", "opt", "=", "\"value\"", "if", "opt", "not", "in", "options", ":", "options", "[", "opt", "]", "=", "\"Model\"", "if", "opt", "not", "in", "self", ".", "help", ":", "self", ".", "help", "[", "opt", "]", "=", "\"The name of the container value to pick from the container (string).\"", "opt", "=", "\"switch\"", "if", "opt", "not", "in", "options", ":", "options", "[", "opt", "]", "=", "False", "if", "opt", "not", "in", "self", ".", "help", ":", "self", ".", "help", "[", "opt", "]", "=", "\"Whether to switch the ouputs, i.e., forward the container to the sub-flow and the \"", "+", "\"container value to the following actor instead (bool).\"", "return", "options" ]
Fixes the options, if necessary. I.e., it adds all required elements to the dictionary. :param options: the options to fix :type options: dict :return: the (potentially) fixed options :rtype: dict
[ "Fixes", "the", "options", "if", "necessary", ".", "I", ".", "e", ".", "it", "adds", "all", "required", "elements", "to", "the", "dictionary", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/control.py#L1186-L1210
fracpete/python-weka-wrapper3
python/weka/flow/control.py
ContainerValuePicker.do_execute
def do_execute(self): """ The actual execution of the actor. :return: None if successful, otherwise error message :rtype: str """ result = None cont = self.input.payload name = str(self.resolve_option("value")) value = cont.get(name) switch = bool(self.resolve_option("switch")) if switch: if self.first_active is not None: self.first_active.input = self.input result = self._director.execute() if result is None: self._output.append(Token(value)) else: if self.first_active is not None: self.first_active.input = Token(value) result = self._director.execute() if result is None: self._output.append(self.input) return result
python
def do_execute(self): """ The actual execution of the actor. :return: None if successful, otherwise error message :rtype: str """ result = None cont = self.input.payload name = str(self.resolve_option("value")) value = cont.get(name) switch = bool(self.resolve_option("switch")) if switch: if self.first_active is not None: self.first_active.input = self.input result = self._director.execute() if result is None: self._output.append(Token(value)) else: if self.first_active is not None: self.first_active.input = Token(value) result = self._director.execute() if result is None: self._output.append(self.input) return result
[ "def", "do_execute", "(", "self", ")", ":", "result", "=", "None", "cont", "=", "self", ".", "input", ".", "payload", "name", "=", "str", "(", "self", ".", "resolve_option", "(", "\"value\"", ")", ")", "value", "=", "cont", ".", "get", "(", "name", ")", "switch", "=", "bool", "(", "self", ".", "resolve_option", "(", "\"switch\"", ")", ")", "if", "switch", ":", "if", "self", ".", "first_active", "is", "not", "None", ":", "self", ".", "first_active", ".", "input", "=", "self", ".", "input", "result", "=", "self", ".", "_director", ".", "execute", "(", ")", "if", "result", "is", "None", ":", "self", ".", "_output", ".", "append", "(", "Token", "(", "value", ")", ")", "else", ":", "if", "self", ".", "first_active", "is", "not", "None", ":", "self", ".", "first_active", ".", "input", "=", "Token", "(", "value", ")", "result", "=", "self", ".", "_director", ".", "execute", "(", ")", "if", "result", "is", "None", ":", "self", ".", "_output", ".", "append", "(", "self", ".", "input", ")", "return", "result" ]
The actual execution of the actor. :return: None if successful, otherwise error message :rtype: str
[ "The", "actual", "execution", "of", "the", "actor", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/control.py#L1212-L1236
fracpete/python-weka-wrapper3
python/weka/flow/conversion.py
CommandlineToAny.fix_config
def fix_config(self, options): """ Fixes the options, if necessary. I.e., it adds all required elements to the dictionary. :param options: the options to fix :type options: dict :return: the (potentially) fixed options :rtype: dict """ options = super(CommandlineToAny, self).fix_config(options) opt = "wrapper" if opt not in options: options[opt] = "weka.core.classes.OptionHandler" if opt not in self.help: self.help[opt] = "The name of the wrapper class to use (string)." return options
python
def fix_config(self, options): """ Fixes the options, if necessary. I.e., it adds all required elements to the dictionary. :param options: the options to fix :type options: dict :return: the (potentially) fixed options :rtype: dict """ options = super(CommandlineToAny, self).fix_config(options) opt = "wrapper" if opt not in options: options[opt] = "weka.core.classes.OptionHandler" if opt not in self.help: self.help[opt] = "The name of the wrapper class to use (string)." return options
[ "def", "fix_config", "(", "self", ",", "options", ")", ":", "options", "=", "super", "(", "CommandlineToAny", ",", "self", ")", ".", "fix_config", "(", "options", ")", "opt", "=", "\"wrapper\"", "if", "opt", "not", "in", "options", ":", "options", "[", "opt", "]", "=", "\"weka.core.classes.OptionHandler\"", "if", "opt", "not", "in", "self", ".", "help", ":", "self", ".", "help", "[", "opt", "]", "=", "\"The name of the wrapper class to use (string).\"", "return", "options" ]
Fixes the options, if necessary. I.e., it adds all required elements to the dictionary. :param options: the options to fix :type options: dict :return: the (potentially) fixed options :rtype: dict
[ "Fixes", "the", "options", "if", "necessary", ".", "I", ".", "e", ".", "it", "adds", "all", "required", "elements", "to", "the", "dictionary", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/conversion.py#L188-L205
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): """ 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__)
[ "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", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/conversion.py#L207-L218
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): """ 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
[ "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", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/conversion.py#L220-L229
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): """ 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()
[ "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", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/plot/experiments.py#L28-L99
fracpete/python-weka-wrapper3
python/weka/plot/__init__.py
create_subsample
def create_subsample(data, percent, seed=1): """ Generates a subsample of the dataset. :param data: the data to create the subsample from :type data: Instances :param percent: the percentage (0-100) :type percent: float :param seed: the seed value to use :type seed: int """ if percent <= 0 or percent >= 100: return data data = Instances.copy_instances(data) data.randomize(Random(seed)) data = Instances.copy_instances(data, 0, int(round(data.num_instances * percent / 100.0))) return data
python
def create_subsample(data, percent, seed=1): """ Generates a subsample of the dataset. :param data: the data to create the subsample from :type data: Instances :param percent: the percentage (0-100) :type percent: float :param seed: the seed value to use :type seed: int """ if percent <= 0 or percent >= 100: return data data = Instances.copy_instances(data) data.randomize(Random(seed)) data = Instances.copy_instances(data, 0, int(round(data.num_instances * percent / 100.0))) return data
[ "def", "create_subsample", "(", "data", ",", "percent", ",", "seed", "=", "1", ")", ":", "if", "percent", "<=", "0", "or", "percent", ">=", "100", ":", "return", "data", "data", "=", "Instances", ".", "copy_instances", "(", "data", ")", "data", ".", "randomize", "(", "Random", "(", "seed", ")", ")", "data", "=", "Instances", ".", "copy_instances", "(", "data", ",", "0", ",", "int", "(", "round", "(", "data", ".", "num_instances", "*", "percent", "/", "100.0", ")", ")", ")", "return", "data" ]
Generates a subsample of the dataset. :param data: the data to create the subsample from :type data: Instances :param percent: the percentage (0-100) :type percent: float :param seed: the seed value to use :type seed: int
[ "Generates", "a", "subsample", "of", "the", "dataset", ".", ":", "param", "data", ":", "the", "data", "to", "create", "the", "subsample", "from", ":", "type", "data", ":", "Instances", ":", "param", "percent", ":", "the", "percentage", "(", "0", "-", "100", ")", ":", "type", "percent", ":", "float", ":", "param", "seed", ":", "the", "seed", "value", "to", "use", ":", "type", "seed", ":", "int" ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/plot/__init__.py#L45-L60
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): """ 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
[ "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", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/classifiers.py#L2061-L2114
fracpete/python-weka-wrapper3
python/weka/classifiers.py
Classifier.distributions_for_instances
def distributions_for_instances(self, data): """ Peforms predictions, returning the class distributions. :param data: the Instances to get the class distributions for :type data: Instances :return: the class distribution matrix, None if not a batch predictor :rtype: ndarray """ if self.is_batchpredictor: return typeconv.double_matrix_to_ndarray(self.__distributions(data.jobject)) else: return None
python
def distributions_for_instances(self, data): """ Peforms predictions, returning the class distributions. :param data: the Instances to get the class distributions for :type data: Instances :return: the class distribution matrix, None if not a batch predictor :rtype: ndarray """ if self.is_batchpredictor: return typeconv.double_matrix_to_ndarray(self.__distributions(data.jobject)) else: return None
[ "def", "distributions_for_instances", "(", "self", ",", "data", ")", ":", "if", "self", ".", "is_batchpredictor", ":", "return", "typeconv", ".", "double_matrix_to_ndarray", "(", "self", ".", "__distributions", "(", "data", ".", "jobject", ")", ")", "else", ":", "return", "None" ]
Peforms predictions, returning the class distributions. :param data: the Instances to get the class distributions for :type data: Instances :return: the class distribution matrix, None if not a batch predictor :rtype: ndarray
[ "Peforms", "predictions", "returning", "the", "class", "distributions", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/classifiers.py#L120-L132
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): """ 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)
[ "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", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/classifiers.py#L148-L156
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): """ 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)
[ "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", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/classifiers.py#L196-L207
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): """ 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)
[ "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", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/classifiers.py#L355-L366
fracpete/python-weka-wrapper3
python/weka/classifiers.py
GridSearch.x
def x(self): """ Returns a dictionary with all the current values for the X of the grid. Keys for the dictionary: property, min, max, step, base, expression Types: property=str, min=float, max=float, step=float, base=float, expression=str :return: the dictionary with the parameters :rtype: dict """ result = {} result["property"] = javabridge.call(self.jobject, "getXProperty", "()Ljava/lang/String;") result["min"] = javabridge.call(self.jobject, "getXMin", "()D") result["max"] = javabridge.call(self.jobject, "getXMax", "()D") result["step"] = javabridge.call(self.jobject, "getXStep", "()D") result["base"] = javabridge.call(self.jobject, "getXBase", "()D") result["expression"] = javabridge.call(self.jobject, "getXExpression", "()Ljava/lang/String;") return result
python
def x(self): """ Returns a dictionary with all the current values for the X of the grid. Keys for the dictionary: property, min, max, step, base, expression Types: property=str, min=float, max=float, step=float, base=float, expression=str :return: the dictionary with the parameters :rtype: dict """ result = {} result["property"] = javabridge.call(self.jobject, "getXProperty", "()Ljava/lang/String;") result["min"] = javabridge.call(self.jobject, "getXMin", "()D") result["max"] = javabridge.call(self.jobject, "getXMax", "()D") result["step"] = javabridge.call(self.jobject, "getXStep", "()D") result["base"] = javabridge.call(self.jobject, "getXBase", "()D") result["expression"] = javabridge.call(self.jobject, "getXExpression", "()Ljava/lang/String;") return result
[ "def", "x", "(", "self", ")", ":", "result", "=", "{", "}", "result", "[", "\"property\"", "]", "=", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"getXProperty\"", ",", "\"()Ljava/lang/String;\"", ")", "result", "[", "\"min\"", "]", "=", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"getXMin\"", ",", "\"()D\"", ")", "result", "[", "\"max\"", "]", "=", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"getXMax\"", ",", "\"()D\"", ")", "result", "[", "\"step\"", "]", "=", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"getXStep\"", ",", "\"()D\"", ")", "result", "[", "\"base\"", "]", "=", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"getXBase\"", ",", "\"()D\"", ")", "result", "[", "\"expression\"", "]", "=", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"getXExpression\"", ",", "\"()Ljava/lang/String;\"", ")", "return", "result" ]
Returns a dictionary with all the current values for the X of the grid. Keys for the dictionary: property, min, max, step, base, expression Types: property=str, min=float, max=float, step=float, base=float, expression=str :return: the dictionary with the parameters :rtype: dict
[ "Returns", "a", "dictionary", "with", "all", "the", "current", "values", "for", "the", "X", "of", "the", "grid", ".", "Keys", "for", "the", "dictionary", ":", "property", "min", "max", "step", "base", "expression", "Types", ":", "property", "=", "str", "min", "=", "float", "max", "=", "float", "step", "=", "float", "base", "=", "float", "expression", "=", "str" ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/classifiers.py#L369-L385
fracpete/python-weka-wrapper3
python/weka/classifiers.py
GridSearch.x
def x(self, d): """ Allows to configure the X of the grid with one method call. Keys for the dictionary: property, min, max, step, base, expression Types: property=str, min=float, max=float, step=float, base=float, expression=str :param d: the dictionary with the parameters :type d: dict """ if "property" in d: javabridge.call(self.jobject, "setXProperty", "(Ljava/lang/String;)V", d["property"]) if "min" in d: javabridge.call(self.jobject, "setXMin", "(D)V", d["min"]) if "max" in d: javabridge.call(self.jobject, "setXMax", "(D)V", d["max"]) if "step" in d: javabridge.call(self.jobject, "setXStep", "(D)V", d["step"]) if "base" in d: javabridge.call(self.jobject, "setXBase", "(D)V", d["base"]) if "expression" in d: javabridge.call(self.jobject, "setXExpression", "(Ljava/lang/String;)V", d["expression"])
python
def x(self, d): """ Allows to configure the X of the grid with one method call. Keys for the dictionary: property, min, max, step, base, expression Types: property=str, min=float, max=float, step=float, base=float, expression=str :param d: the dictionary with the parameters :type d: dict """ if "property" in d: javabridge.call(self.jobject, "setXProperty", "(Ljava/lang/String;)V", d["property"]) if "min" in d: javabridge.call(self.jobject, "setXMin", "(D)V", d["min"]) if "max" in d: javabridge.call(self.jobject, "setXMax", "(D)V", d["max"]) if "step" in d: javabridge.call(self.jobject, "setXStep", "(D)V", d["step"]) if "base" in d: javabridge.call(self.jobject, "setXBase", "(D)V", d["base"]) if "expression" in d: javabridge.call(self.jobject, "setXExpression", "(Ljava/lang/String;)V", d["expression"])
[ "def", "x", "(", "self", ",", "d", ")", ":", "if", "\"property\"", "in", "d", ":", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"setXProperty\"", ",", "\"(Ljava/lang/String;)V\"", ",", "d", "[", "\"property\"", "]", ")", "if", "\"min\"", "in", "d", ":", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"setXMin\"", ",", "\"(D)V\"", ",", "d", "[", "\"min\"", "]", ")", "if", "\"max\"", "in", "d", ":", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"setXMax\"", ",", "\"(D)V\"", ",", "d", "[", "\"max\"", "]", ")", "if", "\"step\"", "in", "d", ":", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"setXStep\"", ",", "\"(D)V\"", ",", "d", "[", "\"step\"", "]", ")", "if", "\"base\"", "in", "d", ":", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"setXBase\"", ",", "\"(D)V\"", ",", "d", "[", "\"base\"", "]", ")", "if", "\"expression\"", "in", "d", ":", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"setXExpression\"", ",", "\"(Ljava/lang/String;)V\"", ",", "d", "[", "\"expression\"", "]", ")" ]
Allows to configure the X of the grid with one method call. Keys for the dictionary: property, min, max, step, base, expression Types: property=str, min=float, max=float, step=float, base=float, expression=str :param d: the dictionary with the parameters :type d: dict
[ "Allows", "to", "configure", "the", "X", "of", "the", "grid", "with", "one", "method", "call", ".", "Keys", "for", "the", "dictionary", ":", "property", "min", "max", "step", "base", "expression", "Types", ":", "property", "=", "str", "min", "=", "float", "max", "=", "float", "step", "=", "float", "base", "=", "float", "expression", "=", "str" ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/classifiers.py#L388-L408
fracpete/python-weka-wrapper3
python/weka/classifiers.py
GridSearch.y
def y(self): """ Returns a dictionary with all the current values for the Y of the grid. Keys for the dictionary: property, min, max, step, base, expression Types: property=str, min=float, max=float, step=float, base=float, expression=str :return: the dictionary with the parameters :rtype: dict """ result = {} result["property"] = javabridge.call(self.jobject, "getYProperty", "()Ljava/lang/String;") result["min"] = javabridge.call(self.jobject, "getYMin", "()D") result["max"] = javabridge.call(self.jobject, "getYMax", "()D") result["step"] = javabridge.call(self.jobject, "getYStep", "()D") result["base"] = javabridge.call(self.jobject, "getYBase", "()D") result["expression"] = javabridge.call(self.jobject, "getYExpression", "()Ljava/lang/String;") return result
python
def y(self): """ Returns a dictionary with all the current values for the Y of the grid. Keys for the dictionary: property, min, max, step, base, expression Types: property=str, min=float, max=float, step=float, base=float, expression=str :return: the dictionary with the parameters :rtype: dict """ result = {} result["property"] = javabridge.call(self.jobject, "getYProperty", "()Ljava/lang/String;") result["min"] = javabridge.call(self.jobject, "getYMin", "()D") result["max"] = javabridge.call(self.jobject, "getYMax", "()D") result["step"] = javabridge.call(self.jobject, "getYStep", "()D") result["base"] = javabridge.call(self.jobject, "getYBase", "()D") result["expression"] = javabridge.call(self.jobject, "getYExpression", "()Ljava/lang/String;") return result
[ "def", "y", "(", "self", ")", ":", "result", "=", "{", "}", "result", "[", "\"property\"", "]", "=", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"getYProperty\"", ",", "\"()Ljava/lang/String;\"", ")", "result", "[", "\"min\"", "]", "=", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"getYMin\"", ",", "\"()D\"", ")", "result", "[", "\"max\"", "]", "=", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"getYMax\"", ",", "\"()D\"", ")", "result", "[", "\"step\"", "]", "=", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"getYStep\"", ",", "\"()D\"", ")", "result", "[", "\"base\"", "]", "=", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"getYBase\"", ",", "\"()D\"", ")", "result", "[", "\"expression\"", "]", "=", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"getYExpression\"", ",", "\"()Ljava/lang/String;\"", ")", "return", "result" ]
Returns a dictionary with all the current values for the Y of the grid. Keys for the dictionary: property, min, max, step, base, expression Types: property=str, min=float, max=float, step=float, base=float, expression=str :return: the dictionary with the parameters :rtype: dict
[ "Returns", "a", "dictionary", "with", "all", "the", "current", "values", "for", "the", "Y", "of", "the", "grid", ".", "Keys", "for", "the", "dictionary", ":", "property", "min", "max", "step", "base", "expression", "Types", ":", "property", "=", "str", "min", "=", "float", "max", "=", "float", "step", "=", "float", "base", "=", "float", "expression", "=", "str" ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/classifiers.py#L411-L427
fracpete/python-weka-wrapper3
python/weka/classifiers.py
GridSearch.y
def y(self, d): """ Allows to configure the Y of the grid with one method call. Keys for the dictionary: property, min, max, step, base, expression Types: property=str, min=float, max=float, step=float, base=float, expression=str :param d: the dictionary with the parameters :type d: dict """ if "property" in d: javabridge.call(self.jobject, "setYProperty", "(Ljava/lang/String;)V", d["property"]) if "min" in d: javabridge.call(self.jobject, "setYMin", "(D)V", d["min"]) if "max" in d: javabridge.call(self.jobject, "setYMax", "(D)V", d["max"]) if "step" in d: javabridge.call(self.jobject, "setYStep", "(D)V", d["step"]) if "base" in d: javabridge.call(self.jobject, "setYBase", "(D)V", d["base"]) if "expression" in d: javabridge.call(self.jobject, "setYExpression", "(Ljava/lang/String;)V", d["expression"])
python
def y(self, d): """ Allows to configure the Y of the grid with one method call. Keys for the dictionary: property, min, max, step, base, expression Types: property=str, min=float, max=float, step=float, base=float, expression=str :param d: the dictionary with the parameters :type d: dict """ if "property" in d: javabridge.call(self.jobject, "setYProperty", "(Ljava/lang/String;)V", d["property"]) if "min" in d: javabridge.call(self.jobject, "setYMin", "(D)V", d["min"]) if "max" in d: javabridge.call(self.jobject, "setYMax", "(D)V", d["max"]) if "step" in d: javabridge.call(self.jobject, "setYStep", "(D)V", d["step"]) if "base" in d: javabridge.call(self.jobject, "setYBase", "(D)V", d["base"]) if "expression" in d: javabridge.call(self.jobject, "setYExpression", "(Ljava/lang/String;)V", d["expression"])
[ "def", "y", "(", "self", ",", "d", ")", ":", "if", "\"property\"", "in", "d", ":", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"setYProperty\"", ",", "\"(Ljava/lang/String;)V\"", ",", "d", "[", "\"property\"", "]", ")", "if", "\"min\"", "in", "d", ":", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"setYMin\"", ",", "\"(D)V\"", ",", "d", "[", "\"min\"", "]", ")", "if", "\"max\"", "in", "d", ":", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"setYMax\"", ",", "\"(D)V\"", ",", "d", "[", "\"max\"", "]", ")", "if", "\"step\"", "in", "d", ":", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"setYStep\"", ",", "\"(D)V\"", ",", "d", "[", "\"step\"", "]", ")", "if", "\"base\"", "in", "d", ":", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"setYBase\"", ",", "\"(D)V\"", ",", "d", "[", "\"base\"", "]", ")", "if", "\"expression\"", "in", "d", ":", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"setYExpression\"", ",", "\"(Ljava/lang/String;)V\"", ",", "d", "[", "\"expression\"", "]", ")" ]
Allows to configure the Y of the grid with one method call. Keys for the dictionary: property, min, max, step, base, expression Types: property=str, min=float, max=float, step=float, base=float, expression=str :param d: the dictionary with the parameters :type d: dict
[ "Allows", "to", "configure", "the", "Y", "of", "the", "grid", "with", "one", "method", "call", ".", "Keys", "for", "the", "dictionary", ":", "property", "min", "max", "step", "base", "expression", "Types", ":", "property", "=", "str", "min", "=", "float", "max", "=", "float", "step", "=", "float", "base", "=", "float", "expression", "=", "str" ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/classifiers.py#L430-L450
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): """ 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
[ "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", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/classifiers.py#L573-L585
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): """ 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)
[ "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", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/classifiers.py#L588-L598
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): """ 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)
[ "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", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/classifiers.py#L666-L681
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): """ 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)
[ "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", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/classifiers.py#L727-L741
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): """ 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!")
[ "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", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/classifiers.py#L744-L756
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): """ 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))
[ "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", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/classifiers.py#L924-L936
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): """ 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)
[ "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", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/classifiers.py#L938-L956
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): """ 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)
[ "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", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/classifiers.py#L958-L970
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): """ 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)
[ "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", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/classifiers.py#L972-L986
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): """ 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)
[ "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", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/classifiers.py#L988-L1006
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): """ 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)
[ "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", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/classifiers.py#L1008-L1020
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): """ 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)
[ "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", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/classifiers.py#L1022-L1038
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): """ 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)
[ "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", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/classifiers.py#L1133-L1155
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): """ 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)
[ "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", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/classifiers.py#L1221-L1237
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): """ 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)
[ "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", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/classifiers.py#L1239-L1253
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): """ 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)
[ "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", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/classifiers.py#L1255-L1267
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): """ 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
[ "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", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/classifiers.py#L1905-L1925
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): """ 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)
[ "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", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/classifiers.py#L2001-L2012
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): """ 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)
[ "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", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/classifiers.py#L2014-L2025
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): """ 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)
[ "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", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/classifiers.py#L2027-L2040
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): """ 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)
[ "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", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/core/tokenizers.py#L76-L86
fracpete/python-weka-wrapper3
python/weka/datagenerators.py
main
def main(): """ Runs a datagenerator from the command-line. Calls JVM start/stop automatically. Use -h to see all options. """ parser = argparse.ArgumentParser( description='Executes a data generator from the command-line. Calls JVM start/stop automatically.') parser.add_argument("-j", metavar="classpath", dest="classpath", help="additional classpath, jars/directories") parser.add_argument("-X", metavar="heap", dest="heap", help="max heap size for jvm, e.g., 512m") parser.add_argument("datagenerator", help="data generator classname, e.g., " + "weka.datagenerators.classifiers.classification.LED24") parser.add_argument("option", nargs=argparse.REMAINDER, help="additional data generator options") parsed = parser.parse_args() jars = [] if parsed.classpath is not None: jars = parsed.classpath.split(os.pathsep) jvm.start(jars, max_heap_size=parsed.heap, packages=True) logger.debug("Commandline: " + join_options(sys.argv[1:])) try: generator = DataGenerator(classname=parsed.datagenerator) if len(parsed.option) > 0: generator.options = parsed.option DataGenerator.make_data(generator, parsed.option) except Exception as e: print(e) finally: jvm.stop()
python
def main(): """ Runs a datagenerator from the command-line. Calls JVM start/stop automatically. Use -h to see all options. """ parser = argparse.ArgumentParser( description='Executes a data generator from the command-line. Calls JVM start/stop automatically.') parser.add_argument("-j", metavar="classpath", dest="classpath", help="additional classpath, jars/directories") parser.add_argument("-X", metavar="heap", dest="heap", help="max heap size for jvm, e.g., 512m") parser.add_argument("datagenerator", help="data generator classname, e.g., " + "weka.datagenerators.classifiers.classification.LED24") parser.add_argument("option", nargs=argparse.REMAINDER, help="additional data generator options") parsed = parser.parse_args() jars = [] if parsed.classpath is not None: jars = parsed.classpath.split(os.pathsep) jvm.start(jars, max_heap_size=parsed.heap, packages=True) logger.debug("Commandline: " + join_options(sys.argv[1:])) try: generator = DataGenerator(classname=parsed.datagenerator) if len(parsed.option) > 0: generator.options = parsed.option DataGenerator.make_data(generator, parsed.option) except Exception as e: print(e) finally: jvm.stop()
[ "def", "main", "(", ")", ":", "parser", "=", "argparse", ".", "ArgumentParser", "(", "description", "=", "'Executes a data generator from the command-line. Calls JVM start/stop automatically.'", ")", "parser", ".", "add_argument", "(", "\"-j\"", ",", "metavar", "=", "\"classpath\"", ",", "dest", "=", "\"classpath\"", ",", "help", "=", "\"additional classpath, jars/directories\"", ")", "parser", ".", "add_argument", "(", "\"-X\"", ",", "metavar", "=", "\"heap\"", ",", "dest", "=", "\"heap\"", ",", "help", "=", "\"max heap size for jvm, e.g., 512m\"", ")", "parser", ".", "add_argument", "(", "\"datagenerator\"", ",", "help", "=", "\"data generator classname, e.g., \"", "+", "\"weka.datagenerators.classifiers.classification.LED24\"", ")", "parser", ".", "add_argument", "(", "\"option\"", ",", "nargs", "=", "argparse", ".", "REMAINDER", ",", "help", "=", "\"additional data generator options\"", ")", "parsed", "=", "parser", ".", "parse_args", "(", ")", "jars", "=", "[", "]", "if", "parsed", ".", "classpath", "is", "not", "None", ":", "jars", "=", "parsed", ".", "classpath", ".", "split", "(", "os", ".", "pathsep", ")", "jvm", ".", "start", "(", "jars", ",", "max_heap_size", "=", "parsed", ".", "heap", ",", "packages", "=", "True", ")", "logger", ".", "debug", "(", "\"Commandline: \"", "+", "join_options", "(", "sys", ".", "argv", "[", "1", ":", "]", ")", ")", "try", ":", "generator", "=", "DataGenerator", "(", "classname", "=", "parsed", ".", "datagenerator", ")", "if", "len", "(", "parsed", ".", "option", ")", ">", "0", ":", "generator", ".", "options", "=", "parsed", ".", "option", "DataGenerator", ".", "make_data", "(", "generator", ",", "parsed", ".", "option", ")", "except", "Exception", "as", "e", ":", "print", "(", "e", ")", "finally", ":", "jvm", ".", "stop", "(", ")" ]
Runs a datagenerator from the command-line. Calls JVM start/stop automatically. Use -h to see all options.
[ "Runs", "a", "datagenerator", "from", "the", "command", "-", "line", ".", "Calls", "JVM", "start", "/", "stop", "automatically", ".", "Use", "-", "h", "to", "see", "all", "options", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/datagenerators.py#L180-L209
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): """ 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)
[ "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", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/datagenerators.py#L50-L61
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): """ 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)
[ "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", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/datagenerators.py#L74-L85
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): """ 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)
[ "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", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/datagenerators.py#L116-L127
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): """ 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)
[ "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", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/datagenerators.py#L129-L140
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): """ 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()))
[ "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", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/datagenerators.py#L167-L177
fracpete/python-weka-wrapper3
python/weka/flow/source.py
FileSupplier.fix_config
def fix_config(self, options): """ Fixes the options, if necessary. I.e., it adds all required elements to the dictionary. :param options: the options to fix :type options: dict :return: the (potentially) fixed options :rtype: dict """ options = super(FileSupplier, self).fix_config(options) opt = "files" if opt not in options: options[opt] = [] if opt not in self.help: self.help[opt] = "The files to output (list of string)." return options
python
def fix_config(self, options): """ Fixes the options, if necessary. I.e., it adds all required elements to the dictionary. :param options: the options to fix :type options: dict :return: the (potentially) fixed options :rtype: dict """ options = super(FileSupplier, self).fix_config(options) opt = "files" if opt not in options: options[opt] = [] if opt not in self.help: self.help[opt] = "The files to output (list of string)." return options
[ "def", "fix_config", "(", "self", ",", "options", ")", ":", "options", "=", "super", "(", "FileSupplier", ",", "self", ")", ".", "fix_config", "(", "options", ")", "opt", "=", "\"files\"", "if", "opt", "not", "in", "options", ":", "options", "[", "opt", "]", "=", "[", "]", "if", "opt", "not", "in", "self", ".", "help", ":", "self", ".", "help", "[", "opt", "]", "=", "\"The files to output (list of string).\"", "return", "options" ]
Fixes the options, if necessary. I.e., it adds all required elements to the dictionary. :param options: the options to fix :type options: dict :return: the (potentially) fixed options :rtype: dict
[ "Fixes", "the", "options", "if", "necessary", ".", "I", ".", "e", ".", "it", "adds", "all", "required", "elements", "to", "the", "dictionary", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/source.py#L116-L133
fracpete/python-weka-wrapper3
python/weka/flow/source.py
FileSupplier.do_execute
def do_execute(self): """ The actual execution of the actor. :return: None if successful, otherwise error message :rtype: str """ for f in self.resolve_option("files"): self._output.append(Token(f)) return None
python
def do_execute(self): """ The actual execution of the actor. :return: None if successful, otherwise error message :rtype: str """ for f in self.resolve_option("files"): self._output.append(Token(f)) return None
[ "def", "do_execute", "(", "self", ")", ":", "for", "f", "in", "self", ".", "resolve_option", "(", "\"files\"", ")", ":", "self", ".", "_output", ".", "append", "(", "Token", "(", "f", ")", ")", "return", "None" ]
The actual execution of the actor. :return: None if successful, otherwise error message :rtype: str
[ "The", "actual", "execution", "of", "the", "actor", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/source.py#L135-L144
fracpete/python-weka-wrapper3
python/weka/flow/source.py
ListFiles.quickinfo
def quickinfo(self): """ Returns a short string describing some of the options of the actor. :return: the info, None if not available :rtype: str """ return "dir: " + str(self.config["dir"]) \ + ", files: " + str(self.config["list_files"]) \ + ", dirs: " + str(self.resolve_option("list_dirs")) \ + ", recursive: " + str(self.config["recursive"])
python
def quickinfo(self): """ Returns a short string describing some of the options of the actor. :return: the info, None if not available :rtype: str """ return "dir: " + str(self.config["dir"]) \ + ", files: " + str(self.config["list_files"]) \ + ", dirs: " + str(self.resolve_option("list_dirs")) \ + ", recursive: " + str(self.config["recursive"])
[ "def", "quickinfo", "(", "self", ")", ":", "return", "\"dir: \"", "+", "str", "(", "self", ".", "config", "[", "\"dir\"", "]", ")", "+", "\", files: \"", "+", "str", "(", "self", ".", "config", "[", "\"list_files\"", "]", ")", "+", "\", dirs: \"", "+", "str", "(", "self", ".", "resolve_option", "(", "\"list_dirs\"", ")", ")", "+", "\", recursive: \"", "+", "str", "(", "self", ".", "config", "[", "\"recursive\"", "]", ")" ]
Returns a short string describing some of the options of the actor. :return: the info, None if not available :rtype: str
[ "Returns", "a", "short", "string", "describing", "some", "of", "the", "options", "of", "the", "actor", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/source.py#L173-L183
fracpete/python-weka-wrapper3
python/weka/flow/source.py
ListFiles.fix_config
def fix_config(self, options): """ Fixes the options, if necessary. I.e., it adds all required elements to the dictionary. :param options: the options to fix :type options: dict :return: the (potentially) fixed options :rtype: dict """ options = super(ListFiles, self).fix_config(options) opt = "dir" if opt not in options: options[opt] = "." if opt not in self.help: self.help[opt] = "The directory to search (string)." opt = "recursive" if opt not in options: options[opt] = False if opt not in self.help: self.help[opt] = "Whether to search recursively (bool)." opt = "list_files" if opt not in options: options[opt] = True if opt not in self.help: self.help[opt] = "Whether to include files (bool)." opt = "list_dirs" if opt not in options: options[opt] = False if opt not in self.help: self.help[opt] = "Whether to include directories (bool)." opt = "regexp" if opt not in options: options[opt] = ".*" if opt not in self.help: self.help[opt] = "The regular expression that files/dirs must match (string)." return options
python
def fix_config(self, options): """ Fixes the options, if necessary. I.e., it adds all required elements to the dictionary. :param options: the options to fix :type options: dict :return: the (potentially) fixed options :rtype: dict """ options = super(ListFiles, self).fix_config(options) opt = "dir" if opt not in options: options[opt] = "." if opt not in self.help: self.help[opt] = "The directory to search (string)." opt = "recursive" if opt not in options: options[opt] = False if opt not in self.help: self.help[opt] = "Whether to search recursively (bool)." opt = "list_files" if opt not in options: options[opt] = True if opt not in self.help: self.help[opt] = "Whether to include files (bool)." opt = "list_dirs" if opt not in options: options[opt] = False if opt not in self.help: self.help[opt] = "Whether to include directories (bool)." opt = "regexp" if opt not in options: options[opt] = ".*" if opt not in self.help: self.help[opt] = "The regular expression that files/dirs must match (string)." return options
[ "def", "fix_config", "(", "self", ",", "options", ")", ":", "options", "=", "super", "(", "ListFiles", ",", "self", ")", ".", "fix_config", "(", "options", ")", "opt", "=", "\"dir\"", "if", "opt", "not", "in", "options", ":", "options", "[", "opt", "]", "=", "\".\"", "if", "opt", "not", "in", "self", ".", "help", ":", "self", ".", "help", "[", "opt", "]", "=", "\"The directory to search (string).\"", "opt", "=", "\"recursive\"", "if", "opt", "not", "in", "options", ":", "options", "[", "opt", "]", "=", "False", "if", "opt", "not", "in", "self", ".", "help", ":", "self", ".", "help", "[", "opt", "]", "=", "\"Whether to search recursively (bool).\"", "opt", "=", "\"list_files\"", "if", "opt", "not", "in", "options", ":", "options", "[", "opt", "]", "=", "True", "if", "opt", "not", "in", "self", ".", "help", ":", "self", ".", "help", "[", "opt", "]", "=", "\"Whether to include files (bool).\"", "opt", "=", "\"list_dirs\"", "if", "opt", "not", "in", "options", ":", "options", "[", "opt", "]", "=", "False", "if", "opt", "not", "in", "self", ".", "help", ":", "self", ".", "help", "[", "opt", "]", "=", "\"Whether to include directories (bool).\"", "opt", "=", "\"regexp\"", "if", "opt", "not", "in", "options", ":", "options", "[", "opt", "]", "=", "\".*\"", "if", "opt", "not", "in", "self", ".", "help", ":", "self", ".", "help", "[", "opt", "]", "=", "\"The regular expression that files/dirs must match (string).\"", "return", "options" ]
Fixes the options, if necessary. I.e., it adds all required elements to the dictionary. :param options: the options to fix :type options: dict :return: the (potentially) fixed options :rtype: dict
[ "Fixes", "the", "options", "if", "necessary", ".", "I", ".", "e", ".", "it", "adds", "all", "required", "elements", "to", "the", "dictionary", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/source.py#L185-L226
fracpete/python-weka-wrapper3
python/weka/flow/source.py
ListFiles._list
def _list(self, path, collected): """ Lists all the files/dirs in directory that match the pattern. :param path: the directory to search :type path: str :param collected: the files/dirs collected so far (full path) :type collected: list :return: None if successful, error otherwise :rtype: str """ list_files = self.resolve_option("list_files") list_dirs = self.resolve_option("list_dirs") recursive = self.resolve_option("recursive") spattern = str(self.resolve_option("regexp")) pattern = None if (spattern is not None) and (spattern != ".*"): pattern = re.compile(spattern) try: items = os.listdir(path) for item in items: fp = path + os.sep + item if list_files and os.path.isfile(fp): if (pattern is None) or pattern.match(item): collected.append(fp) if list_dirs and os.path.isdir(fp): if (pattern is None) or pattern.match(item): collected.append(fp) if recursive and os.path.isdir(fp): self._list(fp, collected) except Exception as e: return "Error listing '" + path + "': " + str(e)
python
def _list(self, path, collected): """ Lists all the files/dirs in directory that match the pattern. :param path: the directory to search :type path: str :param collected: the files/dirs collected so far (full path) :type collected: list :return: None if successful, error otherwise :rtype: str """ list_files = self.resolve_option("list_files") list_dirs = self.resolve_option("list_dirs") recursive = self.resolve_option("recursive") spattern = str(self.resolve_option("regexp")) pattern = None if (spattern is not None) and (spattern != ".*"): pattern = re.compile(spattern) try: items = os.listdir(path) for item in items: fp = path + os.sep + item if list_files and os.path.isfile(fp): if (pattern is None) or pattern.match(item): collected.append(fp) if list_dirs and os.path.isdir(fp): if (pattern is None) or pattern.match(item): collected.append(fp) if recursive and os.path.isdir(fp): self._list(fp, collected) except Exception as e: return "Error listing '" + path + "': " + str(e)
[ "def", "_list", "(", "self", ",", "path", ",", "collected", ")", ":", "list_files", "=", "self", ".", "resolve_option", "(", "\"list_files\"", ")", "list_dirs", "=", "self", ".", "resolve_option", "(", "\"list_dirs\"", ")", "recursive", "=", "self", ".", "resolve_option", "(", "\"recursive\"", ")", "spattern", "=", "str", "(", "self", ".", "resolve_option", "(", "\"regexp\"", ")", ")", "pattern", "=", "None", "if", "(", "spattern", "is", "not", "None", ")", "and", "(", "spattern", "!=", "\".*\"", ")", ":", "pattern", "=", "re", ".", "compile", "(", "spattern", ")", "try", ":", "items", "=", "os", ".", "listdir", "(", "path", ")", "for", "item", "in", "items", ":", "fp", "=", "path", "+", "os", ".", "sep", "+", "item", "if", "list_files", "and", "os", ".", "path", ".", "isfile", "(", "fp", ")", ":", "if", "(", "pattern", "is", "None", ")", "or", "pattern", ".", "match", "(", "item", ")", ":", "collected", ".", "append", "(", "fp", ")", "if", "list_dirs", "and", "os", ".", "path", ".", "isdir", "(", "fp", ")", ":", "if", "(", "pattern", "is", "None", ")", "or", "pattern", ".", "match", "(", "item", ")", ":", "collected", ".", "append", "(", "fp", ")", "if", "recursive", "and", "os", ".", "path", ".", "isdir", "(", "fp", ")", ":", "self", ".", "_list", "(", "fp", ",", "collected", ")", "except", "Exception", "as", "e", ":", "return", "\"Error listing '\"", "+", "path", "+", "\"': \"", "+", "str", "(", "e", ")" ]
Lists all the files/dirs in directory that match the pattern. :param path: the directory to search :type path: str :param collected: the files/dirs collected so far (full path) :type collected: list :return: None if successful, error otherwise :rtype: str
[ "Lists", "all", "the", "files", "/", "dirs", "in", "directory", "that", "match", "the", "pattern", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/source.py#L228-L260
fracpete/python-weka-wrapper3
python/weka/flow/source.py
ListFiles.do_execute
def do_execute(self): """ The actual execution of the actor. :return: None if successful, otherwise error message :rtype: str """ directory = str(self.resolve_option("dir")) if not os.path.exists(directory): return "Directory '" + directory + "' does not exist!" if not os.path.isdir(directory): return "Location '" + directory + "' is not a directory!" collected = [] result = self._list(directory, collected) if result is None: for c in collected: self._output.append(Token(c)) return result
python
def do_execute(self): """ The actual execution of the actor. :return: None if successful, otherwise error message :rtype: str """ directory = str(self.resolve_option("dir")) if not os.path.exists(directory): return "Directory '" + directory + "' does not exist!" if not os.path.isdir(directory): return "Location '" + directory + "' is not a directory!" collected = [] result = self._list(directory, collected) if result is None: for c in collected: self._output.append(Token(c)) return result
[ "def", "do_execute", "(", "self", ")", ":", "directory", "=", "str", "(", "self", ".", "resolve_option", "(", "\"dir\"", ")", ")", "if", "not", "os", ".", "path", ".", "exists", "(", "directory", ")", ":", "return", "\"Directory '\"", "+", "directory", "+", "\"' does not exist!\"", "if", "not", "os", ".", "path", ".", "isdir", "(", "directory", ")", ":", "return", "\"Location '\"", "+", "directory", "+", "\"' is not a directory!\"", "collected", "=", "[", "]", "result", "=", "self", ".", "_list", "(", "directory", ",", "collected", ")", "if", "result", "is", "None", ":", "for", "c", "in", "collected", ":", "self", ".", "_output", ".", "append", "(", "Token", "(", "c", ")", ")", "return", "result" ]
The actual execution of the actor. :return: None if successful, otherwise error message :rtype: str
[ "The", "actual", "execution", "of", "the", "actor", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/source.py#L262-L279
fracpete/python-weka-wrapper3
python/weka/flow/source.py
GetStorageValue.fix_config
def fix_config(self, options): """ Fixes the options, if necessary. I.e., it adds all required elements to the dictionary. :param options: the options to fix :type options: dict :return: the (potentially) fixed options :rtype: dict """ options = super(GetStorageValue, self).fix_config(options) opt = "storage_name" if opt not in options: options[opt] = "unknown" if opt not in self.help: self.help[opt] = "The name of the storage value to retrieve (string)." return options
python
def fix_config(self, options): """ Fixes the options, if necessary. I.e., it adds all required elements to the dictionary. :param options: the options to fix :type options: dict :return: the (potentially) fixed options :rtype: dict """ options = super(GetStorageValue, self).fix_config(options) opt = "storage_name" if opt not in options: options[opt] = "unknown" if opt not in self.help: self.help[opt] = "The name of the storage value to retrieve (string)." return options
[ "def", "fix_config", "(", "self", ",", "options", ")", ":", "options", "=", "super", "(", "GetStorageValue", ",", "self", ")", ".", "fix_config", "(", "options", ")", "opt", "=", "\"storage_name\"", "if", "opt", "not", "in", "options", ":", "options", "[", "opt", "]", "=", "\"unknown\"", "if", "opt", "not", "in", "self", ".", "help", ":", "self", ".", "help", "[", "opt", "]", "=", "\"The name of the storage value to retrieve (string).\"", "return", "options" ]
Fixes the options, if necessary. I.e., it adds all required elements to the dictionary. :param options: the options to fix :type options: dict :return: the (potentially) fixed options :rtype: dict
[ "Fixes", "the", "options", "if", "necessary", ".", "I", ".", "e", ".", "it", "adds", "all", "required", "elements", "to", "the", "dictionary", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/source.py#L317-L334
fracpete/python-weka-wrapper3
python/weka/flow/source.py
GetStorageValue.do_execute
def do_execute(self): """ The actual execution of the actor. :return: None if successful, otherwise error message :rtype: str """ if self.storagehandler is None: return "No storage handler available!" sname = str(self.resolve_option("storage_name")) if sname not in self.storagehandler.storage: return "No storage item called '" + sname + "' present!" self._output.append(Token(self.storagehandler.storage[sname])) return None
python
def do_execute(self): """ The actual execution of the actor. :return: None if successful, otherwise error message :rtype: str """ if self.storagehandler is None: return "No storage handler available!" sname = str(self.resolve_option("storage_name")) if sname not in self.storagehandler.storage: return "No storage item called '" + sname + "' present!" self._output.append(Token(self.storagehandler.storage[sname])) return None
[ "def", "do_execute", "(", "self", ")", ":", "if", "self", ".", "storagehandler", "is", "None", ":", "return", "\"No storage handler available!\"", "sname", "=", "str", "(", "self", ".", "resolve_option", "(", "\"storage_name\"", ")", ")", "if", "sname", "not", "in", "self", ".", "storagehandler", ".", "storage", ":", "return", "\"No storage item called '\"", "+", "sname", "+", "\"' present!\"", "self", ".", "_output", ".", "append", "(", "Token", "(", "self", ".", "storagehandler", ".", "storage", "[", "sname", "]", ")", ")", "return", "None" ]
The actual execution of the actor. :return: None if successful, otherwise error message :rtype: str
[ "The", "actual", "execution", "of", "the", "actor", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/source.py#L336-L349
fracpete/python-weka-wrapper3
python/weka/flow/source.py
ForLoop.fix_config
def fix_config(self, options): """ Fixes the options, if necessary. I.e., it adds all required elements to the dictionary. :param options: the options to fix :type options: dict :return: the (potentially) fixed options :rtype: dict """ options = super(ForLoop, self).fix_config(options) opt = "min" if opt not in options: options[opt] = 1 if opt not in self.help: self.help[opt] = "The minimum for the loop (included, int)." opt = "max" if opt not in options: options[opt] = 10 if opt not in self.help: self.help[opt] = "The maximum for the loop (included, int)." opt = "step" if opt not in options: options[opt] = 1 if opt not in self.help: self.help[opt] = "The step size (int)." return options
python
def fix_config(self, options): """ Fixes the options, if necessary. I.e., it adds all required elements to the dictionary. :param options: the options to fix :type options: dict :return: the (potentially) fixed options :rtype: dict """ options = super(ForLoop, self).fix_config(options) opt = "min" if opt not in options: options[opt] = 1 if opt not in self.help: self.help[opt] = "The minimum for the loop (included, int)." opt = "max" if opt not in options: options[opt] = 10 if opt not in self.help: self.help[opt] = "The maximum for the loop (included, int)." opt = "step" if opt not in options: options[opt] = 1 if opt not in self.help: self.help[opt] = "The step size (int)." return options
[ "def", "fix_config", "(", "self", ",", "options", ")", ":", "options", "=", "super", "(", "ForLoop", ",", "self", ")", ".", "fix_config", "(", "options", ")", "opt", "=", "\"min\"", "if", "opt", "not", "in", "options", ":", "options", "[", "opt", "]", "=", "1", "if", "opt", "not", "in", "self", ".", "help", ":", "self", ".", "help", "[", "opt", "]", "=", "\"The minimum for the loop (included, int).\"", "opt", "=", "\"max\"", "if", "opt", "not", "in", "options", ":", "options", "[", "opt", "]", "=", "10", "if", "opt", "not", "in", "self", ".", "help", ":", "self", ".", "help", "[", "opt", "]", "=", "\"The maximum for the loop (included, int).\"", "opt", "=", "\"step\"", "if", "opt", "not", "in", "options", ":", "options", "[", "opt", "]", "=", "1", "if", "opt", "not", "in", "self", ".", "help", ":", "self", ".", "help", "[", "opt", "]", "=", "\"The step size (int).\"", "return", "options" ]
Fixes the options, if necessary. I.e., it adds all required elements to the dictionary. :param options: the options to fix :type options: dict :return: the (potentially) fixed options :rtype: dict
[ "Fixes", "the", "options", "if", "necessary", ".", "I", ".", "e", ".", "it", "adds", "all", "required", "elements", "to", "the", "dictionary", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/source.py#L389-L418
fracpete/python-weka-wrapper3
python/weka/flow/source.py
ForLoop.do_execute
def do_execute(self): """ The actual execution of the actor. :return: None if successful, otherwise error message :rtype: str """ for i in range( int(self.resolve_option("min")), int(self.resolve_option("max")) + 1, int(self.resolve_option("step"))): self._output.append(Token(i)) return None
python
def do_execute(self): """ The actual execution of the actor. :return: None if successful, otherwise error message :rtype: str """ for i in range( int(self.resolve_option("min")), int(self.resolve_option("max")) + 1, int(self.resolve_option("step"))): self._output.append(Token(i)) return None
[ "def", "do_execute", "(", "self", ")", ":", "for", "i", "in", "range", "(", "int", "(", "self", ".", "resolve_option", "(", "\"min\"", ")", ")", ",", "int", "(", "self", ".", "resolve_option", "(", "\"max\"", ")", ")", "+", "1", ",", "int", "(", "self", ".", "resolve_option", "(", "\"step\"", ")", ")", ")", ":", "self", ".", "_output", ".", "append", "(", "Token", "(", "i", ")", ")", "return", "None" ]
The actual execution of the actor. :return: None if successful, otherwise error message :rtype: str
[ "The", "actual", "execution", "of", "the", "actor", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/source.py#L420-L432
fracpete/python-weka-wrapper3
python/weka/flow/source.py
LoadDatabase.fix_config
def fix_config(self, options): """ Fixes the options, if necessary. I.e., it adds all required elements to the dictionary. :param options: the options to fix :type options: dict :return: the (potentially) fixed options :rtype: dict """ opt = "db_url" if opt not in options: options[opt] = "jdbc:mysql://somehost:3306/somedatabase" if opt not in self.help: self.help[opt] = "The JDBC database URL to connect to (str)." opt = "user" if opt not in options: options[opt] = "user" if opt not in self.help: self.help[opt] = "The database user to use for connecting (str)." opt = "password" if opt not in options: options[opt] = "secret" if opt not in self.help: self.help[opt] = "The password for the database user (str)." opt = "query" if opt not in options: options[opt] = "SELECT * FROM table" if opt not in self.help: self.help[opt] = "The SQL query for generating the dataset (str)." opt = "sparse" if opt not in options: options[opt] = False if opt not in self.help: self.help[opt] = "Whether to return the data in sparse format (bool)." opt = "custom_props" if opt not in options: options[opt] = "" if opt not in self.help: self.help[opt] = "Custom properties filename (str)." return super(LoadDatabase, self).fix_config(options)
python
def fix_config(self, options): """ Fixes the options, if necessary. I.e., it adds all required elements to the dictionary. :param options: the options to fix :type options: dict :return: the (potentially) fixed options :rtype: dict """ opt = "db_url" if opt not in options: options[opt] = "jdbc:mysql://somehost:3306/somedatabase" if opt not in self.help: self.help[opt] = "The JDBC database URL to connect to (str)." opt = "user" if opt not in options: options[opt] = "user" if opt not in self.help: self.help[opt] = "The database user to use for connecting (str)." opt = "password" if opt not in options: options[opt] = "secret" if opt not in self.help: self.help[opt] = "The password for the database user (str)." opt = "query" if opt not in options: options[opt] = "SELECT * FROM table" if opt not in self.help: self.help[opt] = "The SQL query for generating the dataset (str)." opt = "sparse" if opt not in options: options[opt] = False if opt not in self.help: self.help[opt] = "Whether to return the data in sparse format (bool)." opt = "custom_props" if opt not in options: options[opt] = "" if opt not in self.help: self.help[opt] = "Custom properties filename (str)." return super(LoadDatabase, self).fix_config(options)
[ "def", "fix_config", "(", "self", ",", "options", ")", ":", "opt", "=", "\"db_url\"", "if", "opt", "not", "in", "options", ":", "options", "[", "opt", "]", "=", "\"jdbc:mysql://somehost:3306/somedatabase\"", "if", "opt", "not", "in", "self", ".", "help", ":", "self", ".", "help", "[", "opt", "]", "=", "\"The JDBC database URL to connect to (str).\"", "opt", "=", "\"user\"", "if", "opt", "not", "in", "options", ":", "options", "[", "opt", "]", "=", "\"user\"", "if", "opt", "not", "in", "self", ".", "help", ":", "self", ".", "help", "[", "opt", "]", "=", "\"The database user to use for connecting (str).\"", "opt", "=", "\"password\"", "if", "opt", "not", "in", "options", ":", "options", "[", "opt", "]", "=", "\"secret\"", "if", "opt", "not", "in", "self", ".", "help", ":", "self", ".", "help", "[", "opt", "]", "=", "\"The password for the database user (str).\"", "opt", "=", "\"query\"", "if", "opt", "not", "in", "options", ":", "options", "[", "opt", "]", "=", "\"SELECT * FROM table\"", "if", "opt", "not", "in", "self", ".", "help", ":", "self", ".", "help", "[", "opt", "]", "=", "\"The SQL query for generating the dataset (str).\"", "opt", "=", "\"sparse\"", "if", "opt", "not", "in", "options", ":", "options", "[", "opt", "]", "=", "False", "if", "opt", "not", "in", "self", ".", "help", ":", "self", ".", "help", "[", "opt", "]", "=", "\"Whether to return the data in sparse format (bool).\"", "opt", "=", "\"custom_props\"", "if", "opt", "not", "in", "options", ":", "options", "[", "opt", "]", "=", "\"\"", "if", "opt", "not", "in", "self", ".", "help", ":", "self", ".", "help", "[", "opt", "]", "=", "\"Custom properties filename (str).\"", "return", "super", "(", "LoadDatabase", ",", "self", ")", ".", "fix_config", "(", "options", ")" ]
Fixes the options, if necessary. I.e., it adds all required elements to the dictionary. :param options: the options to fix :type options: dict :return: the (potentially) fixed options :rtype: dict
[ "Fixes", "the", "options", "if", "necessary", ".", "I", ".", "e", ".", "it", "adds", "all", "required", "elements", "to", "the", "dictionary", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/source.py#L473-L518
fracpete/python-weka-wrapper3
python/weka/flow/source.py
LoadDatabase.do_execute
def do_execute(self): """ The actual execution of the actor. :return: None if successful, otherwise error message :rtype: str """ iquery = InstanceQuery() iquery.db_url = str(self.resolve_option("db_url")) iquery.user = str(self.resolve_option("user")) iquery.password = str(self.resolve_option("password")) props = str(self.resolve_option("custom_props")) if (len(props) > 0) and os.path.isfile(props): iquery.custom_properties = props iquery.query = str(self.resolve_option("query")) data = iquery.retrieve_instances() self._output.append(Token(data)) return None
python
def do_execute(self): """ The actual execution of the actor. :return: None if successful, otherwise error message :rtype: str """ iquery = InstanceQuery() iquery.db_url = str(self.resolve_option("db_url")) iquery.user = str(self.resolve_option("user")) iquery.password = str(self.resolve_option("password")) props = str(self.resolve_option("custom_props")) if (len(props) > 0) and os.path.isfile(props): iquery.custom_properties = props iquery.query = str(self.resolve_option("query")) data = iquery.retrieve_instances() self._output.append(Token(data)) return None
[ "def", "do_execute", "(", "self", ")", ":", "iquery", "=", "InstanceQuery", "(", ")", "iquery", ".", "db_url", "=", "str", "(", "self", ".", "resolve_option", "(", "\"db_url\"", ")", ")", "iquery", ".", "user", "=", "str", "(", "self", ".", "resolve_option", "(", "\"user\"", ")", ")", "iquery", ".", "password", "=", "str", "(", "self", ".", "resolve_option", "(", "\"password\"", ")", ")", "props", "=", "str", "(", "self", ".", "resolve_option", "(", "\"custom_props\"", ")", ")", "if", "(", "len", "(", "props", ")", ">", "0", ")", "and", "os", ".", "path", ".", "isfile", "(", "props", ")", ":", "iquery", ".", "custom_properties", "=", "props", "iquery", ".", "query", "=", "str", "(", "self", ".", "resolve_option", "(", "\"query\"", ")", ")", "data", "=", "iquery", ".", "retrieve_instances", "(", ")", "self", ".", "_output", ".", "append", "(", "Token", "(", "data", ")", ")", "return", "None" ]
The actual execution of the actor. :return: None if successful, otherwise error message :rtype: str
[ "The", "actual", "execution", "of", "the", "actor", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/source.py#L520-L537
fracpete/python-weka-wrapper3
python/weka/flow/source.py
DataGenerator.fix_config
def fix_config(self, options): """ Fixes the options, if necessary. I.e., it adds all required elements to the dictionary. :param options: the options to fix :type options: dict :return: the (potentially) fixed options :rtype: dict """ opt = "setup" if opt not in options: options[opt] = datagen.DataGenerator(classname="weka.datagenerators.classifiers.classification.Agrawal") if opt not in self.help: self.help[opt] = "The data generator to use (DataGenerator)." opt = "incremental" if opt not in options: options[opt] = False if opt not in self.help: self.help[opt] = "Whether to output the data incrementally, in case the generator supports that (bool)." return super(DataGenerator, self).fix_config(options)
python
def fix_config(self, options): """ Fixes the options, if necessary. I.e., it adds all required elements to the dictionary. :param options: the options to fix :type options: dict :return: the (potentially) fixed options :rtype: dict """ opt = "setup" if opt not in options: options[opt] = datagen.DataGenerator(classname="weka.datagenerators.classifiers.classification.Agrawal") if opt not in self.help: self.help[opt] = "The data generator to use (DataGenerator)." opt = "incremental" if opt not in options: options[opt] = False if opt not in self.help: self.help[opt] = "Whether to output the data incrementally, in case the generator supports that (bool)." return super(DataGenerator, self).fix_config(options)
[ "def", "fix_config", "(", "self", ",", "options", ")", ":", "opt", "=", "\"setup\"", "if", "opt", "not", "in", "options", ":", "options", "[", "opt", "]", "=", "datagen", ".", "DataGenerator", "(", "classname", "=", "\"weka.datagenerators.classifiers.classification.Agrawal\"", ")", "if", "opt", "not", "in", "self", ".", "help", ":", "self", ".", "help", "[", "opt", "]", "=", "\"The data generator to use (DataGenerator).\"", "opt", "=", "\"incremental\"", "if", "opt", "not", "in", "options", ":", "options", "[", "opt", "]", "=", "False", "if", "opt", "not", "in", "self", ".", "help", ":", "self", ".", "help", "[", "opt", "]", "=", "\"Whether to output the data incrementally, in case the generator supports that (bool).\"", "return", "super", "(", "DataGenerator", ",", "self", ")", ".", "fix_config", "(", "options", ")" ]
Fixes the options, if necessary. I.e., it adds all required elements to the dictionary. :param options: the options to fix :type options: dict :return: the (potentially) fixed options :rtype: dict
[ "Fixes", "the", "options", "if", "necessary", ".", "I", ".", "e", ".", "it", "adds", "all", "required", "elements", "to", "the", "dictionary", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/source.py#L575-L596
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): """ 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)
[ "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", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/source.py#L598-L611
fracpete/python-weka-wrapper3
python/weka/flow/source.py
DataGenerator.from_config
def from_config(self, k, v): """ Hook method that allows converting values from the dictionary. :param k: the key in the dictionary :type k: str :param v: the value :type v: object :return: the potentially parsed value :rtype: object """ if k == "setup": return from_commandline(v, classname=to_commandline(datagen.DataGenerator())) return super(DataGenerator, self).from_config(k, v)
python
def from_config(self, k, v): """ Hook method that allows converting values from the dictionary. :param k: the key in the dictionary :type k: str :param v: the value :type v: object :return: the potentially parsed value :rtype: object """ if k == "setup": return from_commandline(v, classname=to_commandline(datagen.DataGenerator())) return super(DataGenerator, self).from_config(k, v)
[ "def", "from_config", "(", "self", ",", "k", ",", "v", ")", ":", "if", "k", "==", "\"setup\"", ":", "return", "from_commandline", "(", "v", ",", "classname", "=", "to_commandline", "(", "datagen", ".", "DataGenerator", "(", ")", ")", ")", "return", "super", "(", "DataGenerator", ",", "self", ")", ".", "from_config", "(", "k", ",", "v", ")" ]
Hook method that allows converting values from the dictionary. :param k: the key in the dictionary :type k: str :param v: the value :type v: object :return: the potentially parsed value :rtype: object
[ "Hook", "method", "that", "allows", "converting", "values", "from", "the", "dictionary", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/source.py#L613-L626
fracpete/python-weka-wrapper3
python/weka/flow/source.py
DataGenerator.do_execute
def do_execute(self): """ The actual execution of the actor. :return: None if successful, otherwise error message :rtype: str """ generator = datagen.DataGenerator.make_copy(self.resolve_option("setup")) generator.dataset_format = generator.define_data_format() if bool(self.resolve_option("incremental")) and generator.single_mode_flag: for i in range(generator.num_examples_act): self._output.append(Token(generator.generate_example())) else: data = generator.generate_examples() self._output.append(Token(data)) return None
python
def do_execute(self): """ The actual execution of the actor. :return: None if successful, otherwise error message :rtype: str """ generator = datagen.DataGenerator.make_copy(self.resolve_option("setup")) generator.dataset_format = generator.define_data_format() if bool(self.resolve_option("incremental")) and generator.single_mode_flag: for i in range(generator.num_examples_act): self._output.append(Token(generator.generate_example())) else: data = generator.generate_examples() self._output.append(Token(data)) return None
[ "def", "do_execute", "(", "self", ")", ":", "generator", "=", "datagen", ".", "DataGenerator", ".", "make_copy", "(", "self", ".", "resolve_option", "(", "\"setup\"", ")", ")", "generator", ".", "dataset_format", "=", "generator", ".", "define_data_format", "(", ")", "if", "bool", "(", "self", ".", "resolve_option", "(", "\"incremental\"", ")", ")", "and", "generator", ".", "single_mode_flag", ":", "for", "i", "in", "range", "(", "generator", ".", "num_examples_act", ")", ":", "self", ".", "_output", ".", "append", "(", "Token", "(", "generator", ".", "generate_example", "(", ")", ")", ")", "else", ":", "data", "=", "generator", ".", "generate_examples", "(", ")", "self", ".", "_output", ".", "append", "(", "Token", "(", "data", ")", ")", "return", "None" ]
The actual execution of the actor. :return: None if successful, otherwise error message :rtype: str
[ "The", "actual", "execution", "of", "the", "actor", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/source.py#L628-L643
fracpete/python-weka-wrapper3
python/weka/flow/source.py
CombineStorage.fix_config
def fix_config(self, options): """ Fixes the options, if necessary. I.e., it adds all required elements to the dictionary. :param options: the options to fix :type options: dict :return: the (potentially) fixed options :rtype: dict """ options = super(CombineStorage, self).fix_config(options) opt = "format" if opt not in options: options[opt] = "" if opt not in self.help: self.help[opt] = "The format to use for generating the combined string; use '@{blah}' for accessing "\ "storage item 'blah' (string)." return options
python
def fix_config(self, options): """ Fixes the options, if necessary. I.e., it adds all required elements to the dictionary. :param options: the options to fix :type options: dict :return: the (potentially) fixed options :rtype: dict """ options = super(CombineStorage, self).fix_config(options) opt = "format" if opt not in options: options[opt] = "" if opt not in self.help: self.help[opt] = "The format to use for generating the combined string; use '@{blah}' for accessing "\ "storage item 'blah' (string)." return options
[ "def", "fix_config", "(", "self", ",", "options", ")", ":", "options", "=", "super", "(", "CombineStorage", ",", "self", ")", ".", "fix_config", "(", "options", ")", "opt", "=", "\"format\"", "if", "opt", "not", "in", "options", ":", "options", "[", "opt", "]", "=", "\"\"", "if", "opt", "not", "in", "self", ".", "help", ":", "self", ".", "help", "[", "opt", "]", "=", "\"The format to use for generating the combined string; use '@{blah}' for accessing \"", "\"storage item 'blah' (string).\"", "return", "options" ]
Fixes the options, if necessary. I.e., it adds all required elements to the dictionary. :param options: the options to fix :type options: dict :return: the (potentially) fixed options :rtype: dict
[ "Fixes", "the", "options", "if", "necessary", ".", "I", ".", "e", ".", "it", "adds", "all", "required", "elements", "to", "the", "dictionary", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/source.py#L681-L699
fracpete/python-weka-wrapper3
python/weka/flow/source.py
CombineStorage.do_execute
def do_execute(self): """ The actual execution of the actor. :return: None if successful, otherwise error message :rtype: str """ formatstr = str(self.resolve_option("format")) expanded = self.storagehandler.expand(formatstr) self._output.append(Token(expanded)) return None
python
def do_execute(self): """ The actual execution of the actor. :return: None if successful, otherwise error message :rtype: str """ formatstr = str(self.resolve_option("format")) expanded = self.storagehandler.expand(formatstr) self._output.append(Token(expanded)) return None
[ "def", "do_execute", "(", "self", ")", ":", "formatstr", "=", "str", "(", "self", ".", "resolve_option", "(", "\"format\"", ")", ")", "expanded", "=", "self", ".", "storagehandler", ".", "expand", "(", "formatstr", ")", "self", ".", "_output", ".", "append", "(", "Token", "(", "expanded", ")", ")", "return", "None" ]
The actual execution of the actor. :return: None if successful, otherwise error message :rtype: str
[ "The", "actual", "execution", "of", "the", "actor", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/source.py#L701-L711
fracpete/python-weka-wrapper3
python/weka/flow/source.py
StringConstants.fix_config
def fix_config(self, options): """ Fixes the options, if necessary. I.e., it adds all required elements to the dictionary. :param options: the options to fix :type options: dict :return: the (potentially) fixed options :rtype: dict """ options = super(StringConstants, self).fix_config(options) opt = "strings" if opt not in options: options[opt] = [] if opt not in self.help: self.help[opt] = "The strings to output (list of string)." return options
python
def fix_config(self, options): """ Fixes the options, if necessary. I.e., it adds all required elements to the dictionary. :param options: the options to fix :type options: dict :return: the (potentially) fixed options :rtype: dict """ options = super(StringConstants, self).fix_config(options) opt = "strings" if opt not in options: options[opt] = [] if opt not in self.help: self.help[opt] = "The strings to output (list of string)." return options
[ "def", "fix_config", "(", "self", ",", "options", ")", ":", "options", "=", "super", "(", "StringConstants", ",", "self", ")", ".", "fix_config", "(", "options", ")", "opt", "=", "\"strings\"", "if", "opt", "not", "in", "options", ":", "options", "[", "opt", "]", "=", "[", "]", "if", "opt", "not", "in", "self", ".", "help", ":", "self", ".", "help", "[", "opt", "]", "=", "\"The strings to output (list of string).\"", "return", "options" ]
Fixes the options, if necessary. I.e., it adds all required elements to the dictionary. :param options: the options to fix :type options: dict :return: the (potentially) fixed options :rtype: dict
[ "Fixes", "the", "options", "if", "necessary", ".", "I", ".", "e", ".", "it", "adds", "all", "required", "elements", "to", "the", "dictionary", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/source.py#L749-L766
fracpete/python-weka-wrapper3
python/weka/flow/source.py
StringConstants.do_execute
def do_execute(self): """ The actual execution of the actor. :return: None if successful, otherwise error message :rtype: str """ for s in self.resolve_option("strings"): self._output.append(Token(s)) return None
python
def do_execute(self): """ The actual execution of the actor. :return: None if successful, otherwise error message :rtype: str """ for s in self.resolve_option("strings"): self._output.append(Token(s)) return None
[ "def", "do_execute", "(", "self", ")", ":", "for", "s", "in", "self", ".", "resolve_option", "(", "\"strings\"", ")", ":", "self", ".", "_output", ".", "append", "(", "Token", "(", "s", ")", ")", "return", "None" ]
The actual execution of the actor. :return: None if successful, otherwise error message :rtype: str
[ "The", "actual", "execution", "of", "the", "actor", ".", ":", "return", ":", "None", "if", "successful", "otherwise", "error", "message", ":", "rtype", ":", "str" ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/source.py#L768-L777
fracpete/python-weka-wrapper3
python/weka/flow/sink.py
Sink.post_execute
def post_execute(self): """ Gets executed after the actual execution. :return: None if successful, otherwise error message :rtype: str """ result = super(Sink, self).post_execute() if result is None: self._input = None return result
python
def post_execute(self): """ Gets executed after the actual execution. :return: None if successful, otherwise error message :rtype: str """ result = super(Sink, self).post_execute() if result is None: self._input = None return result
[ "def", "post_execute", "(", "self", ")", ":", "result", "=", "super", "(", "Sink", ",", "self", ")", ".", "post_execute", "(", ")", "if", "result", "is", "None", ":", "self", ".", "_input", "=", "None", "return", "result" ]
Gets executed after the actual execution. :return: None if successful, otherwise error message :rtype: str
[ "Gets", "executed", "after", "the", "actual", "execution", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/sink.py#L46-L56
fracpete/python-weka-wrapper3
python/weka/flow/sink.py
Console.fix_config
def fix_config(self, options): """ Fixes the options, if necessary. I.e., it adds all required elements to the dictionary. :param options: the options to fix :type options: dict :return: the (potentially) fixed options :rtype: dict """ options = super(Console, self).fix_config(options) opt = "prefix" if opt not in options: options[opt] = "" if opt not in self.help: self.help[opt] = "The prefix for the output (string)." return options
python
def fix_config(self, options): """ Fixes the options, if necessary. I.e., it adds all required elements to the dictionary. :param options: the options to fix :type options: dict :return: the (potentially) fixed options :rtype: dict """ options = super(Console, self).fix_config(options) opt = "prefix" if opt not in options: options[opt] = "" if opt not in self.help: self.help[opt] = "The prefix for the output (string)." return options
[ "def", "fix_config", "(", "self", ",", "options", ")", ":", "options", "=", "super", "(", "Console", ",", "self", ")", ".", "fix_config", "(", "options", ")", "opt", "=", "\"prefix\"", "if", "opt", "not", "in", "options", ":", "options", "[", "opt", "]", "=", "\"\"", "if", "opt", "not", "in", "self", ".", "help", ":", "self", ".", "help", "[", "opt", "]", "=", "\"The prefix for the output (string).\"", "return", "options" ]
Fixes the options, if necessary. I.e., it adds all required elements to the dictionary. :param options: the options to fix :type options: dict :return: the (potentially) fixed options :rtype: dict
[ "Fixes", "the", "options", "if", "necessary", ".", "I", ".", "e", ".", "it", "adds", "all", "required", "elements", "to", "the", "dictionary", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/sink.py#L129-L146
fracpete/python-weka-wrapper3
python/weka/flow/sink.py
FileOutputSink.fix_config
def fix_config(self, options): """ Fixes the options, if necessary. I.e., it adds all required elements to the dictionary. :param options: the options to fix :type options: dict :return: the (potentially) fixed options :rtype: dict """ options = super(FileOutputSink, self).fix_config(options) opt = "output" if opt not in options: options[opt] = "." if opt not in self.help: self.help[opt] = "The file to write to (string)." return options
python
def fix_config(self, options): """ Fixes the options, if necessary. I.e., it adds all required elements to the dictionary. :param options: the options to fix :type options: dict :return: the (potentially) fixed options :rtype: dict """ options = super(FileOutputSink, self).fix_config(options) opt = "output" if opt not in options: options[opt] = "." if opt not in self.help: self.help[opt] = "The file to write to (string)." return options
[ "def", "fix_config", "(", "self", ",", "options", ")", ":", "options", "=", "super", "(", "FileOutputSink", ",", "self", ")", ".", "fix_config", "(", "options", ")", "opt", "=", "\"output\"", "if", "opt", "not", "in", "options", ":", "options", "[", "opt", "]", "=", "\".\"", "if", "opt", "not", "in", "self", ".", "help", ":", "self", ".", "help", "[", "opt", "]", "=", "\"The file to write to (string).\"", "return", "options" ]
Fixes the options, if necessary. I.e., it adds all required elements to the dictionary. :param options: the options to fix :type options: dict :return: the (potentially) fixed options :rtype: dict
[ "Fixes", "the", "options", "if", "necessary", ".", "I", ".", "e", ".", "it", "adds", "all", "required", "elements", "to", "the", "dictionary", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/sink.py#L185-L202
fracpete/python-weka-wrapper3
python/weka/flow/sink.py
DumpFile.fix_config
def fix_config(self, options): """ Fixes the options, if necessary. I.e., it adds all required elements to the dictionary. :param options: the options to fix :type options: dict :return: the (potentially) fixed options :rtype: dict """ options = super(DumpFile, self).fix_config(options) opt = "append" if opt not in options: options[opt] = False if opt not in self.help: self.help[opt] = "Whether to append to the file or overwrite (bool)." return options
python
def fix_config(self, options): """ Fixes the options, if necessary. I.e., it adds all required elements to the dictionary. :param options: the options to fix :type options: dict :return: the (potentially) fixed options :rtype: dict """ options = super(DumpFile, self).fix_config(options) opt = "append" if opt not in options: options[opt] = False if opt not in self.help: self.help[opt] = "Whether to append to the file or overwrite (bool)." return options
[ "def", "fix_config", "(", "self", ",", "options", ")", ":", "options", "=", "super", "(", "DumpFile", ",", "self", ")", ".", "fix_config", "(", "options", ")", "opt", "=", "\"append\"", "if", "opt", "not", "in", "options", ":", "options", "[", "opt", "]", "=", "False", "if", "opt", "not", "in", "self", ".", "help", ":", "self", ".", "help", "[", "opt", "]", "=", "\"Whether to append to the file or overwrite (bool).\"", "return", "options" ]
Fixes the options, if necessary. I.e., it adds all required elements to the dictionary. :param options: the options to fix :type options: dict :return: the (potentially) fixed options :rtype: dict
[ "Fixes", "the", "options", "if", "necessary", ".", "I", ".", "e", ".", "it", "adds", "all", "required", "elements", "to", "the", "dictionary", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/sink.py#L240-L257
fracpete/python-weka-wrapper3
python/weka/flow/sink.py
DumpFile.do_execute
def do_execute(self): """ The actual execution of the actor. :return: None if successful, otherwise error message :rtype: str """ result = None f = None try: if bool(self.resolve_option("append")): f = open(str(self.resolve_option("output")), "a") else: f = open(str(self.resolve_option("output")), "w") f.write(str(self.input.payload)) f.write("\n") except Exception as e: result = self.full_name + "\n" + traceback.format_exc() finally: if f is not None: f.close() return result
python
def do_execute(self): """ The actual execution of the actor. :return: None if successful, otherwise error message :rtype: str """ result = None f = None try: if bool(self.resolve_option("append")): f = open(str(self.resolve_option("output")), "a") else: f = open(str(self.resolve_option("output")), "w") f.write(str(self.input.payload)) f.write("\n") except Exception as e: result = self.full_name + "\n" + traceback.format_exc() finally: if f is not None: f.close() return result
[ "def", "do_execute", "(", "self", ")", ":", "result", "=", "None", "f", "=", "None", "try", ":", "if", "bool", "(", "self", ".", "resolve_option", "(", "\"append\"", ")", ")", ":", "f", "=", "open", "(", "str", "(", "self", ".", "resolve_option", "(", "\"output\"", ")", ")", ",", "\"a\"", ")", "else", ":", "f", "=", "open", "(", "str", "(", "self", ".", "resolve_option", "(", "\"output\"", ")", ")", ",", "\"w\"", ")", "f", ".", "write", "(", "str", "(", "self", ".", "input", ".", "payload", ")", ")", "f", ".", "write", "(", "\"\\n\"", ")", "except", "Exception", "as", "e", ":", "result", "=", "self", ".", "full_name", "+", "\"\\n\"", "+", "traceback", ".", "format_exc", "(", ")", "finally", ":", "if", "f", "is", "not", "None", ":", "f", ".", "close", "(", ")", "return", "result" ]
The actual execution of the actor. :return: None if successful, otherwise error message :rtype: str
[ "The", "actual", "execution", "of", "the", "actor", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/sink.py#L259-L280
fracpete/python-weka-wrapper3
python/weka/flow/sink.py
ModelWriter.check_input
def check_input(self, token): """ Performs checks on the input token. Raises an exception if unsupported. :param token: the token to check :type token: Token """ if not isinstance(token.payload, ModelContainer): raise Exception(self.full_name + ": Input token is not a ModelContainer!")
python
def check_input(self, token): """ Performs checks on the input token. Raises an exception if unsupported. :param token: the token to check :type token: Token """ if not isinstance(token.payload, ModelContainer): raise Exception(self.full_name + ": Input token is not a ModelContainer!")
[ "def", "check_input", "(", "self", ",", "token", ")", ":", "if", "not", "isinstance", "(", "token", ".", "payload", ",", "ModelContainer", ")", ":", "raise", "Exception", "(", "self", ".", "full_name", "+", "\": Input token is not a ModelContainer!\"", ")" ]
Performs checks on the input token. Raises an exception if unsupported. :param token: the token to check :type token: Token
[ "Performs", "checks", "on", "the", "input", "token", ".", "Raises", "an", "exception", "if", "unsupported", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/sink.py#L308-L316
fracpete/python-weka-wrapper3
python/weka/flow/sink.py
ModelWriter.do_execute
def do_execute(self): """ The actual execution of the actor. :return: None if successful, otherwise error message :rtype: str """ result = None cont = self.input.payload serialization.write_all( str(self.resolve_option("output")), [cont.get("Model").jobject, cont.get("Header").jobject]) return result
python
def do_execute(self): """ The actual execution of the actor. :return: None if successful, otherwise error message :rtype: str """ result = None cont = self.input.payload serialization.write_all( str(self.resolve_option("output")), [cont.get("Model").jobject, cont.get("Header").jobject]) return result
[ "def", "do_execute", "(", "self", ")", ":", "result", "=", "None", "cont", "=", "self", ".", "input", ".", "payload", "serialization", ".", "write_all", "(", "str", "(", "self", ".", "resolve_option", "(", "\"output\"", ")", ")", ",", "[", "cont", ".", "get", "(", "\"Model\"", ")", ".", "jobject", ",", "cont", ".", "get", "(", "\"Header\"", ")", ".", "jobject", "]", ")", "return", "result" ]
The actual execution of the actor. :return: None if successful, otherwise error message :rtype: str
[ "The", "actual", "execution", "of", "the", "actor", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/sink.py#L318-L330
fracpete/python-weka-wrapper3
python/weka/flow/sink.py
MatrixPlot.fix_config
def fix_config(self, options): """ Fixes the options, if necessary. I.e., it adds all required elements to the dictionary. :param options: the options to fix :type options: dict :return: the (potentially) fixed options :rtype: dict """ options = super(MatrixPlot, self).fix_config(options) opt = "percent" if opt not in options: options[opt] = 100.0 if opt not in self.help: self.help[opt] = "The percentage of the data to display (0-100, float)." opt = "seed" if opt not in options: options[opt] = 1 if opt not in self.help: self.help[opt] = "The seed value for randomizing the plot when viewing a subset (int)." opt = "size" if opt not in options: options[opt] = 10 if opt not in self.help: self.help[opt] = "The size of the circles in the plot (int)." opt = "title" if opt not in options: options[opt] = None if opt not in self.help: self.help[opt] = "The title for the plot (str)." opt = "outfile" if opt not in options: options[opt] = None if opt not in self.help: self.help[opt] = "The file to store the plot in (str)." opt = "wait" if opt not in options: options[opt] = True if opt not in self.help: self.help[opt] = "Whether to wait for user to close the plot window (bool)." return options
python
def fix_config(self, options): """ Fixes the options, if necessary. I.e., it adds all required elements to the dictionary. :param options: the options to fix :type options: dict :return: the (potentially) fixed options :rtype: dict """ options = super(MatrixPlot, self).fix_config(options) opt = "percent" if opt not in options: options[opt] = 100.0 if opt not in self.help: self.help[opt] = "The percentage of the data to display (0-100, float)." opt = "seed" if opt not in options: options[opt] = 1 if opt not in self.help: self.help[opt] = "The seed value for randomizing the plot when viewing a subset (int)." opt = "size" if opt not in options: options[opt] = 10 if opt not in self.help: self.help[opt] = "The size of the circles in the plot (int)." opt = "title" if opt not in options: options[opt] = None if opt not in self.help: self.help[opt] = "The title for the plot (str)." opt = "outfile" if opt not in options: options[opt] = None if opt not in self.help: self.help[opt] = "The file to store the plot in (str)." opt = "wait" if opt not in options: options[opt] = True if opt not in self.help: self.help[opt] = "Whether to wait for user to close the plot window (bool)." return options
[ "def", "fix_config", "(", "self", ",", "options", ")", ":", "options", "=", "super", "(", "MatrixPlot", ",", "self", ")", ".", "fix_config", "(", "options", ")", "opt", "=", "\"percent\"", "if", "opt", "not", "in", "options", ":", "options", "[", "opt", "]", "=", "100.0", "if", "opt", "not", "in", "self", ".", "help", ":", "self", ".", "help", "[", "opt", "]", "=", "\"The percentage of the data to display (0-100, float).\"", "opt", "=", "\"seed\"", "if", "opt", "not", "in", "options", ":", "options", "[", "opt", "]", "=", "1", "if", "opt", "not", "in", "self", ".", "help", ":", "self", ".", "help", "[", "opt", "]", "=", "\"The seed value for randomizing the plot when viewing a subset (int).\"", "opt", "=", "\"size\"", "if", "opt", "not", "in", "options", ":", "options", "[", "opt", "]", "=", "10", "if", "opt", "not", "in", "self", ".", "help", ":", "self", ".", "help", "[", "opt", "]", "=", "\"The size of the circles in the plot (int).\"", "opt", "=", "\"title\"", "if", "opt", "not", "in", "options", ":", "options", "[", "opt", "]", "=", "None", "if", "opt", "not", "in", "self", ".", "help", ":", "self", ".", "help", "[", "opt", "]", "=", "\"The title for the plot (str).\"", "opt", "=", "\"outfile\"", "if", "opt", "not", "in", "options", ":", "options", "[", "opt", "]", "=", "None", "if", "opt", "not", "in", "self", ".", "help", ":", "self", ".", "help", "[", "opt", "]", "=", "\"The file to store the plot in (str).\"", "opt", "=", "\"wait\"", "if", "opt", "not", "in", "options", ":", "options", "[", "opt", "]", "=", "True", "if", "opt", "not", "in", "self", ".", "help", ":", "self", ".", "help", "[", "opt", "]", "=", "\"Whether to wait for user to close the plot window (bool).\"", "return", "options" ]
Fixes the options, if necessary. I.e., it adds all required elements to the dictionary. :param options: the options to fix :type options: dict :return: the (potentially) fixed options :rtype: dict
[ "Fixes", "the", "options", "if", "necessary", ".", "I", ".", "e", ".", "it", "adds", "all", "required", "elements", "to", "the", "dictionary", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/sink.py#L358-L405
fracpete/python-weka-wrapper3
python/weka/flow/sink.py
LinePlot.fix_config
def fix_config(self, options): """ Fixes the options, if necessary. I.e., it adds all required elements to the dictionary. :param options: the options to fix :type options: dict :return: the (potentially) fixed options :rtype: dict """ options = super(LinePlot, self).fix_config(options) opt = "attributes" if opt not in options: options[opt] = None if opt not in self.help: self.help[opt] = "The list of 0-based attribute indices to print; None for all (int)." opt = "percent" if opt not in options: options[opt] = 100.0 if opt not in self.help: self.help[opt] = "The percentage of the data to display (0-100, float)." opt = "seed" if opt not in options: options[opt] = 1 if opt not in self.help: self.help[opt] = "The seed value for randomizing the plot when viewing a subset (int)." opt = "title" if opt not in options: options[opt] = None if opt not in self.help: self.help[opt] = "The title for the plot (str)." opt = "outfile" if opt not in options: options[opt] = None if opt not in self.help: self.help[opt] = "The file to store the plot in (str)." opt = "wait" if opt not in options: options[opt] = True if opt not in self.help: self.help[opt] = "Whether to wait for user to close the plot window (bool)." return options
python
def fix_config(self, options): """ Fixes the options, if necessary. I.e., it adds all required elements to the dictionary. :param options: the options to fix :type options: dict :return: the (potentially) fixed options :rtype: dict """ options = super(LinePlot, self).fix_config(options) opt = "attributes" if opt not in options: options[opt] = None if opt not in self.help: self.help[opt] = "The list of 0-based attribute indices to print; None for all (int)." opt = "percent" if opt not in options: options[opt] = 100.0 if opt not in self.help: self.help[opt] = "The percentage of the data to display (0-100, float)." opt = "seed" if opt not in options: options[opt] = 1 if opt not in self.help: self.help[opt] = "The seed value for randomizing the plot when viewing a subset (int)." opt = "title" if opt not in options: options[opt] = None if opt not in self.help: self.help[opt] = "The title for the plot (str)." opt = "outfile" if opt not in options: options[opt] = None if opt not in self.help: self.help[opt] = "The file to store the plot in (str)." opt = "wait" if opt not in options: options[opt] = True if opt not in self.help: self.help[opt] = "Whether to wait for user to close the plot window (bool)." return options
[ "def", "fix_config", "(", "self", ",", "options", ")", ":", "options", "=", "super", "(", "LinePlot", ",", "self", ")", ".", "fix_config", "(", "options", ")", "opt", "=", "\"attributes\"", "if", "opt", "not", "in", "options", ":", "options", "[", "opt", "]", "=", "None", "if", "opt", "not", "in", "self", ".", "help", ":", "self", ".", "help", "[", "opt", "]", "=", "\"The list of 0-based attribute indices to print; None for all (int).\"", "opt", "=", "\"percent\"", "if", "opt", "not", "in", "options", ":", "options", "[", "opt", "]", "=", "100.0", "if", "opt", "not", "in", "self", ".", "help", ":", "self", ".", "help", "[", "opt", "]", "=", "\"The percentage of the data to display (0-100, float).\"", "opt", "=", "\"seed\"", "if", "opt", "not", "in", "options", ":", "options", "[", "opt", "]", "=", "1", "if", "opt", "not", "in", "self", ".", "help", ":", "self", ".", "help", "[", "opt", "]", "=", "\"The seed value for randomizing the plot when viewing a subset (int).\"", "opt", "=", "\"title\"", "if", "opt", "not", "in", "options", ":", "options", "[", "opt", "]", "=", "None", "if", "opt", "not", "in", "self", ".", "help", ":", "self", ".", "help", "[", "opt", "]", "=", "\"The title for the plot (str).\"", "opt", "=", "\"outfile\"", "if", "opt", "not", "in", "options", ":", "options", "[", "opt", "]", "=", "None", "if", "opt", "not", "in", "self", ".", "help", ":", "self", ".", "help", "[", "opt", "]", "=", "\"The file to store the plot in (str).\"", "opt", "=", "\"wait\"", "if", "opt", "not", "in", "options", ":", "options", "[", "opt", "]", "=", "True", "if", "opt", "not", "in", "self", ".", "help", ":", "self", ".", "help", "[", "opt", "]", "=", "\"Whether to wait for user to close the plot window (bool).\"", "return", "options" ]
Fixes the options, if necessary. I.e., it adds all required elements to the dictionary. :param options: the options to fix :type options: dict :return: the (potentially) fixed options :rtype: dict
[ "Fixes", "the", "options", "if", "necessary", ".", "I", ".", "e", ".", "it", "adds", "all", "required", "elements", "to", "the", "dictionary", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/sink.py#L475-L522