예제 #1
0
def execute_waiting():
    """
    Looks for jobs not currently being executed in the pipeline and processes one if the pipeline is
    currently empty.
    """
    from providentia import app
    from providentia.classifier import sentiment

    # only run analysis if classifier is ready
    if sentiment.classify("test") is None:
        logging.debug('Classifier not ready, going back to sleep.')
        return

    # look to process a job
    with app.app_context():
        if tbl_benchmark.is_job_being_processed():
            logging.debug('A job is being processed, going back to sleep')
        else:
            logging.debug('No job being processed, looking for jobs to execute')
            unstarted_jobs = tbl_benchmark.get_unstarted_jobs()

            if unstarted_jobs is None:
                logging.debug('No jobs available, going back to sleep.')
            else:
                logging.debug('Found unstarted jobs!')
                random.shuffle(unstarted_jobs)
                start_job(unstarted_jobs.pop())
예제 #2
0
 def add_review(self, text, stars):
     self.review_count += 1
     self.stars += stars
     if sentiment.classify(text) == "pos":
         self.positive_count += 1
     else:
         self.negative_count += 1
예제 #3
0
 def __init__(self, business_id, text, stars):
     self.business_id = business_id
     self.total_stars = stars
     self.positive_count = 0
     self.negative_count = 0
     if sentiment.classify(text) == "pos":
         self.positive_count = 1
     else:
         self.negative_count = 1
예제 #4
0
 def add_review(self, text, cool, funny, useful):
     self.review_count += 1
     # Count number of words in the review without punctuation
     tokenizer = RegexpTokenizer(r'\w+')
     tokens = tokenizer.tokenize(text)
     self.length += len(tokens)
     self.cool += cool
     self.funny += funny
     self.useful += useful
     if sentiment.classify(text) == "pos":
         self.positive_count += 1
     else:
         self.negative_count += 1
예제 #5
0
def classify():
    """Classify the given text"""

    data = request.get_json()
    text = data['text']

    result = {}
    from providentia.classifier import sentiment
    if sentiment.get_classifier() is None:
        return Response({"message": "Classifier not ready yet!"}, status=503)
    else:
        result['result'] = sentiment.classify(text)

    return Response(json.dumps(result),
                    status=200,
                    mimetype='application/json')
예제 #6
0
 def add_sentiment(self, text):
     if sentiment.classify(text) == "pos":
         self.positive_count += 1
     else:
         self.negative_count += 1