Use default when an optional tag is not present

I’d like to match

how is the weather today    -> day: today
how is the weather tomorrow -> day: tomorrow
how is the weather          -> day: today

This is what I came up with:

day = ((today|tomorrow){day} | (:){day:today})
how is the weather <day>

Is that correct?

This part would match also other words.


This should work the way you intended.

day = ((today|tomorrow){day} | ( ){day:today})
how is the weather <day>

you can also do things like this if i remeber correctly:

day = ((today|tomorrow| :today){day} 

or what i often when i have multiple words for one option which also should be the drfault option.

day = ((today| this day| ):today | tomorrow){day} 

I dont have acess to my setup at the moment so i could not test the first 2 variants. You can always use the web interface to test just the intent recognition.

Why not make the day optional?

day = (today|tomorrow){day}
how is the weather [<day>]

Then in your intent handler check if the slot has a value, if not, assume today.

The you get:

or when no day

Sure, I could do that, but then it would be off topic here. :yum:

Sorry, I do not understand your comment. What is offtopic?

I offer a solution by making the day slot optional :slight_smile:
Works fine and no complicated stuff in the sentences.ini

I just moves the complicated stuff from Rhasspy to the intent handler.

Yup, and that is where is belongs IMHO.
The sentences should reflect what you actually say and not add functionality.
So, when no day is spoken, let the intent handler decide what to do with it and keep the spoken sentence clean.

That way, you can add extra thing to the intenthandler when no day is spoken, a 4 day forecast or something like that.

just my 2 cents :slight_smile:


I have the following intent like yours but with integer arguments:

last_hours = ((1..24){last_hours!int} | ( ){last_hours:12!int})
what was the weather [the last] <last_hours> [hours]

then when I speak the sentence:

what was the weather

I get a 'No intent recognized'.

but when I hit the "Recognize" button, the intent is recognized !

Where is the error? (with a string argument like your example it works well)