Beispiel #1
0
def classify(response, flag):
    """Run response.description through classifier"""
    try:
        score = get_spicedham().classify(tokenize(response.description))
        if score > ABUSE_CUTOFF:
            return True
    except (ZeroDivisionError, TypeError):
        # If there isn't any training data (and possibly some other
        # situations), classify can raise a TypeError or
        # ZeroDivisionError.
        #
        # https://github.com/mozilla/spicedham/issues/21
        #
        # For now, we'll assume that means it's not abuse.
        pass

    return False
Beispiel #2
0
 def train(self, descriptions, is_abuse=True):
     # Note: This is probably a cached Spicedham object.
     sham = get_spicedham()
     for desc in descriptions:
         sham.train(tokenize(desc), match=is_abuse)