Search code examples
watson-conversation

Watson Conversation: condition matching input to context array


Taking the car dashboard example, I altered the initial @genre node to be @genre:classical. I also added a list to the contex

"choices":["Beethoven","Mahler 9","Brahms 3rd"]

and the Watson response is "I have 3 selections". The condition on the next node is $choices.contains(input.text). The "Found a match" response is just for testing. It looks like this:

enter image description here

When I test this in the api tool and type "Beethoven" both "Found a match" and "Great choice!..." appear. Same for the other two choices, but only if I type the exact choice, e.g., "Mahler 9". Typing "Mahler" or "mahler" doesn't get a match. I read through the SpEL documentation but couldn't see a way in a one-line condition to parse through the list looking for partial matches.

So my question is, is there an condition expression that would match partial user input, e.g., "Mahler"? I'll be using the Java SDK to code the app server, so alternatively I wondered if I could add a temporary @entity just for this sequence instead of using the context list then delete it when the conversation is done? Or is there a way to construct a more complex condition in the MessageRequest and will Watson recognize it? Or is this just not the right way to go about this? Any pointers, examples or docs much appreciated.


Solution

  • So my question is, is there an condition expression that would match partial user input

    You can't add temporary entities or intents. As adding them forces Watson to start training itself (even if you could it through code).

    You can however create quite complex regular expressions, pass them in as a context variable.

    For example your advanced node can have:

    {
      "output": {
        "text": "Please ask me a question."
      },
      "context": {
        "rx": "fish|[0-9]+"
      }
    }
    

    Then in you condition you would write.

    input.text.matches(context.rx)
    

    This will then trigger if the person mentions a number, or the word fish. So you can create your partial user input checking that way.