Skip to content

Commit

Permalink
allow user to remove data based on fields
Browse files Browse the repository at this point in the history
  • Loading branch information
bvreede committed Jan 4, 2024
1 parent 1fcf684 commit 31f0357
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
11 changes: 10 additions & 1 deletion sktalk/corpus/conversation.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def summary(self, n=10, **kwargs):
kwargs (dict): key-value pairs with which specific utterances can be selected
"""
selected = self.select(**kwargs)
for u in selected._utterances[:n]:
for u in selected.utterances[:n]:
if len(u.time) != 2:
time = "(no timing information)"
else:
Expand All @@ -164,6 +164,15 @@ def select(self, **kwargs):
utterances = [Utterance(**fields) for fields in utterances]
return Conversation(utterances, suppress_warnings=True)

def remove(self, **kwargs):
"""Remove utterances based on content in specific fields
Args:
kwargs (dict): key-value pairs with which specific utterances can be selected
"""
to_remove = self.select(**kwargs)
self._utterances = [u for u in self._utterances if u not in to_remove._utterances]

def asdict(self):
"""
Return the Conversation as a dictionary
Expand Down
8 changes: 8 additions & 0 deletions tests/corpus/test_conversation.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ def test_conversation_summary(self, convo, capfd):
captured = capfd.readouterr()
assert captured.out.strip() == "(5500 - 7500) C: '6 utterance F'"

def test_conversation_remove(self, convo, convo_meta):
assert convo.n_utterances == 10
convo.remove(participant = "A")
assert convo.n_utterances == 7
# metadata is unaffected
assert convo.metadata == convo_meta
convo.remove(time = None)
assert convo.n_utterances == 6

class TestConversationMetrics:
@pytest.mark.parametrize("args, error",
Expand Down

0 comments on commit 31f0357

Please sign in to comment.