Beispiel #1
0
def update_content():
    """
    Updates the manual collection with new content.
    """
    json_input_data = json.loads(request.data)
    id = json_input_data["data"]["id"]
    content = json_input_data["data"]["content"]

    lemmatize_content_keywords(content)

    status = factory.get_database().get_collection("manual").update({"id": id}, {"$set": {
        "content": content}})
    if status["updatedExisting"] is False:
        # If the document wasn't already in the manual db then we need to copy the automatic one
        # first.
        document = next(factory.get_collection("prod").find({"id": id}), None)
        document["content"] = content
        factory.get_database().get_collection("manual").insert_one(document)

    # set manually_changed to true.
    factory.get_database().get_collection("prod").update({"id": id}, {"$set": {
        "manually_changed": True}})

    # delete this document from the conflict ids collection
    factory.get_database().get_collection("conflict_ids").delete_one({"conflict_id": id})
    return flask_util.create_success_response("Success")
Beispiel #2
0
def delete_unknown_query():
    """
    This function simply deletes a query from the unknown_query collection.
    :return: A success json if it was successful.
    """
    json_input_data = json.loads(request.data)
    query_text = json_input_data["data"]["query_text"]
    factory.get_database().get_collection("unknown_queries").delete_one({"query_text": query_text})
    return flask_util.create_success_response("Successfully deleted an unknown query.")
Beispiel #3
0
def batch_delete_entities_post():
    json_input_data = json.loads(request.data)
    entity_ids = json_input_data["data"]

    try:
        batch_delete_entities(entity_ids)
        # Since reponse is an operation/ future object we don't really have
        # anything to return here.
        return util.create_success_response("Batch deleted entities.")
    except google_exceptions.FailedPrecondition as e:
        raise InvalidDialogFlowID(str(e), status_code=400)
Beispiel #4
0
def batch_create_entities_post():
    json_input_data = json.loads(request.data)
    entity_types = json_input_data["data"]

    try:
        ID_list = batch_create_entities(entity_types)
        return util.create_success_response("Batch created entities.",
                                            data=ID_list)
    except google_exceptions.FailedPrecondition as e:
        # Entity with same name exception.
        raise InvalidDialogFlowID(str(e), status_code=400)
Beispiel #5
0
def delete_manual_document():
    """
    This function deletes a document from the manual collection
    """
    json_input_data = json.loads(request.data)
    document_id = json_input_data["data"]["id"]
    factory.get_database().get_collection("manual").delete_one({"id": document_id})
    factory.get_database().get_collection("prod").update({"id": document_id}, {"$set": {
        "manually_changed": False}})
    factory.get_database().get_collection("conflict_ids").delete_one({"conflict_id": document_id})
    return flask_util.create_success_response("Successfully deleted manual entry")
Beispiel #6
0
def batch_create_intents_post():
    json_input_data = json.loads(request.data)
    intents = json_input_data["data"]

    try:
        # Since response from batch_create_intents is an operation/ future
        # object we don't really have anything to return here. So just a
        # simple counter, so atleast we know how many intents we created.
        counter = batch_create_intents(intents)
        return util.create_success_response("Batch created " + str(counter) +
                                            " intents.")
    except google_exceptions.FailedPrecondition as e:
        # Intent with same name exception.
        raise InvalidDialogFlowID(str(e), status_code=400)
Beispiel #7
0
def create_intent_post():
    json_input_data = json.loads(request.data)
    try:
        intent_name = json_input_data["intent_name"]
    except KeyError:
        return "Could not find intent_name"

    try:
        training_phrases = json_input_data["training_phrases"]
    except KeyError:
        training_phrases = []

    try:
        intent = create_intent(intent_name, training_phrases)
        return util.create_success_response("Intent created", data=intent.name)
    except google_exceptions.FailedPrecondition as e:
        # Intent with same name exception.
        raise InvalidDialogFlowID(str(e), status_code=400)
Beispiel #8
0
def test():
    return util.create_success_response("Success")