Digital Assistant and Mobile

Get Involved. Join the Conversation.

Topic

    Luc Bors
    How do I get the name of an entity?
    Topic posted August 24, 2018 by Luc BorsRed Ribbon: 250+ Points, tagged Bots 
    82 Views, 12 Comments
    Title:
    How do I get the name of an entity?
    Content:

    Hi,

    I have a question regarding entities. I have 2 entities, each containing a list of hotels. The entities are called hotelsAreaOne and hotelsAreaTwo. They are all connected to an intent called "staying". When the user types: I am staying at hotel "hotelInAreaOne" the intent resolves correctly to "staying". The expression ${iResult.value.entityMatches['hotelsAreaOne'][0]} returns 'hotelInAreaOne' which is just fine. In the JSON I can also see this works fine:

    "entityMatches": {
      "hotelsAreaOne": [
         "hotelInAreaOne"
        ]
      }
    

    However, what I would like to get hold of, is the actual value of the entity itself, in this case 'hotelsAreaOne'. Not sure if this is possible, but curious to know how to do this.

    Thanks

    Comment

     

    • Ameur Baccoucha

      i think that you can use here the component: "System.MatchEntity"
       

      matchEntity:
          component: "System.MatchEntity"
          properties:
            # sourceVariable refers to the user or context variable that holds the text that potentially contains information that can be extracted by an entity.
            sourceVariable: 
            # variable refers to the user or context variable that is used to store the matched entity value.
            variable: 
          transitions:
            actions:
              match: 
              nomatch:

    • Luc Bors

      Hi Ameur,

      Thanks for your reply. I know that as an alternative I could use 2 individual System.matchEntity states. And this does work, and I used it as a workaround.

      However, in the real life bot I have currently 5 "hotelsArea" entities, which results in 5 ocurences of System.SetVariable followed by System.MatchEntity. Because for every nomatch I need to do a new  ${iResult.value.entityMatches['hotelsArea<X>'][0]} and a new system.MatchEntity.

      So this is getting a bit ugly. Thats why I rather have direct access to the Entityname itself, and use one System.SetVariable followed by a system.Switch.

      Don't know if this makes sense, but to me it seems like something one would like to do?

      Thanks

    • Ameur Baccoucha

      if i get you it will better to use an entity with a list of your entities names (yourhotelsentities: [hotelsArea1,hotelsArea2.....]).
      After that use the ${iResult.value.entityMatches['yourhotelsentities'][0]} to get the name and you can after that use the switch like you wish.

       

      • Luc Bors

        Hmmm,

        still no success. Here is what happens when I use an entity (Hotels) with a list of entities like this:

        HotelsEntity:
          "HotelsAreaOneEntity": "hotelInAreaOne", "anotherHotelInAreaOne"
          "HotelsAreaTwoEntity": "hotelInAreaTwo", "anotherHotelInAreaTwo"  
          "HotelsAreaThreeEntity": "hotelInAreaThree", "anotherHotelInAreaThree"
        

        When the user types: I am staying at hotel "anotherHotelInAreaTwo -->  ${iResult.value.entityMatches['HotelsEntity'][0]}  it still returns me "anotherHotelInAreaTwo" where I would expect "HotelsAreaTwoEntity".

        Looks like I am a tricked here. 

        Any explanation?

        Thanks

         

         

        • Ameur Baccoucha

          can you please share the payload here ? 

          • Luc Bors

            Here you go. It says it all. Resolves to entities content, and even child entities content:


                    "messagePayload": {
                      "layout": "vertical",
                      "cards": [<<OMITTED>>],
                      "type": "card",
                      "channelExtensions": {
                        "debugInfo": {
                          "variables": {
                            "profile.updatedOn": "2018-08-27T08:14:14.374Z",
                            "system.invalidUserInput": false,
                            "profile.lastName": "myName",
                            "theDate": {
                              "date": 1535364854000,
                              "entityName": "DATE",
                              "originalString": "Aug 27, 2018 10:14:14 AM"
                            },
                            "greeting": null,
                            "iResult": {
                              "timeStamp": 1535357654441,
                              "intentMatches": {
                                "summary": [
                                  {
                                    "score": 1,
                                    "intent": "Staying"
                                  }
                                ],
                                "detail": {
                                  "final_norm": [
                                    {
                                      "sentence": [],
                                      "score": 1,
                                      "intent": "Staying"
                                    }
                                  ]
                                }
                              },
                              "trainingDataUnit": null,
                              "botName": "Hotels bot",
                              "appId": "XXXXXX",
                              "query": "I am staying at hotel at area two",
                              "entityMatches": {
                                "HotelsAreaTwoEntity": [
                                  "hotel at area two"
                                ],
                                "HotelsEntity": [
                                  "hotel at area two"
                                ]
                              }
                            },
                            "user.botsUserError": false,
                            "profile.locale": "en-US",
                            "rb": null,
                            "theHotelArea": "hotel at area two",
                            "profile.timezoneOffset": -7200000,
                            "hotels": null,
                            "profile.firstName": "myFirstName",
                            "name": null,
                            "defaultDateInput": "Aug 27, 2018 10:14:14 AM",
                            "system.processedUserMessage": false
                          },
                          "currentDialogState": "acOtherHotels",
                          "executedStates": [
                            "setHotelsArea",
                            "printYourNowVar",
                            "switchHotelArea",
                            "acOtherHotels"
                          ]
                        }
                      }
                    },
                    "userId": "<omitted>"
                  }

    • Luc Bors

      Ah very nice,

      that might just work. I will try that later today and let you know.

      Thanks

    • Luc Bors

      Hi Ameur,

      Thanks for your help. It works. It uses a different approach.

      I was expecting entity with list of entities. The working solution uses a value list entity with canonical names and synonyms. So as listed below:

      HotelsEntity:
        --> value --> "HotelsAreaOne" --> synonyms --> "hotelInAreaOne", "anotherHotelInAreaOne"
      
      
        --> value --> "HotelsAreaTwo" --> synonyms --> "hotelInAreaTwo", "anotherHotelInAreaTwo" 
      
      
        --> value --> "HotelsAreaThree" --> synonyms --> "hotelInAreaThree", "anotherHotelInAreaThree"
      
      

      When the user types: I am staying at hotel "anotherHotelInAreaTwo -->  ${iResult.value.entityMatches['HotelsEntity'][0]}  returns "HotelsAreaTwo"

      Thanks