Get the index of the entity item selected

I’m using the Button template on an entity node and populating the options list within the code (not using the enumerated item list from type dropdown menu). Is there a way to get directly the index of the item selected by user, writing something like context.entities.entity_name.get_index?

Francesco,
What is the type of the entity that you are using?

Note that templates are a presentation aspect, and buttons are only a means to shortcut typing. All that a button does is simulate the user typing something in. The buttons do not necessarily have to correspond to the values accepted by the entity, they could be a subset (of the most important items), or they could be totally different (e.g. “discard”). And of course a user can always type/speak something and not press a button at all.

Andy,
I understand and agree with your statement. I was trying to find a workaround to a possible bug: I’m passing to the button template a list of strings, my strings usually contain a substring with a fraction (eg “1/2” or “1/6”), when I select one button for some reason I get back the same string with a space between the first number and the slash, something like “1 /2”. I could replace the spaces, but I don’t understand why this space is added?

Punctuation is tricky within NLP, particularly because people don’t normally speak it. The first step in any NLP pipeline is to tokenize the utterance into sentences and words. Sentence terminators are period, question mark and exclamation mark but within a sentence then other punctuation characters are generally treated as their own word and will be split apart from the surrounding characters.

Now there are exceptions to this splitting for known character sequences, for example dates and times, where the sequence is left untouched.

I am curious about your situation because “1/2” is actually a known sequence, meaning a half, and has a canonical value of “0.5”. So the questions I have are:

  1. Are you working in English or some other language?
  2. What entity type are you using?
  1. In US english, the fractions indicate volume measurement; 2.I’m using a string type in the entity, the items are displayed correctly in the button, the space is added when I retrieve the value.

If there are a known set of valid values for the entity, then you should really use a List of Values entity.

A string entity accept anything and everything, there is no validation and it is greedy - that is it won’t know when to stop when the user says something beyond what is needed for the current entity.

This is my scenario: using an user parameter we send a request to an api and we get back an array from a set of more than 10K records and we prompt the user a button list with usually 2 or 3 options. I think that a great update for the platform would be to have the possibility to populate dynamically the list type in entities.

The platform has had the ability to dynamically set the choices for an enumerated List of Values entity. All you need to do is to store the list, as an array of objects, somewhere in context and then set the names of that array and the names of the appropriate keys in the object.

But if you have 10K choices, then that is probably not the best course. In which case you can try the remote lookup variation: select List of Values (lookup) as the entity type and then change the source to a remote list and provide the details of an endpoint that can validate a value.