def responseActions(): try: ''' Get URL-encoded parameters that are given in the form of the string list "...?a=i1,i2,i3...". makeList returns python list of strings of the parameters. The query combines two tables, thus query generated from the ORM model is somehow complex, using join, and filters. Serialization is customized as well, since the result of the query combines fields from the two models. ''' params=request.args.get('action_ids') params=utils.makeList(params) data=models.Response.query.join(models.Action, models.Response.action_id==models.Action.action_id)\ .filter(models.Response.action_id.in_(params))\ .add_columns(models.Action.action_name).all() results=[item[0].serialize() for item in data] for i, item in enumerate(results): item.update({'action_name': data[i][1]}) return jsonify(results) except Exception as e: return(str(e))
def intentExpressionQuery(): try: data=request.args.get('intent_ids') params=utils.makeList(data) expressions=models.Expression.query.filter(\ models.Expression.intent_id.in_(params)).all() return jsonify([e.serialize() for e in expressions]) except Exception as e: return(str(e))
def variantsSynonyms(synonyms_ids): try: params = utils.makeList(synonyms_ids) variants=models.SynonymVariant.query.filter(\ models.SynonymVariant.synonym_id.in_(params)).all() return jsonify([v.serialize() for v in variants]) except Exception as e: return (str(e))
def parameterExpressionTrain(): try: data=request.args.get('expression_ids') params=utils.makeList(data) parameters=db.session.query(models.t_expression_parameters)\ .filter(models.t_expression_parameters\ .c.expression_id.in_(params)).all() return jsonify([models.Helper\ .serializeStatic(p) for p in parameters]) except Exception as e: return(str(e))
def operation9(): try: data=request.get_json() entity_id=request.args.get('entity_id') messageIds=utils.makeList(request.args.get('messageIds')) res=db.session.query(models.MessagesEntity).filter(db.and_( models.MessagesEntity.message_id.in_(messageIds), models.MessagesEntity.entity_id==entity_id, )).all() for e in res: e.update(data) db.session.commit() return utils.result('success', 'Updated entities') except Exception as e: db.session.rollback() return(str(e))