diff --git a/sktalk/corpus/conversation.py b/sktalk/corpus/conversation.py index b10f8be..df00c92 100644 --- a/sktalk/corpus/conversation.py +++ b/sktalk/corpus/conversation.py @@ -1,6 +1,6 @@ import os import json -from dataclasses import asdict + class Conversation: def __init__( @@ -46,6 +46,12 @@ def summarize(self): for utterance in self._utterances[:10]: print(utterance) + def asdict(self): + utt_list = [u.asdict() for u in self._utterances] + conv_dict = self._metadata.copy() + conv_dict["Conversation"] = utt_list + return conv_dict + def write_json(self, name, directory): """ Write a conversation to a JSONL file. @@ -58,7 +64,7 @@ def write_json(self, name, directory): name = f"{name}.jsonl" destination = os.path.join(directory, name) - utt_list = [asdict(u) for u in self._utterances] + utt_list = [u.asdict() for u in self._utterances] conv_dict = self._metadata.copy() conv_dict["Conversation"] = utt_list diff --git a/sktalk/corpus/utterance.py b/sktalk/corpus/utterance.py index 57b7c96..afcf8de 100644 --- a/sktalk/corpus/utterance.py +++ b/sktalk/corpus/utterance.py @@ -15,6 +15,8 @@ class Utterance: def get_audio(self): pass + def asdict(self): + return asdict(self) # TODO function: that prints summary of data, shows it to user # TODO function: create a pandas data frame with the utterances