ASRResult
- class ase2sprkkr.asr.core.results.ASRResult(data={}, metadata={}, strict=None)[source]
Base class for describing results generated with recipes.
A results object is a container for results generated with ASR. It contains data and metadata describing results and the circumstances under which the result were generated, respectively. The metadata has to be set manually through the
metadata
property. The wrapped data can be accessed through thedata
property or directly as an attribute on the object.The result object provides the means of presenting the wrapped data in different formats as obtained from the
get_formats
method. To implement a new webpanel, inherit from this class and overwrite theformats
dictionary appropriately.This object implements dict/namespace like default behaviour and contained data can be check with
in
(see “Examples” below).Examples
>>> @prepare_result ... class Result(ASRResult): ... a: int ... key_descriptions = {'a': 'Some key description.'} >>> result = Result.fromdata(a=1) >>> result.metadata = {'resources': {'time': 'a good time.'}} >>> result.a 1 >>> result['a'] 1 >>> result.metadata resources={'time': 'a good time.'} >>> str(result) 'a=1' >>> 'a' in result True >>> other_result = Result.fromdata(a=1) >>> result == other_result True >>> print(format(result, 'json')) { "object_id": "asr.core.results::Result", "constructor": "asr.core.results::Result", "args": [], "kwargs": { "data": { "a": 1 }, "metadata": { "resources": { "time": "a good time." } }, "strict": true } }
Class hierarchy
Constructor
- Parameters:
data (Dict[str, Any])
metadata (Dict[str, Any])
strict (bool | None)
- __init__(data={}, metadata={}, strict=None)[source]
Instantiate result.
- Parameters:
data (Dict[str, Any]) – Input data to be wrapped.
metadata (dict) – Dictionary containing metadata.
strict (bool or None) – Strictly enforce data entries in data.
- version: int = 0
- prev_version: Any = None
- key_descriptions: Dict[str, str]
- formats = {'dict': <ase2sprkkr.asr.core.results.DictEncoder object>, 'html': <ase2sprkkr.asr.core.results.HTMLEncoder object>, 'json': <ase2sprkkr.asr.core.results.JSONEncoder object>, 'str': <class 'str'>}
- strict = False
- property data: dict
Get result data.
- format_as(format='', *args, **kwargs)[source]
Format result in specific format.
- Parameters:
format (str)
- Return type:
Any