<commit_before><commit_msg>Fix more missing modules<commit_after>#!/usr/bin/env python
import cPickle as pickle
from time import time
from datetime import datetime

from .data import ObjectStore
from ..features.mapping import FEATURE_MAPPERS

import logging
log = logging.getLogger()

class Classifier(object):
    mid = 'models:classifiers'
    def __init__(self, name):
        self.name = name
        dm = ObjectStore.Get(self.mid).fetch(name)
        if dm:
            # undo the data store encoding here - it's really binary data
            self.model = pickle.loads(dm['data'].encode('utf-8'))
            self.mapper = FEATURE_MAPPERS[dm['mapping']['name']](**dm['mapping']['params'])
        else:
            raise Exception('No classifier for name (%s) in store', self.name)

    @classmethod
    def create(cls, name, mapping, data, metadata = {}):
        timestamp = datetime.fromtimestamp(time()).strftime('%Y-%m-%d %H:%M:%S')
        log.info('Storing classifier model (%s)...', name)
        ObjectStore.Get(cls.mid).save({
            '_id': name,
            'created_at': timestamp,
            'mapping': mapping,
            'data': data,
            'metadata': metadata
        })
{'fraction_non_alphanumeric': 0.13681592039800994, 'fraction_numerical': 0.0008291873963515755, 'mean_word_length': 2.7024539877300615, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '886188', 'n_tokens_mistral': 350, 'n_tokens_neox': 340, 'n_words': 92}