Add a better __repr__ for Metadata objects in Python bindings

This commit is contained in:
Reuben Morais 2020-02-18 12:15:23 +01:00
parent 1c69d93b4e
commit ac26a785df
2 changed files with 18 additions and 1 deletions

View File

@ -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);

View File

@ -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',