Skip to content

Commit

Permalink
count number of participants
Browse files Browse the repository at this point in the history
  • Loading branch information
bvreede committed Nov 21, 2023
1 parent c0593cb commit 319ca96
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 30 deletions.
28 changes: 10 additions & 18 deletions sktalk/corpus/conversation.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,25 +120,17 @@ def _subconversation(self,
"`time_or_index` must be either 'time' or 'index'")
return Conversation(utterances=returned_utterances)

# TODO should metadata be part of this?
return Conversation(returned_utterances, self.metadata)

def _time_to_next(self) -> int:
# if len(self.utterances) != 2:
# return None
try:
return self.utterances[0].until(self.utterances[1])
except (TypeError, IndexError):
return None

def _dyadic(self) -> bool:
participants = [u.participant for u in self.utterances]
return len(set(participants)) == 2
def _count_participants(self) -> int:
"""Count the number of participants in a conversation
Importantly: if one of the utterances has no participant, it is counted
as a separate participant (None).
CONVERSATION_FUNCTIONS = {
"dyadic": _dyadic,
"time_to_next": _time_to_next,
}
Returns:
int: number of participants
"""
participants = [u.participant for u in self.utterances]
return len(set(participants))

def apply(self, field, **kwargs):
"""
Expand Down
18 changes: 6 additions & 12 deletions tests/corpus/test_conversation.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,9 @@ def test_overlap(self):
assert not Conversation.overlap(
70, 80, [90, 110]) # utterance after window

def test_dyadic(self, convo):
assert not convo._dyadic()
convo2 = convo.subconversation(0, 2)
assert convo2._dyadic()
convo3 = convo.subconversation(0)
assert not convo3._dyadic()

def test_apply_dyadic(self, convo):
convo.apply("dyadic", before=1)
assert convo.utterances[0].dyadic
assert convo.utterances[2].dyadic
assert not convo.utterances[8].dyadic
def test_count_participants(self, convo):
assert convo._count_participants() == 3
convo2 = convo._subconversation(index=0, before=2)
assert convo2._count_participants() == 2
convo3 = convo._subconversation(index=0)
assert convo3._count_participants() == 1

0 comments on commit 319ca96

Please sign in to comment.