def from_json(cls, json, max_entries=0):
        """Creates a new instance from the given JSON data as dict data
        structure.

        :param max_entries: Limit training set to a maximum of ``max_entries``
            items. This can be helpful to reduce memory usage. A value of 0 or
            less means no limit.
        """

        pos_tweets, neg_tweets = _limited_tweet_split(json, max_entries)

        tweets = _extract_documents(pos_tweets, "positive") + _extract_documents(neg_tweets, "negative")

        training_set = [(extract_features(doc), label) for (doc, label) in tweets]

        return cls.from_training_set(training_set)
예제 #2
0
    def from_json(cls, json, max_entries=0):
        """Creates a new instance from the given JSON data as dict data
        structure.

        :param max_entries: Limit training set to a maximum of ``max_entries``
            items. This can be helpful to reduce memory usage. A value of 0 or
            less means no limit.
        """

        pos_tweets, neg_tweets = _limited_tweet_split(json, max_entries)

        tweets = (_extract_documents(pos_tweets, 'positive') +
                  _extract_documents(neg_tweets, 'negative'))

        training_set = [(extract_features(doc), label)
                        for (doc, label) in tweets]

        return cls.from_training_set(training_set)
예제 #3
0
파일: server.py 프로젝트: passy/twentiment
 def _guess(self, message):
     twfeat = extract_features(normalize_text(message))
     result = self.classifier.prob_classify(twfeat)
     return format(result.prob('positive') - result.prob('negative'))