跳转到主要内容

Home Assistant 意图语言解析器

项目描述

HassIL

用于意图的Home Assistant意图语言(HassIL)解析器。

依赖项

  • PyYAML

安装

运行script/setup脚本来自动创建虚拟环境和安装依赖项。

运行

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

加载后,您可以输入一个句子并查看它匹配的意图。例如

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

请确保使用--areas提供区域名称。设备或实体名称可以使用--names提供。

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

采样句子

可以从意图YAML文件中采样每个意图的句子

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"}

python3 -m hassil中的--areas--names参数相同,但默认为通用的“区域”和“实体”术语。

省略-n参数以采样所有可能的句子。

句子模板

使用用Python编写的自定义解析器。

  • 可选的单词或短语
    • (红色 | 绿色 | 蓝色)
    • 变成(s | ed | ing)
  • 可选的单词或短语
    • [the]
    • [this | that]
    • 灯[s]
  • 单词或短语的排列
    • (耐心;你必须有)我的年轻的学徒
    • 是[the]灯(开;在中)
  • 槽位列表
    • {list_name}
    • {list_name:slot_name}
    • 指代在YAML中预定义的值列表(在lists中),可以是全局的或局部的(特定于句子所指的意图)
  • 扩展规则
    • <rule_name>
    • 指代在YAML中预定义的扩展规则(在expansion_rules中),可以是全局的或局部的(特定于句子所指的意图)

YAML格式

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>
        expansion_rules:
          # Expansion rules which only apply to the intent, referenced as <rule_name>
          <rule_name>: <sentence template>
        lists:
          # Lists which apply only to the current set of sentences, referenced as {list_name} or {list_name:slot_name}
          <list name>:
            values:
              # See below for other possible types
              - "items"
              - "in list"
        metadata:
          # Arbitrary key/value pairs that will be available in the result
          <key>: <value>

# 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>
        metadata:
          # Arbitrary key/value pairs that will be available in the result
          <key>: <value>
  <range_name>
    range:
      type: "number"
      from: 0
      to: 100  # inclusive
      multiplier: 1.0  # multiply to get final value
  <wildcard_name>
    wildcard: true

# 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>"

项目详情


下载文件

下载您平台上的文件。如果您不确定选择哪一个,请了解更多关于安装包的信息。

源分布

hassil-1.7.4.tar.gz (40.6 kB 查看哈希值)

上传时间

构建分布

hassil-1.7.4-py3-none-any.whl (33.0 kB 查看哈希值)

上传时间 Python 3

由以下支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面