Am trying to get normalized value that is extracted using duckling for duration but am facing this error

You need to pass a string in the utter_message method, but you are passing an object.

how can we do that?

I need to know what’s in the variable data2. Can you show me what’s in that variable? I think it’s an integer

here is the extracted value using duckling

the “normalized” property is an object that has the value:

  "value": 7200,
  "unit": "second"

You are passing this object as a parameter in the utter_message method, but it expects to receive a string. Do you want to show the seconds of a certain duration?

yes,i want rasa to catch that then i want to store it to the database

try this:

data2 = entity_val["normalized"]
dispatcher.utter_message(f"{data2["value"]} {data2["unit"]}")

For this example, your output will be:

User input: “2 hours”

Output: “7200 seconds”

thank you but here it says unexpected token

Hmm. I tried to reproduce your scenario and I succeeded.

yes i aslo suceed with that one too…ofcourse i get the value …but here am trying to get the next value which is the normalized one …not the 2 which is in hour but the one in second…did you get me this are the values that duckling the duckling has extracted for me and if you see the picture there are 3 values for 2 hours

I think that the get_latest_entity_values() method does not return the normalized value.

To get the normalized text, I think you should use the tracker.latest_message["entities"] property and filter by the entity duration.

how can we do that?

like this:

ow ysysysysyssysysysysyyayayayayayayyayayayyayayya

data = tracker.latest_message["entities"]
print('1>', data)

 #If there are other entities in the list, it will be filtered to return only entities of type "duration"
data = list(filter(
  lambda entity: entity['entity'] == "duration", 
print('2>', data)

if data:
  normalized = data[0]["additional_info"]["normalized"]
  print('3>', normalized["value"], normalized["unit"])
  dispatcher.utter_message(text=f"{normalized['value']} {normalized['unit']}")
  dispatcher.utter_message(text="Entity not found")

god bless you heheheh

1 Like

worked for me thank you so much

1 Like

great! :smiley:

here i get the value using dispatcher…what if i want to store it to database?..