Exemplo n.º 1
0
from app.config import config

from tweepy.error import TweepError
from mongoengine.errors import NotUniqueError, OperationError
from pymongo.errors import DuplicateKeyError

import random

# Logging
from app.logger import logger
logger = logger(__name__)

# Load the classifier and markov.
# Loaded here so we can keep it in memory.
# accessible via app.brain.CLS or app.brain.MKV
CLS = Classifier()
MKV = Markov(ramble=config().ramble,
             ngram_size=config().ngram_size,
             spasm=config().spasm)


def ponder():
    """
    Fetch tweets from the Muses
    and memorize them;
    i.e. train classifier or Markov on them.
    """
    logger.info('Pondering new twitter data...')

    # Each of these are just a list
    # of tweets as strings.
Exemplo n.º 2
0
 def setUp(self):
     self.clf = Classifier(filepath=test_filepath)
Exemplo n.º 3
0
 def setUp(self):
     self.clf = Classifier(filepath=test_filepath)
Exemplo n.º 4
0
class ClassifierTest(unittest.TestCase):
    def setUp(self):
        self.clf = Classifier(filepath=test_filepath)

    def tearDown(self):
        # Clean up test pickle.
        try:
            os.remove(test_filepath)
        except FileNotFoundError:
            pass

    def test_train(self):
        self.clf.train(docs, labels, save=False)
        self.assertEqual(list(self.clf.clf.class_count_), [3.0, 3.0])

    def test_online_train(self):
        self.clf.train(docs, labels, save=False)
        self.clf.train(new_docs, [1, 1, 1], save=False)
        self.assertEqual(list(self.clf.clf.class_count_), [3.0, 6.0])

    def test_classify(self):
        self.clf.train(docs, labels, save=False)
        probs = self.clf.classify(["foo dog bar"])[0]
        self.assertEqual(1, round(probs[1]))

    def test_save_and_load(self):
        self.clf.train(docs, labels, save=True)
        clf = self.clf.load()
        self.assertEqual(list(clf.class_count_), [3.0, 3.0])
Exemplo n.º 5
0
class ClassifierTest(unittest.TestCase):
    def setUp(self):
        self.clf = Classifier(filepath=test_filepath)

    def tearDown(self):
        # Clean up test pickle.
        try:
            os.remove(test_filepath)
        except FileNotFoundError:
            pass

    def test_train(self):
        self.clf.train(docs, labels, save=False)
        self.assertEqual(list(self.clf.clf.class_count_), [3.0, 3.0])

    def test_online_train(self):
        self.clf.train(docs, labels, save=False)
        self.clf.train(new_docs, [1, 1, 1], save=False)
        self.assertEqual(list(self.clf.clf.class_count_), [3.0, 6.0])

    def test_classify(self):
        self.clf.train(docs, labels, save=False)
        probs = self.clf.classify(['foo dog bar'])[0]
        self.assertEqual(1, round(probs[1]))

    def test_save_and_load(self):
        self.clf.train(docs, labels, save=True)
        clf = self.clf.load()
        self.assertEqual(list(clf.class_count_), [3.0, 3.0])