Debian Codegraph @

README.md

raw
1 # HassIL
2
3 The Home Assistant Intent Language (HassIL) parser for [intents](https://github.com/OHF-Voice/intents).
4
5 [Template syntax](docs/template_syntax.md)
6
7 ## Dependencies
8
9 * PyYAML
10
11
12 ## Installation
13
14 Run the `script/setup` script to automatically create a virtual environment and install the requirements.
15
16
17 # Running
18
19 ``` sh
20 python3 -m hassil <yaml_file_or_directory> [<yaml_file_or_directory> ...]
21 ```
22
23 Once loaded, you may type in a sentence and see what intent it matches.
24 For example:
25
26 ``` sh
27 python3 -m hassil examples/en.yaml --areas 'living room'
28 what is the temperature in the living room
29 {'intent': 'HassClimateGetTemperature', 'area': 'living room', 'domain': 'climate'}
30 ```
31
32 Make sure to provide area names with `--areas`. Device or entity names can be provided with `--names`.
33
34 ``` sh
35 python3 -m hassil examples/en.yaml --areas office --names trapdoor
36 open the trapdoor in the office
37 {'intent': 'HassOpenCover', 'name': 'trapdoor', 'area': 'office'}
38 ```
39
40
41 ### Sampling Sentences
42
43 Sentences for each intent can be sampled from the intent YAML files:
44
45 ``` sh
46 python3 -m hassil.sample examples/en.yaml -n 1
47 {"intent": "HassTurnOn", "text": "turn on the entity"}
48 {"intent": "HassTurnOff", "text": "turn off the entity"}
49 {"intent": "HassOpenCover", "text": "open the entity in the area"}
50 {"intent": "HassCloseCover", "text": "close the entity in the area"}
51 {"intent": "HassLightsSet", "text": "set the entity color to red"}
52 {"intent": "HassClimateSetTemperature", "text": "set temperature to 0 degrees in the area"}
53 {"intent": "HassClimateGetTemperature", "text": "what is the temperature in the area"}
54 ```
55
56 The `--areas` and `--names` arguments are the same from `python3 -m hassil`, but default to generic "area" and "entity" terms.
57
58 Exclude the `-n` argument to sample all possible sentences.
59
60
61 ## Sentence Templates
62
63 Uses a custom parser written in Python.
64
65 * Alternative words or phrases
66 * `(red|green|blue)`
67 * `turn(s|ed|ing)`
68 * Optional words or phrases
69 * `[the]`
70 * `[this|that]`
71 * `light[s]`
72 * Permutations of words or phrases
73 * `(patience; you must have) my young Padawan`
74 * `is [the] light (on; in <area>)`
75 * Slot Lists
76 * `{list_name}`
77 * `{list_name:slot_name}`
78 * Refers to a pre-defined list of values in YAML (`lists`), either global or local (particular to the intent to which the sentence refers)
79 * Expansion Rules
80 * `<rule_name>`
81 * Refers to a pre-defined expansion rule in YAML (`expansion_rules`), either global or local (particular to the intent to which the sentence refers)
82
83
84 ## YAML Format
85
86 ``` yaml
87 language: "<language code>"
88 intents:
89 <intent name>:
90 data:
91 # List of sentences/slots/etc.
92 - sentences:
93 - "<sentence template>"
94 - "<sentence template>"
95 # Optional
96 slots:
97 # Fixed slots for the recognized intent
98 <name>: <value>
99 requires_context:
100 # Must be present in match context
101 <name>: # Any provided value is good
102 excludes_context:
103 # Must NOT be present in match context
104 <name>: <value or list>
105 expansion_rules:
106 # Expansion rules which only apply to the intent, referenced as <rule_name>
107 <rule_name>: <sentence template>
108 lists:
109 # Lists which apply only to the current set of sentences, referenced as {list_name} or {list_name:slot_name}
110 <list name>:
111 values:
112 # See below for other possible types
113 - "items"
114 - "in list"
115 metadata:
116 # Arbitrary key/value pairs that will be available in the result
117 <key>: <value>
118
119 # Optional lists of items that become alternatives in sentence templates
120 lists:
121 # Referenced as {list_name} or {list_name:slot_name}
122 <list name>:
123 values:
124 - "items"
125 - "in list"
126 - in: "text in"
127 out: <value for slot>
128 # Optional
129 context:
130 <name>: <value>
131 metadata:
132 # Arbitrary key/value pairs that will be available in the result
133 <key>: <value>
134 <range_name>
135 range:
136 type: "number"
137 from: 0
138 to: 100 # inclusive
139 multiplier: 1.0 # multiply to get final value
140 <wildcard_name>
141 wildcard: true
142
143 # Optional rules that are expanded in sentence templates
144 expansion_rules:
145 # Referenced as <rule_name>
146 <rule_name>: "<sentence template>"
147
148 # Optional words that the intent recognizer can skip during recognition
149 skip_words:
150 - "<word>"
151 ```
152
153 ### Inline Range Lists
154
155 Within a sentence template, you can create a range list inline with the format `{start..end,[step]:slot_name}`. For example:
156
157 ``` yaml
158 language: "en"
159 intents:
160 SetBrightness:
161 data:
162 - sentences:
163 - "set brightness to {0..100:brightness}"
164 ```
165
166 During matching, a range list from 0 to 100 will be available and its value will be stored in the `brightness` slot.
167
168 An optional step can be used as well:
169
170 ``` yaml
171 language: "en"
172 intents:
173 StartTimer:
174 data:
175 - sentences:
176 - "start timer for {10..100,10:seconds} seconds"
177 ```
178
179 This range list goes from 10 to 100 in steps of 10, so the sentence "start timer for 11 seconds" will not be recognized.