SMap containers are the Speect Engine equivalent of the Python dict type. The Python SMap class is just an interface to the Speect Engine C SMap type. Python SMap objects can not be instantiated, however, it can be a return value of certain functions or class attributes (for example SVoice.features).
A map class, an abstract data type composed of a collection of unique keys (strings) and a collection of values, where each key is associated with one value.
Note
The SMap object inherits from SObject in the Speect Engine and can therefore be used in functions/methods that require parameters of type SObject.
SMap supports the following Python dict operations:
len(m)
Return the number of items in the map m.
m[key]
Return the item of m with key key. Raises a KeyError if key is not in the map.
m[key] = value
Set m[key] to value.
del m[key]
Remove m[key] from m. Raises a KeyError if key is not in the map.
key in m
Return True if m has a key key, else False.
key not in m
Equivalent to not key in m.
for key in m
SMap also supports the Python iterator protocol and therefore one can iterate over a map’s keys.
str(m)
SMap supports the Python method __str__() and can therefore be used in the str() built-in function and by the print statement to compute the “informal” string representation of the map.
value_get(key)
Get the raw SObject value in the map that is associated with the given key. This function can be used in place of the normal:
map['key']
The reason for this is that the above will try to convert the returned value into a Python object if possible. Sometimes we want the value as a Speect object. So instead we can use this function:
map.value_get('key')
which will return the value object as it is in Speect, i.e. an SObject.
Parameters: | key (str) – The key of the key-value pair to get. |
---|---|
Returns: | The value associated with the given key or None if no such key-value pair. |
Return type: | SObject |