in libraries/botbuilder-ai/botbuilder/ai/luis/luis_recognizer_v3.py [0:0]
def _map_properties(self, source, in_instance):
if isinstance(source, (int, float, bool, str)):
return source
result = source
if isinstance(source, list):
narr = []
for item in source:
is_geography_v2 = ""
if (
isinstance(item, dict)
and "type" in item
and item["type"] in self._geographySubtypes
):
is_geography_v2 = item["type"]
if not in_instance and is_geography_v2:
geo_entity = {}
for item_props in item:
if item_props == "value":
geo_entity["location"] = item[item_props]
geo_entity["type"] = is_geography_v2
narr.append(geo_entity)
else:
narr.append(self._map_properties(item, in_instance))
result = narr
elif not isinstance(source, str):
nobj = {}
if (
not in_instance
and isinstance(source, dict)
and "type" in source
and isinstance(source["type"], str)
and source["type"] in self._dateSubtypes
):
timexs = source["values"]
arr = []
if timexs:
unique = []
for elt in timexs:
if elt["timex"] and elt["timex"] not in unique:
unique.append(elt["timex"])
for timex in unique:
arr.append(timex)
nobj["timex"] = arr
nobj["type"] = source["type"]
else:
for property in source:
name = self._normalize(property)
is_array = isinstance(source[property], list)
is_string = isinstance(source[property], str)
is_int = isinstance(source[property], (int, float))
val = self._map_properties(
source[property], in_instance or property == self._metadata_key
)
if name == "datetime" and is_array:
nobj["datetimeV1"] = val
elif name == "datetimeV2" and is_array:
nobj["datetime"] = val
elif in_instance:
if name == "length" and is_int:
nobj["endIndex"] = source[name] + source["startIndex"]
elif not (
(is_int and name == "modelTypeId")
or (is_string and name == "role")
):
nobj[name] = val
else:
if name == "unit" and is_string:
nobj["units"] = val
else:
nobj[name] = val
result = nobj
return result