Ejemplo n.º 1
0
def fit_suggestions(token, document):
    send_json({
        'action': 'fit',
        'token': token,
        'document': document
    }, settings.NETWORK['recommendation']['host'],
              settings.NETWORK['recommendation']['port'])
Ejemplo n.º 2
0
def build(path):
    dic = {'action': 'build', 'path': path}
    success = {
        send_json(dic, settings.NETWORK['models']['host'],
                  settings.NETWORK['models']['port'], True)['success'],
        send_json(dic, settings.NETWORK['recommendation']['host'],
                  settings.NETWORK['recommendation']['port'], True)['success'],
        send_json(dic, settings.NETWORK['summaries']['host'],
                  settings.NETWORK['summaries']['port'], True)['success']
    }
    return False not in success
Ejemplo n.º 3
0
    def _build_index(self, freq, terms):
        index = [{'key': term, 'value': {'documents': []}} for term in terms]
        freq = np.array(freq.todense())

        it = np.nditer(freq, flags=['multi_index'])
        while not it.finished:
            f = int(it[0])
            i, j = it.multi_index
            if f:
                index[i]['value']['documents'].append({'document': self.doc_names[j], 'freq': f})
            it.iternext()

        utils.send_json({
            'action': 'create',
            'data': index
        }, NETWORK['indices']['host'], NETWORK['indices']['port'])
Ejemplo n.º 4
0
def _analyze(text, is_query):
    response = utils.send_json({
        'action': 'process',
        'data': text,
        'is_query': is_query
    }, NETWORK['text']['host'], NETWORK['text']['port'], True)
    return response['terms']
Ejemplo n.º 5
0
def update_search(token, document, positive, count):
    return send_json(
        {
            'action': 'update_query',
            'token': token,
            'document': document,
            'positive': positive,
            'count': count
        }, settings.NETWORK['models']['host'],
        settings.NETWORK['models']['port'], True)
Ejemplo n.º 6
0
def search(token, query, continuation, count):
    return send_json(
        {
            'action': 'query',
            'token': token,
            'query': query,
            'continuation': continuation,
            'count': count
        }, settings.NETWORK['models']['host'],
        settings.NETWORK['models']['port'], True)
Ejemplo n.º 7
0
 def _load_index(self):
     while True:
         index = utils.send_json({
             'action': 'load',
             'path': self.path
         }, NETWORK['indices']['host'], NETWORK['indices']['port'], True)
         if index:
             break
         time.sleep(random.randint(10, 60))  # Give some time so indices module can make it
     return index
Ejemplo n.º 8
0
    def build(self, path):
        self.path = path
        self.doc_names = [
            '.'.join(doc.name.split('.')[:-1])
            for doc in Path(self.path).iterdir() if doc.name.endswith('.txt')
        ]
        self.doc_names.sort()

        index = utils.send_json({
            'action': 'load',
            'path': path
        }, NETWORK['indices']['host'], NETWORK['indices']['port'], True)

        if not index:
            freq, terms = self._calculate_freq()
            self._build_index(freq, terms)
        else:
            freq, terms = utils.load_freq(index, self.doc_names)

        self.freq = freq
        self.w = TfidfTransformer().fit_transform(freq)
        self.terms = terms
        self.term_count = self.w.shape[0]
        self.doc_count = self.w.shape[1]
Ejemplo n.º 9
0
def set_model(model):
    send_json({
        'action': 'set_model',
        'model': model
    }, settings.NETWORK['models']['host'], settings.NETWORK['models']['port'])
Ejemplo n.º 10
0
def get_summary():
    return send_json({'action': 'get'}, settings.NETWORK['summaries']['host'],
                     settings.NETWORK['summaries']['port'], True)
Ejemplo n.º 11
0
def get_suggestions(token):
    return send_json({
        'action': 'suggest',
        'token': token
    }, settings.NETWORK['recommendation']['host'],
                     settings.NETWORK['recommendation']['port'], True)
Ejemplo n.º 12
0
def get_model():
    return send_json({'action': 'get_model'},
                     settings.NETWORK['models']['host'],
                     settings.NETWORK['models']['port'], True)