from pkg_resources import iter_entry_points

from config import config


plugins = []
for plugin in iter_entry_points(group='spicedham.classifiers', name=None):
    pluginClass = plugin.load()
    plugins.append(pluginClass())


def train(training_data, is_spam):
    for plugin in plugins:
        plugin.train(training_data, is_spam)


def classify(classification_data):
    average_score = 0
    total = 0
    for plugin in plugins:
        value = plugin.classify(classification_data)
        if value != None:
            total += 1
            average_score += value
    return average_score / total

from pkg_resources import iter_entry_points

from config import config


plugins = []
for plugin in iter_entry_points(group='spicedham.classifiers', name=None):
    pluginClass = plugin.load()
    plugins.append(pluginClass())


def train(training_data, is_spam):
    for plugin in plugins:
        plugin.train(training_data, is_spam)


def classify(classification_data):
    average_score = 0
    total = 0
    for plugin in plugins:
        value = plugin.classify(classification_data)
        if value != None:
            total += 1
            average_score += value
    if total > 0:
        return average_score / total
    else:
        return 0

Allow for the case where no plugin returns a score