Beispiel #1
0
def insertIntent():
    intents = request.get_json()
    print(intents)
    for intentJson in intents['intents']:
        intent = Intent()
        intent.tag = intentJson['tag']

        for resJson in intentJson['responses']:
            res = Response()
            res.response = resJson
            intent.responses.append(res)

        for pattJson in intentJson['patterns']:
            patt = Pattern()
            patt.pattern = pattJson
            intent.patterns.append(patt)
        
        print(intent)
        insertEdit(intent)
    
    try:
        insertEdit(intent)
        return returnOk()
    except exc.SQLAlchemyError:
        return errorResp() 
Beispiel #2
0
def insertIntentAnswersPatterns():
    intents = request.get_json()
    print(intents)
    
    intent = getSingleIntent(intents['id'])

    for resJson in intents['responses']:
        if(resJson['id'] == -1):
            print(resJson)
            res = Response()
            res.response = resJson['response']
            intent.responses.append(res)

    for pattJson in intents['patterns']:
        if(pattJson['id'] == -1):
            patt = Pattern()
            patt.pattern = pattJson['pattern']
            intent.patterns.append(patt)


    try:
        insertEdit(intent)
        return returnOk()

    except exc.SQLAlchemyError:
        return errorResp()
Beispiel #3
0
def addPhone(id):
    c = getSingleContato(id)
    t = Telefone()
    if request.method == 'POST':
        if (id != -1):
            t.telefone = request.form['telefone']
            t.tipo = request.form['tipo_tel']
            c.telefones.append(t)
            insertEdit(c)

        return redirect(url_for('listar'))
    return render_template("addphone.html", c=c)
Beispiel #4
0
def insertUser():
    try:
        userJSON = request.get_json()
        user = User()
        user.name = userJSON['name']
        user.username = userJSON['username']
        user.password = userJSON['password']
        insertEdit(user)
        return returnOk()

    except exc.SQLAlchemyError:
        return errorResp()
Beispiel #5
0
def addAddress(id):
    c = getSingleContato(id)
    e = Endereco()
    if request.method == 'POST':
        if (id != -1):
            e.endereco = request.form['endereco']
            e.numero = request.form['numero']
            e.cep = request.form['cep']
            c.enderecos.append(e)
            insertEdit(c)
        return redirect(url_for('listar'))

    return render_template("addaddress.html", c=c)
Beispiel #6
0
def cadastrar(id=-1):
    c = Contato()
    t = Telefone()
    e = Endereco()
    telefones = []
    telefones.append(t)

    if (id != -1):
        c = getSingleContato(id)

    else:
        c.telefones.append(t)
        c.enderecos.append(e)

    if request.method == 'POST':
        if (id != -1):
            print(request.form)
            c.nome = request.form['nome']
            c.email = request.form['email']
            print(c.telefones)
            for i in range(0, len(c.telefones), 1):
                print(c.telefones[i].telefone)
                c.telefones[i].telefone = request.form['telefone' +
                                                       str(c.telefones[i].id)]
                c.telefones[i].tipo = request.form['tipo_tel' +
                                                   str(c.telefones[i].id)]

            for i in range(0, len(c.enderecos), 1):
                c.enderecos[i].endereco = request.form['endereco' +
                                                       str(c.enderecos[i].id)]
                c.enderecos[i].numero = request.form['numero' +
                                                     str(c.enderecos[i].id)]
                c.enderecos[i].cep = request.form['cep' +
                                                  str(c.enderecos[i].id)]

            print(c.telefones[0].telefone)
            insertEdit(c)

        else:
            print(request.form)
            c.nome = request.form['nome']
            c.email = request.form['email']
            t.telefone = request.form['telefone']
            e.endereco = request.form['endereco']
            e.numero = request.form['numero']
            e.cep = request.form['cep']

            c.telefones.append(t)
            c.enderecos.append(e)

            insertEdit(t)
            insertEdit(e)
            insertEdit(c)

        return redirect(url_for('listar'))

    elif request.method == 'GET':

        return render_template("cadastro.html", c=c, telefones=telefones)
Beispiel #7
0
def curateConversationWCorrectAnswer(idCV):
    try:
        conversation: Conversation = getCvById(idCV)
        conversation.classify = 0.31
        intent: Intent = conversation.intent
        patt = Pattern()    
        patt.pattern = conversation.question
        intent.patterns.append(patt)
        insertEdit(intent)

        addConversation(conversation)

        
        return returnOk()


    except exc.SQLAlchemyError:
        import sys
        print(sys.exc_info())
        return errorResp()
Beispiel #8
0
def insertSingleIntent():
    intentJson = request.get_json()
    print(intentJson)

    intent = Intent()
    intent.tag = intentJson['tag']

    for pattJson in intentJson['patterns']:
        patt = Pattern()
        print(pattJson['pattern'])
        patt.pattern = pattJson['pattern']
        intent.patterns.append(patt)


    try:
        print(intent)
        insertEdit(intent)
        return returnOk()

    except exc.SQLAlchemyError:
        return errorResp()
Beispiel #9
0
def curateConversation(idCV,idIntent):
    try:
        conversation: Conversation = getCvById(idCV)

        intent: Intent = getSingleIntent(idIntent)
        patt = Pattern()    
        patt.pattern = conversation.question
        intent.patterns.append(patt)
        insertEdit(intent)


        intent = getSingleIntent(idIntent)
        conversation.intent = intent
        addConversation(conversation)

        
        return returnOk()


    except exc.SQLAlchemyError:
        import sys
        print(sys.exc_info())
        return errorResp()