Himanshu,
That pattern does not quite how the composite entity works. Let me describe how it does and what you can do to fix your test case.
When a composite entity is reached in the dialog flow then all of the subentities mentioned in any of the composite entities patterns are identified. It is quite possible for different composite entity patterns to contain different combinations of subentities, and in different orders. Each composite entity pattern describes a relationship (in terms of word order) between the subentities, and as patterns are evaluated in order then you might want to relax the need for some of the subentities if the full set are not found.
Once we have the complete set of subentities then we final all possible instances of those subentities, independently of what the composite entity patterns look like, and we record where those are.
Then we go back to the composite entity patterns and evaluate each one to identify the specific set of subentity instances that match that specific pattern until we get a match.
What that means is that the composite entity pattern is not used to identify the subentities. So in your example “my first name is @firstName and last name is @lastName” is not used to find each of those subentities, which means that each of the subentities will match the entire string, and that is why the composite entity is empty in your scenario.
(The reason for not using the composite entity pattern in the subentity identification is that patterns can be far more complex than just a sequence of words.)
So to fix your test case, then do these things:
-
On the firstName entity, add the pattern: first name is * [ and , > ]
-
On the lastName entity, add the pattern: last name is * [ and , > ]
-
Change the composite entity pattern to: << @firstName @lastName >>
Now there’s all kinds of special syntax in there that helps to reduce the number of patterns, and you could have other “simpler” patterns that deal with each scenario individually, but let me explain them.
First adding a pattern to a subentity, and strings especially because they can match anything and everything, helps to define where the value starts and stops. So “first name is”, as you know, will say that the entity value will start after these words.
The piece enclosed in square brackets means that one of the “tokens” inside the brackets has to be present for this pattern to match - a mandatory choice. This provides an end point for the string, and those endpoints are either the word “and”, a comma, or the end of the sentence - “>” means sentence end.
Without the mandatory choice then the default end point will be the end of the sentence, so you would never need to write “last name is * >
” - the “>” is implied. But when you have a choice after the asterisk then you have to include the sentence end as a viable option (and as the last item in the choice because there is an ordering to the choices).
Using patterns like this for the subentities means that those names can be supplied in any order, e.g. “my last name is Goel, my first name is Himanshu”, and also allows for additional words to be placed before, in between or after each of those phrases.
The composite entity pattern is enclosed in double angle brackets, << and >>, and those mean match all of the enclosed “tokens” but in any order and with any number of words between them. The composite entity doesn’t care about how we determined a firstName and a lastName, just that both of them have been found in the sentence. You can choose to not have the brackets, in which case the firstName must be strictly before the lastName, but being too restrictive means that some utterances will not match.
One final point about patterns is that the platform actually tests each pattern several times with an increasing number of wildcards between each token. So we start off seeing if the firstName is directly followed by lastName, then we try with 1 extra word between them, then 2 extra words. This is why in this case I am suggesting to enclose the subentities in double angle brackets because you could say “my first name is Himanshu and then my last name is Goel” - there are a lot of words between Himanshu and Goel. You can easily conceive of other variations with even more words between them.