From 347387e784aee39972cb87764986bca298c30b0f Mon Sep 17 00:00:00 2001 From: Michael Hansen Date: Wed, 26 Jul 2023 15:24:21 -0500 Subject: [PATCH] Update template syntax for hassil 1.2 (#1862) --- .../template-sentence-syntax.md | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/docs/voice/intent-recognition/template-sentence-syntax.md b/docs/voice/intent-recognition/template-sentence-syntax.md index 709c5fb0..a7749fd7 100644 --- a/docs/voice/intent-recognition/template-sentence-syntax.md +++ b/docs/voice/intent-recognition/template-sentence-syntax.md @@ -131,6 +131,26 @@ lists: out: 1 ``` +#### Wildcards + +Wildcard lists can match any text, for example: + +```yaml +language: en +intents: + PlayAlbum: + data: + - sentences: + - play {album} by {artist} +lists: + artist: + wildcard: true + album: + wildcard: true +``` + +will match sentences such as "play the white album by the beatles". The `PlayAlbum` intent will have an `album` slot with "the white album " (note the trailing whitespace) and an `artist` slot with "the beatles". + ### Expansion Rules A lot of template sentences can be written in a similar way. To avoid having to repeat the same matching structure multiple times, we can define expansion rules. For example, a user might add "the" in front of the area name, or they might not. We can define an expansion rule to match both cases. @@ -146,6 +166,45 @@ expansion_rules: turn: "(turn | switch)" ``` +#### Local Expansion Rules + +Expansion rules can also be defined locally next to a list of sentences, and will only be available within those templates. This allows you to write similar templates for different situations. For example: + +```yaml +language: en +intents: + GetLocked: + data: + - sentences: + - is the door + requires_context: + domain: binary_sensor + expansion_rules: + state: "{binary_state}" + + - sentences: + - is the door + requires_context: + domain: lock + expansion_rules: + state: "{lock_state}" + +lists: + binary_state: + values: + - in: "locked" + out: "off" + - in: "unlocked" + out: "on" + lock_state: + values: + - "locked" + - "unlocked" + +``` + +The same template `is the door ` is used for both binary sensors and regular locks, but the local `state` expansion rules refer to different lists. + ### Skip Words Skip words are words that the intent recognizer will skip during recognition. This is useful for words that are not part of the intent, but are commonly used in sentences. For example, a user might use the word "please" in a sentence, but it is not part of the intent.