Skip to main content

The Home Assistant Intent Language parser

Project description

HassIL

The Home Assistant Intent Language (HassIL) parser for intents.

Dependencies

  • antlr4-python3-runtime
  • PyYAML
  • dataclasses-json

Installation

Run the script/setup script to automatically create a virtual environment and install the requirements.

Running

python3 -m hassil <yaml_file_or_directory> [<yaml_file_or_directory> ...]

Once loaded, you may type in a sentence and see what intent it matches. For example:

python3 -m hassil examples/en.yaml --areas 'living room'
what is the temperature in the living room
{'intent': 'HassClimateGetTemperature', 'area': 'living room', 'domain': 'climate'}

Make sure to provide area names with --areas. Device or entity names can be provided with --names.

python3 -m hassil examples/en.yaml --areas office --names trapdoor
open the trapdoor in the office
{'intent': 'HassOpenCover', 'name': 'trapdoor', 'area': 'office'}

Sampling Sentences

Sentences for each intent can be sampled from the intent YAML files:

python3 -m hassil.sample examples/en.yaml -n 1
{"intent": "HassTurnOn", "text": "turn on the entity"}
{"intent": "HassTurnOff", "text": "turn off the entity"}
{"intent": "HassOpenCover", "text": "open the entity in the area"}
{"intent": "HassCloseCover", "text": "close the entity in the area"}
{"intent": "HassLightsSet", "text": "set the entity color to red"}
{"intent": "HassClimateSetTemperature", "text": "set temperature to 0 degrees in the area"}
{"intent": "HassClimateGetTemperature", "text": "what is the temperature in the area"}

The --areas and --names arguments are the same from python3 -m hassil, but default to generic "area" and "entity" terms.

Exclude the -n argument to sample all possible sentences.

Sentence Templates

Uses a custom parser written in Python.

  • Alternative words or phrases
    • (red | green | blue)
    • turn(s | ed | ing)
  • Optional words or phrases
    • [the]
    • [this | that]
    • light[s]
  • Slot Lists
    • {list_name}
    • {list_name:slot_name}
    • Refers to a pre-defined list of values in YAML (lists)
  • Expansion Rules
    • <rule_name>
    • Refers to a pre-defined expansion rule in YAML (expansion_rules)

YAML Format

language: "<language code>"
intents:
  <intent name>:
    data:
      # List of sentences/slots/etc.
      - sentences:
          - "<sentence template>"
          - "<sentence template>"
        # Optional
        slots:
          # Fixed slots for the recognized intent
          <name>: <value>
        requires_context:
          # Must be present in match context
          <name>: # Any provided value is good
        excludes_context:
          # Must NOT be present in match context
          <name>: <value or list>

# Optional lists of items that become alternatives in sentence templates
lists:
  # Referenced as {list_name} or {list_name:slot_name}
  <list name>:
    values:
      - "items"
      - "in list"
      - in: "text in"
        out: <value for slot>
        # Optional
        context:
          <name>: <value>
  <range_name>
    range:
      type: "number"
      from: 0
      to: 100  # inclusive

# Optional rules that are expanded in sentence templates
expansion_rules:
  # Referenced as <rule_name>
  <rule_name>: "<sentence template>"

# Optional words that the intent recognizer can skip during recognition
skip_words:
  - "<word>"

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hassil-1.0.3.tar.gz (26.6 kB view details)

Uploaded Source

File details

Details for the file hassil-1.0.3.tar.gz.

File metadata

  • Download URL: hassil-1.0.3.tar.gz
  • Upload date:
  • Size: 26.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.2

File hashes

Hashes for hassil-1.0.3.tar.gz
Algorithm Hash digest
SHA256 4451398baf10ea4519827ce5ce85c45f330311f75d970858019082d3c7e036e0
MD5 fc37b904b19505d87b06b33c64f06559
BLAKE2b-256 cb9ea9e884cc8d23f0d58656edef62a29b65c024f2984dd0bc1cc565094a108e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page