snipsco / snips-issues

Feel free to share your bugs with us.
14 stars 5 forks source link

Feature request - Hermes-python - return the original sentence snippet with the slot #182

Closed flatsiedatsie closed 5 years ago

flatsiedatsie commented 5 years ago

Is your feature request related to a problem? Please describe. I am happily using extracted slots. But in some cases it can be useful to have the snippet from the original sentence that the slot was based on.

For example, if a user asks a timer to be set for tomorrow morning at 9 am, the time slots data that arrives in python is the date as a standardized datetime string. E.g. 06-03-2019 09:34:12.

This string is useful for turning the time into a time object. But it also means that I cannot easily 'parrot back' the time as the user originally spoke it. My app will now say "I have set a timer for 9 o'clock". I'd like it to parrot what the user said: "I have set a timer for tomorrow morning at 9 am".

This would have a number of advantages.

What are the use cases of this feature It would allow developers more flexibility in how they respond to the user, how they translate their sentence, etc.

Describe the solution you'd like It would be great if the slots data (intent_message.slots.slot_name_here) could also contain the original snippet somewhere.

Describe alternatives you've considered Snips does already provide the complete input string (intent_message.input). I could try to extract the time value from that manually. But when exploring that option I was overwhelmed by the complexity of it. Snips already knows what part of the sentence I'm looking for, so I feel it would make more sense if Snips supplies it.

Additional context I hope I haven't overlooked it.

davidleroy commented 5 years ago

Actually you can access the raw_value of the slot using the same syntax as the one used in the documentation e.g intent_msg.slots.slot1.first().raw_value

The API reference lists all fields accessible at the slot level.

flatsiedatsie commented 5 years ago

Ah, I was hoping I had overlooked it. Thanks!

flatsiedatsie commented 5 years ago

@davidleroy I really can't get that to work. When I go a dir, vars or str of the first() on a duration slot the value simply isn't there? It's just a normal datetime-like object?

--DIR intent_message duration = ['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'days', 'from_c_repr', 'hours', 'minutes', 'months', 'precision', 'quarters', 'seconds', 'weeks', 'years']

The documentation does seem to mention a raw value in hermes_python.ontology.dialogue.slot.NluSlot, but I don't seem to have the dialogue part of the tree.

Another user on the Forum mentioned something similar: https://forum.snips.ai/t/two-issues-and-1-question-with-python-snippets/724

Ah, I found it.

This does work: intent_message.slots.duration[0].raw_value

flatsiedatsie commented 5 years ago

@davidleroy I'm trying to get the raw value from a "from-to" time. I've tried everything, but I can't get at the raw value. Could you help in determining the correct path?


                    try:
                        print("RAW1: " + str( intent_message.slots.end_time[0].to_date.raw_value))
                        #time_data.to_date
                    except:
                        print("no1")
                    try:
                        print("RAW2: " + str( intent_message.slots.end_time.to_date.raw_value))
                        #time_data.to_date
                    except:
                        print("no2")
                    try:
                        print("RAW3: " + str( intent_message.slots.end_time[0].raw_value))
                        #time_data.to_date
                    except:
                        print("no3")
                    try:
                        print("RAW4: " + str( intent_message.slots.end_time.first().raw_value))
                        #time_data.to_date
                    except:
                        print("no4")
                    try:
                        print("RAW5: " + str( intent_message.slots.end_time.first()[0].raw_value))
                        #time_data.to_date
                    except:
                        print("no5")
anthonyray commented 5 years ago

Hi @flatsiedatsie ,

You can obtain the raw value of your "from-to" time slot with the following method :

intent_message.slots.end_time[0].raw_value

Don't hesitate to check out the tutorial for accessing slots in the documentation.