Search code examples
pythonazurebotframeworkchatbotazure-language-understanding

How to access the entity value in Luis


I want to print the value of the entity that is already defined in the Luis portal, I already printed the TopIntent but I need to access the entity and print the value of it


Solution

  • As per MS doc:

    You can get entity and subentities, for example:

    modelObject = client.model.get_entity(app_id, versionId, modelId)
    toppingQuantityId = get_grandchild_id(modelObject, "Toppings", "Quantity")
    pizzaQuantityId = get_grandchild_id(modelObject, "Pizza", "Quantity")
    

    If you want to get the prediction from the runtime, for example:

    # Production == slot name
    predictionRequest = { "query" : "I want two small pepperoni pizzas with more salsa" }
    
    predictionResponse = clientRuntime.prediction.get_slot_prediction(app_id, "Production", predictionRequest)
    print("Top intent: {}".format(predictionResponse.prediction.top_intent))
    print("Sentiment: {}".format (predictionResponse.prediction.sentiment))
    print("Intents: ")
    
    for intent in predictionResponse.prediction.intents:
        print("\t{}".format (json.dumps (intent)))
    print("Entities: {}".format (predictionResponse.prediction.entities))
    

    You can refer to How to extract entity from Microsoft LUIS using python?