Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Participant is not initialised correctly when loading from JSON #261

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions dialoguekit/utils/dialogue_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def user_act_ratio(self) -> Dict[str, float]:

for dialogue in self._dialogues:
for utterance in dialogue.utterances:
sender = str(utterance.participant)
sender = utterance.participant.name
statistics[sender] += 1

if len(statistics.keys()) > 2:
Expand Down Expand Up @@ -152,10 +152,12 @@ def reward(self) -> Dict[str, List[Dict[str, float]]]:

# Start dialogue with Agent first.
for j, utterance in enumerate(dialogue.utterances):
if utterance.participant == DialogueParticipant.AGENT.name:
if utterance.participant == DialogueParticipant.AGENT:
dialogue_utterances_start_agent: List[
AnnotatedUtterance
] = dialogue.utterances[j:]
] = dialogue.utterances[
j:
] # type: ignore[assignment]
break
previous_sender = dialogue_utterances_start_agent[0].participant
previous_intents = dialogue_utterances_start_agent[0].get_intents()
Expand Down Expand Up @@ -209,7 +211,7 @@ def _check_included_intents(self) -> Dict[str, Any]:
for utterance in dialogue.utterances:
if (
isinstance(utterance, AnnotatedUtterance)
and utterance.participant == DialogueParticipant.USER.name
and utterance.participant == DialogueParticipant.USER
):
intents = [
Intent(intent.label.split(".")[0])
Expand Down Expand Up @@ -244,7 +246,7 @@ def _user_agent_ratio(self, results: Dict[str, Any]) -> Dict[str, Any]:
num_user_acts = sum(
1
for utterance in dialogue.utterances
if utterance.participant == DialogueParticipant.USER.name
if utterance.participant == DialogueParticipant.USER
)
results["dialogues"][i]["user_turns"] = num_user_acts
results["dialogues"][i][
Expand Down
3 changes: 2 additions & 1 deletion dialoguekit/utils/dialogue_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from dialoguekit.core.feedback import BinaryFeedback, UtteranceFeedback
from dialoguekit.core.intent import Intent
from dialoguekit.core.slot_value_annotation import SlotValueAnnotation
from dialoguekit.participant import DialogueParticipant

_FIELD_UTTERANCE = "utterance"
_FIELD_DIALOGUE_ACTS = "dialogue_acts"
Expand Down Expand Up @@ -58,7 +59,7 @@ def json_to_annotated_utterance(
Returns:
An AnnotatedUtterance object representation of the json utterance.
"""
participant = json_utterance.get(_FIELD_PARTICIPANT)
participant = DialogueParticipant[json_utterance.get(_FIELD_PARTICIPANT)]

utterance_text = json_utterance.get(_FIELD_UTTERANCE)
utterance_id = json_utterance.get(_FIELD_UTTERANCE_ID)
Expand Down
5 changes: 3 additions & 2 deletions tests/utils/test_dialogue_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from dialoguekit.core.feedback import BinaryFeedback
from dialoguekit.core.intent import Intent
from dialoguekit.participant import DialogueParticipant
from dialoguekit.utils.dialogue_reader import json_to_dialogues


Expand All @@ -20,8 +21,8 @@ def test_json_to_dialogues() -> None:
assert dialogues[0].user_id == "TEST03"
assert dialogues[-1].agent_id == "Agent"
assert dialogues[-1].user_id == "User"
assert dialogues[0].utterances[0].participant == "USER"
assert dialogues[0].utterances[1].participant == "AGENT"
assert dialogues[0].utterances[0].participant == DialogueParticipant.USER
assert dialogues[0].utterances[1].participant == DialogueParticipant.AGENT
assert dialogues[0].utterances[0].get_intents() == [
Intent("DISCLOSE.NON-DISCLOSE")
]
Expand Down
Loading