From 3a86e2164245353643d3de2a8534571a52e98f6d Mon Sep 17 00:00:00 2001 From: Megan Ung <20617868+meganung@users.noreply.github.com> Date: Thu, 19 Aug 2021 09:42:50 -0700 Subject: [PATCH] [turn annotations static] more customization (annotation question, buckets, speaker label) (#3926) * annotation buckets customization from task data * customize annotation question per utterance * customize speaker label * use turnIdx for determining speaker label --- .../webapp/src/components/task_components.jsx | 41 ++++++++++++++++--- 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/parlai/crowdsourcing/tasks/turn_annotations_static/webapp/src/components/task_components.jsx b/parlai/crowdsourcing/tasks/turn_annotations_static/webapp/src/components/task_components.jsx index da1c2832547..378501b7f09 100644 --- a/parlai/crowdsourcing/tasks/turn_annotations_static/webapp/src/components/task_components.jsx +++ b/parlai/crowdsourcing/tasks/turn_annotations_static/webapp/src/components/task_components.jsx @@ -85,6 +85,24 @@ var handleUserInputUpdate = function (subtaskData) { } } +var getAnnotationBuckets = function (taskData, annotationBuckets) { + // return list of all the bucket ids + var buckets = [] + if (annotationBuckets !== null && 'config' in annotationBuckets){ + buckets = Object.keys(annotationBuckets.config); + } + taskData.forEach(elem => { + if ('annotation_buckets' in elem) { + (Object.keys(elem.annotation_buckets.config)).forEach(bucketKey => { + if (!buckets.includes(bucketKey)) { + buckets.push(bucketKey) + } + }) + } + }) + return buckets +} + var handleSubtaskSubmit = function (subtaskIndex, setIndex, numSubtasks, initialTaskData, annotationBuckets, mephistoSubmit) { // initialTaskData is the initial task data for this index console.log('In handleSubtaskSubmit for subtask: ' + subtaskIndex); @@ -103,8 +121,8 @@ var handleSubtaskSubmit = function (subtaskIndex, setIndex, numSubtasks, initial 'agent_idx': initialTaskData[i].agent_idx, 'other_metadata': initialTaskData[i].other_metadata }; - if (annotationBuckets !== null) { - var buckets = Object.keys(annotationBuckets.config); + var buckets = getAnnotationBuckets(initialTaskData, annotationBuckets) + if (buckets !== null && buckets.length > 0) { for (var j = 0; j < buckets.length; j++) { answersForTurn[buckets[j]] = null; var checkbox = document.getElementById(buckets[j] + '_' + i); @@ -198,9 +216,18 @@ function SubtaskSubmitButton({ subtaskIndex, numSubtasks, onSubtaskSubmit }) { ) } -function ChatMessage({ text, agentIdx, annotationQuestion, annotationBuckets, turnIdx, doAnnotateMessage, askReason, responseField, onUserInputUpdate }) { +function ChatMessage({ text, agentIdx, annotationQuestion, annotationBuckets, turnIdx, doAnnotateMessage, askReason, responseField, speakerLabel, onUserInputUpdate }) { var extraElements = ''; var responseInputElement = ''; + if (speakerLabel == null) { + speakerLabel = turnIdx % 2 == 0 ? 'YOU' : 'THEM' + } + var speakerElements = ( +
+ {speakerLabel}: {text} +
+ ) + if (doAnnotateMessage) { if (annotationBuckets !== null) { extraElements = (

@@ -233,7 +260,8 @@ function ChatMessage({ text, agentIdx, annotationQuestion, annotationBuckets, tu return (
- {turnIdx % 2 == 0 ? 'YOU' : 'THEM'}: {text} + + {speakerElements} {extraElements} @@ -266,11 +294,12 @@ function ContentPane({ subtaskData, taskConfig, subtaskIndex, numSubtasks }) { text={m.text} agentIdx={m.agent_idx} turnIdx={idx} - annotationQuestion={annotationQuestion} - annotationBuckets={annotationBuckets} + annotationQuestion={ ('annotation_question' in m) ? m.annotation_question : annotationQuestion} + annotationBuckets={ ('annotation_buckets' in m) ? m.annotation_buckets : annotationBuckets} doAnnotateMessage={m.do_annotate} askReason={askReason} responseField={responseField} + speakerLabel={('speaker_label' in m) ? m.speaker_label : null} onUserInputUpdate={() => handleUserInputUpdate(subtaskData)} />