From ac26a785dfdf87a776ec7848a9196377d63ff3f5 Mon Sep 17 00:00:00 2001 From: Reuben Morais Date: Tue, 18 Feb 2020 12:15:23 +0100 Subject: [PATCH] Add a better __repr__ for Metadata objects in Python bindings --- native_client/python/impl.i | 17 +++++++++++++++++ native_client/python/setup.py | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/native_client/python/impl.i b/native_client/python/impl.i index e1644a35..d6c7ba19 100644 --- a/native_client/python/impl.i +++ b/native_client/python/impl.i @@ -46,6 +46,23 @@ import_array(); } %} +%extend struct MetadataItem { +%pythoncode %{ + def __repr__(self): + return 'MetadataItem(character=\'{}\', timestep={}, start_time={})'.format(self.character, self.timestep, self.start_time) +%} +} + +%extend struct Metadata { +%pythoncode %{ + def __repr__(self): + items_repr = ', \n'.join(' ' + repr(i) for i in self.items) + return 'Metadata(confidence={}, items=[\n{}\n])'.format(self.confidence, items_repr) +%} +} + +%ignore Metadata::num_items; + %extend struct Metadata { ~Metadata() { DS_FreeMetadata($self); diff --git a/native_client/python/setup.py b/native_client/python/setup.py index b07aa603..b5a5d95b 100755 --- a/native_client/python/setup.py +++ b/native_client/python/setup.py @@ -64,7 +64,7 @@ def main(): include_dirs=[numpy_include, '../'], library_dirs=list(map(lambda x: x.strip(), lib_dirs_split(os.getenv('MODEL_LDFLAGS', '')))), libraries=list(map(lambda x: x.strip(), libs_split(os.getenv('MODEL_LIBS', '')))), - swig_opts=['-c++', '-keyword', '-builtin']) + swig_opts=['-c++', '-keyword']) setup(name=project_name, description='A library for running inference on a DeepSpeech model',