Exemple #1
0
def load_graph(scene):
    try:
        mongo = Mongo(scene + '_test')
        mongo_automata = automata.Mongo_automata('127.0.0.1', 'automata_test')
        config = mongo_automata.load_graph_config(scene_id=scene)
        if not config:
            return {'result': 'scene_id error'}
        nodes = mongo.search('instruction', {'fields': ['instruction', '_id']})
        edges = mongo.search('automata', {'fields': ['intent', '_id']})
        #nodes = list(map(lambda x:x['instruction'], nodes))
        #edges = list(map(lambda x:x['intent'], edges))

        result = json.dumps(
            {
                'config': config,
                'instruction': nodes,
                'automata': edges
            },
            ensure_ascii=False,
            sort_keys=True)
        result = result.encode('utf-8')
        return result
    except:
        traceback.print_exc()
        return {'result': 'error'}
Exemple #2
0
def search(db, collection, query):
    mongo = Mongo(db)
    if type(query) == bytes:
        query = query.decode('utf-8')
    try:
        query = json.loads(query)
    except:
        traceback.print_exc()
        return {'result': 'query format error'}
    if type(query) != dict:
        return {'result': 'query format error'}
    data = mongo.search(collection, query)
    result = json.dumps({'result': data}, ensure_ascii=False, sort_keys=True)
    result = result.encode('utf-8')
    return result
Exemple #3
0
def search_data(db, collection, query):
    mongo = Mongo(db)
    if type(query) == bytes:
        query = query.decode('utf-8')
    try:
        query = json.loads(query)
    except Exception:
        return {'result':'query format error'}
    if type(query) != dict:
        return {'result':'query format error'}
    if collection == 'dialogue':
        data = mongo.search_dialogue(query)
    else:
        data = mongo.search(collection, query)
    result = json.dumps({'result':data}, ensure_ascii=False, sort_keys=True)
    result = result.encode('utf-8')
    return result