| 1 | """API for home_assistant_intents package.""" |
| 2 | |
| 3 | import importlib.resourcesscip-python python python-stdlib 3.11 `importlib.resources`/__init__: |
| 4 | import jsonscip-python python python-stdlib 3.11 json/__init__: |
| 5 | import osscip-python python python-stdlib 3.11 os/__init__: |
| 6 | import typingscip-python python python-stdlib 3.11 typing/__init__: |
| 7 | from dataclassesscip-python python python-stdlib 3.11 dataclasses/__init__: import dataclassscip-python python python-stdlib 3.11 dataclasses/dataclass(). |
| 8 | from enumscip-python python python-stdlib 3.11 enum/__init__: import Enumscip-python python python-stdlib 3.11 enum/Enum# |
| 9 | from pathlibscip-python python python-stdlib 3.11 pathlib/__init__: import Pathscip-python python python-stdlib 3.11 pathlib/Path# |
| 10 | from typingscip-python python python-stdlib 3.11 typing/__init__: import IOscip-python python python-stdlib 3.11 typing/IO#, Anyscip-python python python-stdlib 3.11 typing/Any., Callablescip-python python python-stdlib 3.11 typing/Callable., Collectionscip-python python python-stdlib 3.11 typing/Collection#, Dictscip-python python python-stdlib 3.11 typing/Dict., Listscip-python python python-stdlib 3.11 typing/List., Optionalscip-python python python-stdlib 3.11 typing/Optional., Setscip-python python python-stdlib 3.11 typing/Set., Tuplescip-python python python-stdlib 3.11 typing/Tuple. |
| 11 | |
| 12 | |
| 13 | from .languagesscip-python python home-assistant-intents 2026.3.3 languages/__init__: import LANGUAGESscip-python python home-assistant-intents 2026.3.3 `home_assistant_intents.languages`/LANGUAGES. |
| 14 | |
| 15 | _PACKAGEscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/_PACKAGE. = "home_assistant_intents" |
| 16 | _DIRscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/_DIR. = Pathscip-python python python-stdlib 3.11 pathlib/Path#(typingscip-python python python-stdlib 3.11 typing/__init__:.castscip-python python python-stdlib 3.11 typing/cast().(osscip-python python python-stdlib 3.11 os/__init__:.PathLikescip-python python python-stdlib 3.11 os/PathLike#, importlib.resourcesscip-python python python-stdlib 3.11 `importlib.resources`/__init__:.files(_PACKAGEscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/_PACKAGE.))) |
| 17 | _DATA_DIRscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/_DATA_DIR. = _DIRscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/_DIR. / "data" |
| 18 | _FUZZY_DIRscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/_FUZZY_DIR. = _DIRscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/_DIR. / "fuzzy" |
| 19 | |
| 20 | |
| 21 | class ErrorKeyscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/ErrorKey#(strscip-python python python-stdlib 3.11 builtins/str#, Enumscip-python python python-stdlib 3.11 enum/Enum#): |
| 22 | """Keys for home assistant intent errors.""" |
| 23 | |
| 24 | NO_INTENTscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/ErrorKey#NO_INTENT. = "no_intent" |
| 25 | """Intent was not recognized.""" |
| 26 | |
| 27 | HANDLE_ERRORscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/ErrorKey#HANDLE_ERROR. = "handle_error" |
| 28 | """Unexpected error while handling intent.""" |
| 29 | |
| 30 | NO_AREAscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/ErrorKey#NO_AREA. = "no_area" |
| 31 | """Area does not exist.""" |
| 32 | |
| 33 | NO_FLOORscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/ErrorKey#NO_FLOOR. = "no_floor" |
| 34 | """Floor does not exist.""" |
| 35 | |
| 36 | NO_DOMAINscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/ErrorKey#NO_DOMAIN. = "no_domain" |
| 37 | """No devices exist for a domain.""" |
| 38 | |
| 39 | NO_DOMAIN_EXPOSEDscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/ErrorKey#NO_DOMAIN_EXPOSED. = "no_domain_exposed" |
| 40 | """No devices are exposed for a domain.""" |
| 41 | |
| 42 | NO_DOMAIN_IN_AREAscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/ErrorKey#NO_DOMAIN_IN_AREA. = "no_domain_in_area" |
| 43 | """No devices in an area exist for a domain.""" |
| 44 | |
| 45 | NO_DOMAIN_IN_AREA_EXPOSEDscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/ErrorKey#NO_DOMAIN_IN_AREA_EXPOSED. = "no_domain_in_area_exposed" |
| 46 | """No devices in an area are exposed for a domain.""" |
| 47 | |
| 48 | NO_DOMAIN_IN_FLOORscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/ErrorKey#NO_DOMAIN_IN_FLOOR. = "no_domain_in_floor" |
| 49 | """No devices in an floor exist for a domain.""" |
| 50 | |
| 51 | NO_DOMAIN_IN_FLOOR_EXPOSEDscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/ErrorKey#NO_DOMAIN_IN_FLOOR_EXPOSED. = "no_domain_in_floor_exposed" |
| 52 | """No devices in an floor are exposed for a domain.""" |
| 53 | |
| 54 | NO_DEVICE_CLASSscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/ErrorKey#NO_DEVICE_CLASS. = "no_device_class" |
| 55 | """No devices of a class exist.""" |
| 56 | |
| 57 | NO_DEVICE_CLASS_EXPOSEDscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/ErrorKey#NO_DEVICE_CLASS_EXPOSED. = "no_device_class_exposed" |
| 58 | """No devices of a class are exposed.""" |
| 59 | |
| 60 | NO_DEVICE_CLASS_IN_AREAscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/ErrorKey#NO_DEVICE_CLASS_IN_AREA. = "no_device_class_in_area" |
| 61 | """No devices of a class exist in an area.""" |
| 62 | |
| 63 | NO_DEVICE_CLASS_IN_AREA_EXPOSEDscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/ErrorKey#NO_DEVICE_CLASS_IN_AREA_EXPOSED. = "no_device_class_in_area_exposed" |
| 64 | """No devices of a class are exposed in an area.""" |
| 65 | |
| 66 | NO_DEVICE_CLASS_IN_FLOORscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/ErrorKey#NO_DEVICE_CLASS_IN_FLOOR. = "no_device_class_in_floor" |
| 67 | """No devices of a class exist in an floor.""" |
| 68 | |
| 69 | NO_DEVICE_CLASS_IN_FLOOR_EXPOSEDscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/ErrorKey#NO_DEVICE_CLASS_IN_FLOOR_EXPOSED. = "no_device_class_in_floor_exposed" |
| 70 | """No devices of a class are exposed in an floor.""" |
| 71 | |
| 72 | NO_ENTITYscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/ErrorKey#NO_ENTITY. = "no_entity" |
| 73 | """Entity does not exist.""" |
| 74 | |
| 75 | NO_ENTITY_EXPOSEDscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/ErrorKey#NO_ENTITY_EXPOSED. = "no_entity_exposed" |
| 76 | """Entity is not exposed.""" |
| 77 | |
| 78 | NO_ENTITY_IN_AREAscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/ErrorKey#NO_ENTITY_IN_AREA. = "no_entity_in_area" |
| 79 | """Entity does not exist in area.""" |
| 80 | |
| 81 | NO_ENTITY_IN_AREA_EXPOSEDscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/ErrorKey#NO_ENTITY_IN_AREA_EXPOSED. = "no_entity_in_area_exposed" |
| 82 | """Entity in area is not exposed.""" |
| 83 | |
| 84 | NO_ENTITY_IN_FLOORscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/ErrorKey#NO_ENTITY_IN_FLOOR. = "no_entity_in_floor" |
| 85 | """Entity does not exist in floor.""" |
| 86 | |
| 87 | NO_ENTITY_IN_FLOOR_EXPOSEDscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/ErrorKey#NO_ENTITY_IN_FLOOR_EXPOSED. = "no_entity_in_floor_exposed" |
| 88 | """Entity in floor is not exposed.""" |
| 89 | |
| 90 | DUPLICATE_ENTITIESscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/ErrorKey#DUPLICATE_ENTITIES. = "duplicate_entities" |
| 91 | """More than one entity matched with the same name.""" |
| 92 | |
| 93 | DUPLICATE_ENTITIES_IN_AREAscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/ErrorKey#DUPLICATE_ENTITIES_IN_AREA. = "duplicate_entities_in_area" |
| 94 | """More than one entity in an area matched with the same name.""" |
| 95 | |
| 96 | DUPLICATE_ENTITIES_IN_FLOORscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/ErrorKey#DUPLICATE_ENTITIES_IN_FLOOR. = "duplicate_entities_in_floor" |
| 97 | """More than one entity in an floor matched with the same name.""" |
| 98 | |
| 99 | FEATURE_NOT_SUPPORTEDscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/ErrorKey#FEATURE_NOT_SUPPORTED. = "feature_not_supported" |
| 100 | """Entity does not support a required feature.""" |
| 101 | |
| 102 | ENTITY_WRONG_STATEscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/ErrorKey#ENTITY_WRONG_STATE. = "entity_wrong_state" |
| 103 | """Entity is not in the correct state.""" |
| 104 | |
| 105 | TIMER_NOT_FOUNDscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/ErrorKey#TIMER_NOT_FOUND. = "timer_not_found" |
| 106 | """No timer matched the provided constraints.""" |
| 107 | |
| 108 | MULTIPLE_TIMERS_MATCHEDscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/ErrorKey#MULTIPLE_TIMERS_MATCHED. = "multiple_timers_matched" |
| 109 | """More than one timer targeted for an action matched the constraints.""" |
| 110 | |
| 111 | NO_TIMER_SUPPORTscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/ErrorKey#NO_TIMER_SUPPORT. = "no_timer_support" |
| 112 | """Voice satellite does not support timers.""" |
| 113 | |
| 114 | |
| 115 | @dataclassscip-python python python-stdlib 3.11 dataclasses/dataclass(). |
| 116 | class LanguageScoresscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/LanguageScores#: |
| 117 | """Support scores for a language from 0 (no support) to 3 (full support).""" |
| 118 | |
| 119 | cloudscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/LanguageScores#cloud.: intscip-python python python-stdlib 3.11 builtins/int# |
| 120 | focused_localscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/LanguageScores#focused_local.: intscip-python python python-stdlib 3.11 builtins/int# |
| 121 | full_localscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/LanguageScores#full_local.: intscip-python python python-stdlib 3.11 builtins/int# |
| 122 | |
| 123 | |
| 124 | def get_intentsscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/get_intents().( |
| 125 | languagescip-python python home-assistant-intents 2026.3.3 home_assistant_intents/get_intents().(language): strscip-python python python-stdlib 3.11 builtins/str#, |
| 126 | json_loadscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/get_intents().(json_load): Callablescip-python python python-stdlib 3.11 typing/Callable.[[IOscip-python python python-stdlib 3.11 typing/IO#[strscip-python python python-stdlib 3.11 builtins/str#]], Dictscip-python python python-stdlib 3.11 typing/Dict.[strscip-python python python-stdlib 3.11 builtins/str#, Anyscip-python python python-stdlib 3.11 typing/Any.]] = jsonscip-python python python-stdlib 3.11 json/__init__:.loadscip-python python python-stdlib 3.11 json/load()., |
| 127 | ) -> Optionalscip-python python python-stdlib 3.11 typing/Optional.[Dictscip-python python python-stdlib 3.11 typing/Dict.[strscip-python python python-stdlib 3.11 builtins/str#, Anyscip-python python python-stdlib 3.11 typing/Any.]]: |
| 128 | """Load intents by language.""" |
| 129 | intents_path = _DATA_DIRscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/_DATA_DIR. / f"{languagescip-python python home-assistant-intents 2026.3.3 home_assistant_intents/get_intents().(language)}.json" |
| 130 | if not intents_path.existsscip-python python python-stdlib 3.11 pathlib/Path#exists().(): |
| 131 | return None |
| 132 | |
| 133 | with intents_path.openscip-python python python-stdlib 3.11 pathlib/Path#open().(encodingscip-python python python-stdlib 3.11 pathlib/Path#open().(encoding)="utf-8") as intents_file: |
| 134 | return json_loadscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/get_intents().(json_load)(intents_file) |
| 135 | |
| 136 | |
| 137 | def get_languagesscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/get_languages().() -> Listscip-python python python-stdlib 3.11 typing/List.[strscip-python python python-stdlib 3.11 builtins/str#]: |
| 138 | """Return a list of available languages.""" |
| 139 | return LANGUAGESscip-python python home-assistant-intents 2026.3.3 `home_assistant_intents.languages`/LANGUAGES. |
| 140 | |
| 141 | |
| 142 | def get_language_scoresscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/get_language_scores().( |
| 143 | json_loadscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/get_language_scores().(json_load): Callablescip-python python python-stdlib 3.11 typing/Callable.[[IOscip-python python python-stdlib 3.11 typing/IO#[strscip-python python python-stdlib 3.11 builtins/str#]], Dictscip-python python python-stdlib 3.11 typing/Dict.[strscip-python python python-stdlib 3.11 builtins/str#, Anyscip-python python python-stdlib 3.11 typing/Any.]] = jsonscip-python python python-stdlib 3.11 json/__init__:.loadscip-python python python-stdlib 3.11 json/load()., |
| 144 | ) -> Dictscip-python python python-stdlib 3.11 typing/Dict.[strscip-python python python-stdlib 3.11 builtins/str#, LanguageScoresscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/LanguageScores#]: |
| 145 | """Get support scores by language.""" |
| 146 | scores_path = _DIRscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/_DIR. / "language_scores.json" |
| 147 | if not scores_path.existsscip-python python python-stdlib 3.11 pathlib/Path#exists().(): |
| 148 | return {} |
| 149 | |
| 150 | with scores_path.openscip-python python python-stdlib 3.11 pathlib/Path#open().(encodingscip-python python python-stdlib 3.11 pathlib/Path#open().(encoding)="utf-8") as scores_file: |
| 151 | scores_dict = json_loadscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/get_language_scores().(json_load)(scores_file) |
| 152 | return { |
| 153 | lang_key: LanguageScoresscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/LanguageScores#( |
| 154 | cloudscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/LanguageScores#cloud.=lang_scores.get("cloud", 0), |
| 155 | focused_localscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/LanguageScores#focused_local.=lang_scores.get("focused_local", 0), |
| 156 | full_localscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/LanguageScores#full_local.=lang_scores.get("full_local", 0), |
| 157 | ) |
| 158 | for lang_key, lang_scores in scores_dict.itemsscip-python python python-stdlib 3.11 builtins/dict#items().() |
| 159 | } |
| 160 | |
| 161 | |
| 162 | # ----------------------------------------------------------------------------- |
| 163 | |
| 164 | |
| 165 | @dataclassscip-python python python-stdlib 3.11 dataclasses/dataclass(). |
| 166 | class FuzzySlotCombinationInfoscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/FuzzySlotCombinationInfo#: |
| 167 | """Information about a fuzzy slot combination.""" |
| 168 | |
| 169 | context_areascip-python python home-assistant-intents 2026.3.3 home_assistant_intents/FuzzySlotCombinationInfo#context_area.: boolscip-python python python-stdlib 3.11 builtins/bool# |
| 170 | name_domainsscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/FuzzySlotCombinationInfo#name_domains.: Setscip-python python python-stdlib 3.11 typing/Set.[strscip-python python python-stdlib 3.11 builtins/str#] |
| 171 | |
| 172 | |
| 173 | @dataclassscip-python python python-stdlib 3.11 dataclasses/dataclass(). |
| 174 | class FuzzyConfigscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/FuzzyConfig#: |
| 175 | """Shared configuration for fuzzy matching.""" |
| 176 | |
| 177 | # intent -> (slot, slot) -> slot combo info |
| 178 | slot_combinationsscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/FuzzyConfig#slot_combinations.: Dictscip-python python python-stdlib 3.11 typing/Dict.[strscip-python python python-stdlib 3.11 builtins/str#, Dictscip-python python python-stdlib 3.11 typing/Dict.[Tuplescip-python python python-stdlib 3.11 typing/Tuple.[strscip-python python python-stdlib 3.11 builtins/str#, ...], FuzzySlotCombinationInfoscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/FuzzySlotCombinationInfo#]] |
| 179 | """info for all intent slot combinations.""" |
| 180 | |
| 181 | # list name -> [slot names] |
| 182 | slot_list_namesscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/FuzzyConfig#slot_list_names.: Dictscip-python python python-stdlib 3.11 typing/Dict.[strscip-python python python-stdlib 3.11 builtins/str#, Listscip-python python python-stdlib 3.11 typing/List.[strscip-python python python-stdlib 3.11 builtins/str#]] |
| 183 | """Mapping between list and slot names.""" |
| 184 | |
| 185 | |
| 186 | @dataclassscip-python python python-stdlib 3.11 dataclasses/dataclass(). |
| 187 | class FuzzyNgramModelscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/FuzzyNgramModel#: |
| 188 | """N-gram model for fuzzy matching.""" |
| 189 | |
| 190 | orderscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/FuzzyNgramModel#order.: intscip-python python python-stdlib 3.11 builtins/int# |
| 191 | """N-gram order.""" |
| 192 | |
| 193 | wordsscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/FuzzyNgramModel#words.: Dictscip-python python python-stdlib 3.11 typing/Dict.[strscip-python python python-stdlib 3.11 builtins/str#, intscip-python python python-stdlib 3.11 builtins/int#] |
| 194 | """Words to integer ids.""" |
| 195 | |
| 196 | database_pathscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/FuzzyNgramModel#database_path.: Pathscip-python python python-stdlib 3.11 pathlib/Path# |
| 197 | """Path to sqlite3 database file.""" |
| 198 | |
| 199 | |
| 200 | FuzzyLanguageResponsesscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/FuzzyLanguageResponses. = Dictscip-python python python-stdlib 3.11 typing/Dict.[strscip-python python python-stdlib 3.11 builtins/str#, Dictscip-python python python-stdlib 3.11 typing/Dict.[Tuplescip-python python python-stdlib 3.11 typing/Tuple.[strscip-python python python-stdlib 3.11 builtins/str#, ...], Dictscip-python python python-stdlib 3.11 typing/Dict.[strscip-python python python-stdlib 3.11 builtins/str#, strscip-python python python-stdlib 3.11 builtins/str#]]] |
| 201 | |
| 202 | |
| 203 | @dataclassscip-python python python-stdlib 3.11 dataclasses/dataclass(). |
| 204 | class FuzzyLanguageInfoscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/FuzzyLanguageInfo#: |
| 205 | """Language specific information for fuzzy matching.""" |
| 206 | |
| 207 | languagescip-python python home-assistant-intents 2026.3.3 home_assistant_intents/FuzzyLanguageInfo#language.: strscip-python python python-stdlib 3.11 builtins/str# |
| 208 | |
| 209 | # domain -> [keywords] |
| 210 | domain_keywordsscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/FuzzyLanguageInfo#domain_keywords.: Dictscip-python python python-stdlib 3.11 typing/Dict.[strscip-python python python-stdlib 3.11 builtins/str#, Listscip-python python python-stdlib 3.11 typing/List.[strscip-python python python-stdlib 3.11 builtins/str#]] |
| 211 | """Keywords that hint at a domain.""" |
| 212 | |
| 213 | # intent -> model |
| 214 | ngram_modelsscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/FuzzyLanguageInfo#ngram_models.: Dictscip-python python python-stdlib 3.11 typing/Dict.[strscip-python python python-stdlib 3.11 builtins/str#, FuzzyNgramModelscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/FuzzyNgramModel#] |
| 215 | """N-gram model for each intent.""" |
| 216 | |
| 217 | # intent -> (slot, slot) -> domain -> response |
| 218 | responsesscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/FuzzyLanguageInfo#responses.: FuzzyLanguageResponsesscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/FuzzyLanguageResponses. |
| 219 | """Response code mapping per slot combination.""" |
| 220 | |
| 221 | stop_wordsscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/FuzzyLanguageInfo#stop_words.: Optionalscip-python python python-stdlib 3.11 typing/Optional.[Collectionscip-python python python-stdlib 3.11 typing/Collection#[strscip-python python python-stdlib 3.11 builtins/str#]] = None |
| 222 | """Words that can be ignored if unknown.""" |
| 223 | |
| 224 | |
| 225 | def get_fuzzy_configscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/get_fuzzy_config().( |
| 226 | json_loadscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/get_fuzzy_config().(json_load): Callablescip-python python python-stdlib 3.11 typing/Callable.[[IOscip-python python python-stdlib 3.11 typing/IO#[strscip-python python python-stdlib 3.11 builtins/str#]], Dictscip-python python python-stdlib 3.11 typing/Dict.[strscip-python python python-stdlib 3.11 builtins/str#, Anyscip-python python python-stdlib 3.11 typing/Any.]] = jsonscip-python python python-stdlib 3.11 json/__init__:.loadscip-python python python-stdlib 3.11 json/load()., |
| 227 | ) -> FuzzyConfigscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/FuzzyConfig#: |
| 228 | """Return shared configuration for fuzzy matching.""" |
| 229 | with openscip-python python python-stdlib 3.11 builtins/open().(_FUZZY_DIRscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/_FUZZY_DIR. / "config.json", "r", encodingscip-python python python-stdlib 3.11 builtins/open().(encoding)="utf-8") as config_file: |
| 230 | config_dict = json_loadscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/get_fuzzy_config().(json_load)(config_file) |
| 231 | |
| 232 | return FuzzyConfigscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/FuzzyConfig#( |
| 233 | slot_combinationsscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/FuzzyConfig#slot_combinations.={ |
| 234 | intent_name: { |
| 235 | tuplescip-python python python-stdlib 3.11 builtins/tuple#(sortedscip-python python python-stdlib 3.11 builtins/sorted().(combo_key_str.split())): FuzzySlotCombinationInfoscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/FuzzySlotCombinationInfo#( |
| 236 | context_areascip-python python home-assistant-intents 2026.3.3 home_assistant_intents/FuzzySlotCombinationInfo#context_area.=combo_info.get("context_area", False), |
| 237 | name_domainsscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/FuzzySlotCombinationInfo#name_domains.=setscip-python python python-stdlib 3.11 builtins/set#(combo_info.get("name_domains", [])), |
| 238 | ) |
| 239 | for combo_key_str, combo_info in intent_combos.items() |
| 240 | } |
| 241 | for intent_name, intent_combos in config_dict["slot_combinations"].items() |
| 242 | }, |
| 243 | slot_list_namesscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/FuzzyConfig#slot_list_names.=config_dict["slot_list_names"], |
| 244 | ) |
| 245 | |
| 246 | |
| 247 | def get_fuzzy_languagesscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/get_fuzzy_languages().() -> Setscip-python python python-stdlib 3.11 typing/Set.[strscip-python python python-stdlib 3.11 builtins/str#]: |
| 248 | """Return languages with fuzzy matching support.""" |
| 249 | return {lang_dir.namescip-python python python-stdlib 3.11 pathlib/PurePath#name(). for lang_dir in _FUZZY_DIRscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/_FUZZY_DIR..iterdirscip-python python python-stdlib 3.11 pathlib/Path#iterdir().() if lang_dir.is_dirscip-python python python-stdlib 3.11 pathlib/Path#is_dir().()} |
| 250 | |
| 251 | |
| 252 | def get_fuzzy_languagescip-python python home-assistant-intents 2026.3.3 home_assistant_intents/get_fuzzy_language().( |
| 253 | languagescip-python python home-assistant-intents 2026.3.3 home_assistant_intents/get_fuzzy_language().(language): strscip-python python python-stdlib 3.11 builtins/str#, |
| 254 | json_loadscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/get_fuzzy_language().(json_load): Callablescip-python python python-stdlib 3.11 typing/Callable.[[IOscip-python python python-stdlib 3.11 typing/IO#[strscip-python python python-stdlib 3.11 builtins/str#]], Dictscip-python python python-stdlib 3.11 typing/Dict.[strscip-python python python-stdlib 3.11 builtins/str#, Anyscip-python python python-stdlib 3.11 typing/Any.]] = jsonscip-python python python-stdlib 3.11 json/__init__:.loadscip-python python python-stdlib 3.11 json/load()., |
| 255 | ) -> Optionalscip-python python python-stdlib 3.11 typing/Optional.[FuzzyLanguageInfoscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/FuzzyLanguageInfo#]: |
| 256 | """Return fuzzy matching information for a language.""" |
| 257 | lang_fuzzy_dir = _FUZZY_DIRscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/_FUZZY_DIR. / languagescip-python python home-assistant-intents 2026.3.3 home_assistant_intents/get_fuzzy_language().(language) |
| 258 | lang_ngram_dir = lang_fuzzy_dir / "ngram" |
| 259 | |
| 260 | if not lang_ngram_dir.is_dirscip-python python python-stdlib 3.11 pathlib/Path#is_dir().(): |
| 261 | return None |
| 262 | |
| 263 | with openscip-python python python-stdlib 3.11 builtins/open().(lang_fuzzy_dir / "config.json", "r", encodingscip-python python python-stdlib 3.11 builtins/open().(encoding)="utf-8") as config_file: |
| 264 | lang_config = json_loadscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/get_fuzzy_language().(json_load)(config_file) |
| 265 | |
| 266 | ngram_models: Dictscip-python python python-stdlib 3.11 typing/Dict.[strscip-python python python-stdlib 3.11 builtins/str#, FuzzyNgramModelscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/FuzzyNgramModel#] = {} |
| 267 | for intent_ngram_path in lang_ngram_dir.globscip-python python python-stdlib 3.11 pathlib/Path#glob().("*.json"): |
| 268 | intent_db_path = intent_ngram_path.with_suffixscip-python python python-stdlib 3.11 pathlib/PurePath#with_suffix().(".db") |
| 269 | if not intent_db_path.existsscip-python python python-stdlib 3.11 pathlib/Path#exists().(): |
| 270 | continue |
| 271 | |
| 272 | with openscip-python python python-stdlib 3.11 builtins/open().(intent_ngram_path, "r", encodingscip-python python python-stdlib 3.11 builtins/open().(encoding)="utf-8") as intent_ngram_file: |
| 273 | intent_ngram_dict = json_loadscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/get_fuzzy_language().(json_load)(intent_ngram_file) |
| 274 | |
| 275 | intent_name = intent_ngram_path.stemscip-python python python-stdlib 3.11 pathlib/PurePath#stem(). |
| 276 | ngram_models[intent_name] = FuzzyNgramModelscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/FuzzyNgramModel#( |
| 277 | orderscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/FuzzyNgramModel#order.=intent_ngram_dict["order"], |
| 278 | wordsscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/FuzzyNgramModel#words.=intent_ngram_dict["words"], |
| 279 | database_pathscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/FuzzyNgramModel#database_path.=intent_db_path, |
| 280 | ) |
| 281 | |
| 282 | with openscip-python python python-stdlib 3.11 builtins/open().( |
| 283 | lang_fuzzy_dir / "responses.json", "r", encodingscip-python python python-stdlib 3.11 builtins/open().(encoding)="utf-8" |
| 284 | ) as responses_file: |
| 285 | lang_responses_dict = json_loadscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/get_fuzzy_language().(json_load)(responses_file) |
| 286 | lang_responses = { |
| 287 | intent_name: { |
| 288 | tuplescip-python python python-stdlib 3.11 builtins/tuple#(sortedscip-python python python-stdlib 3.11 builtins/sorted().(combo_key_str.split())): domain_responses |
| 289 | for combo_key_str, domain_responses in intent_responses.items() |
| 290 | } |
| 291 | for intent_name, intent_responses in lang_responses_dict.itemsscip-python python python-stdlib 3.11 builtins/dict#items().() |
| 292 | } |
| 293 | |
| 294 | return FuzzyLanguageInfoscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/FuzzyLanguageInfo#( |
| 295 | languagescip-python python home-assistant-intents 2026.3.3 home_assistant_intents/FuzzyLanguageInfo#language.=languagescip-python python home-assistant-intents 2026.3.3 home_assistant_intents/get_fuzzy_language().(language), |
| 296 | domain_keywordsscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/FuzzyLanguageInfo#domain_keywords.=lang_config["domain_keywords"], |
| 297 | stop_wordsscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/FuzzyLanguageInfo#stop_words.=lang_config.getscip-python python python-stdlib 3.11 builtins/dict#get().("stop_words"), |
| 298 | ngram_modelsscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/FuzzyLanguageInfo#ngram_models.=ngram_models, |
| 299 | responsesscip-python python home-assistant-intents 2026.3.3 home_assistant_intents/FuzzyLanguageInfo#responses.=lang_responses, |
| 300 | ) |