arrayswatsonwatson-conversationslot

How to store literals using @entity.values on Slot IBM Conversation Service?


I'm trying use slots on my dialog nodes on Watson conversation but seems that is not properly useful if you want to play with array of literal. I've an entity "@email" that is a pattern so I must use .literal if I want to store the "real value", that is sent by the user, on a context variable. Trouble starts when I try to use @entity.values to store all values that are sent by the user. Actually is not possible to store an array of literals and I'm stuck at this point.

Anyone developed a workaround for this?


Solution

  • The literal is a method, not an attribute. The entities contains a location field, which you can programatically use at the application layer to parse the input text.

    If you want to pull them out in conversation, you can use a counter to walk through the entities.

    For example:

    In your slot node "Then respond with" add the following context bit.

      "context": {
        "counter": "<? entities.size() ?>",
        "literals": ""
      },
    

    Next create three child nodes.

    Node 1: Create a dummy node, set condition to true. Have it jump to the second node.

    Node 2: For the second node, set the condition to $counter > 0 and add the following code to the JSON section.

      "context": {
        "counter": "<? $counter - 1 ?>",
        "literals": "<? entities[$counter].literal + ',' + $literals ?>"
      },
    

    Have it jump back to Node 1. The reason for this is Conversation will not allow you to jump to the same node.

    Node 3: Have it output the answer. For example: Literal Values: $literals

    Here is a sample workspace.

    https://pastebin.com/xwgnLq9n

    Warning

    Watson Conversation has a built in endless loop detection. If a node is hit 50 times in one request, it will throw the following error:

    Detected recursion when processing the node with id
    [node_20_1513835954092]. This node has been already processed [50] times
    in this execution step
    

    At which point the node will fail and you will get no result back. So if you expect more than 50 entities then you need to do this at the application layer.