0

for e.g. "show me an image of Eiffel tower" ... so i want Eiffel tower to be stored in the variable. that is i want any word after "of" to be stored. how to do this? . Thanks in advance.

Vinay Nair
  • 41
  • 3

2 Answers2

1

Simple way to do this is by creating an entity which contains values like Eiffel Tower. Then you can store that in any context variable.

{
  "context": {
    "xyz":"@Place"
  },
  "output": {}
}

Here Place is your entity.You can use your context variable anywhere.

Rohit
  • 187
  • 6
  • then how would i do this - " show me the imdb rating of iron man"... want that movie name "iron man" to be stored in a variable – Vinay Nair Feb 23 '18 at 18:27
  • U need to create a entity of movie names. – Rohit Feb 26 '18 at 05:32
  • no i am not. This is the right way to do this.Your method is incorrect.Suppose if your text contains 2 times "of" then what will u do? – Rohit Mar 31 '18 at 09:01
0

You can use regular expressions to capture entity values from user input. To capture the one or two words after of, use of ([a-z]+\s*[a-z]+) as the regular expression. Regular expressions are called patterns in WCS. Here is how a definition could look:

entity recognition using regular expressions

Then save the what the user says into the context variable using:

{
  "context": {
    "thing": "<? @thing.groups[1] ?>"
  }
}

To test it you can use the context variable in an answer, for example:

{
  "output": {
    "text": {
      "values": [
        "Getting a picture of $thing"
      ]
    }
  }
}

More information can be found at: https://console.bluemix.net/docs/services/conversation/entities.html#defining-entities

matsair
  • 51
  • 1
  • 5