示例#1
0
 def handle_response(self, data, _response, _session):
     for post in self.xread(data):
         if post.message:
             topics = classifier.classify(post.message, "Environment")
             score = topics.get("Environment", 0)
             if score > 0:
                 self.append(post._replace(score=score))
示例#2
0
    def classify(cls, postid, text, *topics):
        """Classify the given `text` using the quick-and-dirty classifier and
        instantiate a new PostTopics instance.

        """
        classifications = classify(text, *topics)
        # DDB/Decimals are exact; eagerly convert to Decimal with
        # appropriate Context to avoid error:
        prepared = {topic: CLASSIFY_CONTEXT.create_decimal(score)
                    for (topic, score) in classifications.iteritems()}
        return cls(postid=postid, classifier=cls.QD_CLASSIFIER, **prepared)