def get_feature_functions(cls, features='all'): from gamera import plugin global all_features if all_features is None: all_features = plugin.methods_flat_category('Features', ONEBIT) all_features.sort() if features == 'all' or features is None: functions = all_features return functions, cls._get_feature_vector_size(functions) features = util.make_sequence(features) all_strings = True for feature in features: if not util.is_string_or_unicode(feature): all_strings = False break if not all_strings: import plugin all_functions = False if (type(features) == tuple and len(features) == 2 and type(features[0]) == list and type(features[1]) == int): all_functions = True for feature in features[0]: if not (type(feature) == tuple and util.is_string_or_unicode(feature[0]) and issubclass(feature[1], plugin.PluginFunction)): all_functions = False break if not all_functions: raise ValueError( "'%s' is not a valid way to specify a list of features." % str(features)) else: return features else: features.sort() functions = [] for feature in features: found = 0 for i in all_features: if feature == i[0]: functions.append(i) found = 1 break if not found: raise ValueError("'%s' is not a known feature function." % feature) functions.sort() return functions, cls._get_feature_vector_size(functions)
def classify_heuristic(self, id_name): """Classifies the image as the value *id_name* and sets the state to HEURISTIC. Use this method when a heuristic process has classified this glyph. This method also unsets the *confidence* map. *id_name* Can come in one of two forms: **string** image is classified using the given ``.``-delimited class name. As in this case no confidence is provided, it is set to 0.5. **list of tuples** A list of tuples where each tuple is the pair (*confidence*, *class_name*). *confidence* A value in range (0, 1), where 0 is uncertain and 1 is certain. *class_name* A ``.``-delimited class name.""" if util.is_string_or_unicode(id_name): id_name = [(0.5, id_name)] elif type(id_name) != ListType: raise TypeError("id_name must be a string or a list") self.id_name = id_name self.confidence = {} self.classification_state = HEURISTIC
def classify_automatic(self, id_name): """Classifies the image as the value *id_name* and sets the state to AUTOMATIC. Use this method when an automatic classifier has classified this glyph. Note that this method does not touch the *confidence* map for the main id; this must be set separately. *id_name* Can come in one of two forms: **string** image is classified using the given ``.``-delimited class name. As in this case no confidence is provided, it is set to zero. **list of tuples** A list of tuples where each tuple is the pair (*confidence*, *class_name*). *confidence* A value in range (0, 1), where 0 is uncertain and 1 is certain. *class_name* A ``.``-delimited class name.""" if util.is_string_or_unicode(id_name): id_name = [(0.0, id_name)] elif type(id_name) != ListType: raise TypeError("id_name must be a string or a list") self.id_name = id_name self.classification_state = AUTOMATIC
def __init__(self, name=None, default="", extension="*.*"): Arg.__init__(self, name) if not util.is_string_or_unicode(default): raise TypeError("'default' must be a string") self.default = default ## if not util.is_string_or_unicode(extension): ## raise TypeError("'extension' must be a string") self.extension = extension
def __init__(self, name=None, default="", extension="*.*"): Arg.__init__(self, name) if not util.is_string_or_unicode(default): raise TypeError("'default' must be a string") self.default = default ## if not util.is_string_or_unicode(extension): ## raise TypeError("'extension' must be a string") self.extension = extension
def __init__(self, name=None, default=None): Arg.__init__(self, name) if default is None: self.has_default = False self.default = '' else: self.has_default = True self.default = default if not util.is_string_or_unicode(self.default): raise TypeError("'default' must be an int")
def __init__(self, name=None, default=None): Arg.__init__(self, name) if default is None: self.has_default = False self.default = '' else: self.has_default = True self.default = default if not util.is_string_or_unicode(self.default): raise TypeError("'default' must be an int")
def __init__(self, name=None, check_box='', default=None, enabled=True): Arg.__init__(self, name) if not util.is_string_or_unicode(check_box): raise TypeError("'check_box' must be a string") self.check_box = check_box if default is None: self.has_default = False self.default = False else: self.has_default = True self.default = default self.default = bool(self.default) self.enabled = bool(enabled)
def __init__(self, name=None, check_box='', default=None, enabled=True): Arg.__init__(self, name) if not util.is_string_or_unicode(check_box): raise TypeError("'check_box' must be a string") self.check_box = check_box if default is None: self.has_default = False self.default = False else: self.has_default = True self.default = default self.default = bool(self.default) self.enabled = bool(enabled)
def __init__(self, name): self.name = name if name is not None and not util.is_string_or_unicode(name): raise TypeError("'name' must be a string") self.has_default = False
def __init__(self, name): self.name = name if name is not None and not util.is_string_or_unicode(name): raise TypeError("'name' must be a string") self.has_default = False