Beispiel #1
0
def update_graph_context(updates, update_count=False):

    if update_count:
        for x in updates:
            context_vector = x['updated_context']
            unit_context_vector = context_vector / np.linalg.norm(
                context_vector)
            collection.update_one(
                {
                    'word': x['word'],
                    'connection': x['connection']
                }, {
                    '$set': {
                        'context': list(unit_context_vector),
                        'update_count': x['update_count'] + 1
                    }
                })
    else:
        for x in updates:
            context_vector = x['updated_context']
            unit_context_vector = context_vector / np.linalg.norm(
                context_vector)
            collection.update_one(
                {
                    'word': x['word'],
                    'connection': x['connection']
                }, {'$set': {
                    'context': list(unit_context_vector)
                }})
Beispiel #2
0
 def release_lock(self):
     for connection in self.sub_graph:
         collection.update_one(
             {
                 'word': connection[0],
                 'connection': connection[1]
             }, {'$set': {
                 'lock': False
             }})
Beispiel #3
0
 def set_lock(self):
     for connection in self.sub_graph:
         collection.update_one(
             {
                 'word': connection[0],
                 'connection': connection[1]
             }, {'$set': {
                 'lock': True
             }})
Beispiel #4
0
def unlock_graph():
    locked_nodes = list(collection.find({'lock': True}))
    for node in locked_nodes:
        collection.update_one(
            {
                'word': node['word'],
                'connection': node['connection']
            }, {'$set': {
                'lock': False
            }})
def update_note(user_id):
    body = ast.literal_eval(json.dumps(request.get_json()))
    records_updated = collection.update_one({"id": int(user_id)}, body)
    if records_updated.modified_count > 0:
        return "", 200
    else:
        return "", 404
Beispiel #6
0
def update_graph_node(updates):
    for x in updates:
        update_vector = x['update_vector']
        weight_vector = x['weight_vector']

        unit_update_vector = update_vector / np.linalg.norm(update_vector)
        unit_weight_vector = weight_vector / np.linalg.norm(weight_vector)

        collection.update_one(
            {
                'word': x['word'],
                'connection': x['connection']
            }, {
                '$set': {
                    'update_vector': list(unit_update_vector),
                    'weight_vector': list(unit_weight_vector)
                }
            })
Beispiel #7
0
def mongo_update(search: Dict, newData: Dict):
    collection.update_one(search, {"$set": newData})
Beispiel #8
0
    collection.delete_one(search)


def mongo_read():
    results = collection.find()
    for r in results:
        print(r)


def mongo_query(search: Dict):
    results = collection.find(search)
    for r in results:
        print(r)


if __name__ == '__main__':
    # Nota si las pruebas se hacen desde WSL mongodb tiene que estar instalado en esa maquina virtual, esto solo aplica en windows
    document = {"_id": 4, "name": "mouse", "price": 300}
    # mongo_create(document)
    # mongo_read()
    #mongo_query({"price": 400})
    #mongo_update({"price": 400}, document)
    mongo_delete({"_id": 4})

    #otros comandos utiles
    # para contar los objetos
    c = collection.count_documents({})
    print(c)
    #para incrementar el valor de un dato
    i = collection.update_one({"_id": 3}, {"$inc": {"price": 30}})
    mongo_read()