def __init__(self, config): self.config_ = config self.logger_ = logging.getLogger("main") self.stdout = sys.stdout self.extractor = LdaFeatureExtractor(prefix=config['prefix'])
def test_get_feature_number(self): feature_extractor = LdaFeatureExtractor(prefix=self.config['prefix']) num_topics = feature_extractor.get_feature_number() self.assertEqual(500, num_topics)
class StompListener(object): def __init__(self, config): self.config_ = config self.logger_ = logging.getLogger("main") self.stdout = sys.stdout self.extractor = LdaFeatureExtractor(prefix=config['prefix']) def __print_async(self, frame_type, headers, body): """ Utility function to print a message and setup the command prompt for the next input """ self.__sysout("\r \r", end='') self.__sysout(frame_type) for header_key in headers.keys(): self.__sysout('%s: %s' % (header_key, headers[header_key])) self.__sysout('') self.__sysout(body) self.__sysout('> ', end='') self.stdout.flush() def __extract_features(self, message): """ Extracts features from clean content and sends it on """ self.logger_.debug("Got article '%s'" % message['headline']) features = self.extractor.get_features(message['clean_content']) version = self.extractor.get_version() #add features to json representation of article message['features'] = {'version': version, 'data': features} #send message on to Article Ranker try: self.conn_.send(json.dumps(message), destination="queue/features") except Exception as inst: self.logger_.error("Could not send message to feature queue. " "Unknown Error %s: %s" % (type(inst), inst)) def on_error(self, hears, message): self.logger_.error('received an error %s' % message) def on_message(self, headers, message): received_message = json.loads(message) self.__extract_features(received_message) def on_connected(self, headers, body): self.__print_async("CONNECTED", headers, body) def __sysout(self, msg, end="\n"): self.stdout.write(str(msg) + end) def __error(self, msg, end="\n"): self.stdout.write(str(msg) + end) def set_stomp_connection(self, connection): self.conn_ = connection