diff --git a/client/src/components/content-blocks/assignment/SpellCheck.vue b/client/src/components/content-blocks/assignment/SpellCheck.vue index cf208576..d39fa051 100644 --- a/client/src/components/content-blocks/assignment/SpellCheck.vue +++ b/client/src/components/content-blocks/assignment/SpellCheck.vue @@ -16,17 +16,18 @@ let parts = []; let index = 0; [...this.corrections] // no side effects, as sort changes the source array - .sort((e1, e2) => e1.offset - e2.offset) + .sort((e1, e2) => (e1.offset + e1.sentenceOffset) - (e2.offset + e2.sentenceOffset)) .forEach(current => { + let realOffset = current.offset + current.sentenceOffset; parts.push({ correct: true, - text: this.text.substring(index, current.offset) + text: this.text.substring(index, realOffset) }); parts.push({ correct: false, - text: this.text.substring(current.offset, current.offset + current.length) + text: this.text.substring(realOffset, realOffset + current.length) }); - index = current.offset + current.length + index = realOffset + current.length }); parts.push({ correct: true, diff --git a/client/src/graphql/gql/mutations/spellCheck.gql b/client/src/graphql/gql/mutations/spellCheck.gql index db54804b..807c593a 100644 --- a/client/src/graphql/gql/mutations/spellCheck.gql +++ b/client/src/graphql/gql/mutations/spellCheck.gql @@ -4,6 +4,7 @@ mutation SpellCheck($input: SpellCheckInput!) { results { sentence offset + sentenceOffset length affected corrected diff --git a/server/spellcheck/mutations.py b/server/spellcheck/mutations.py index 62fe7866..ba443804 100644 --- a/server/spellcheck/mutations.py +++ b/server/spellcheck/mutations.py @@ -15,11 +15,17 @@ from assignments.models import Assignment from spellcheck.client import TaskbaseClient +def sentence_offset_to_snake_case(result): + result['sentence_offset'] = result['sentenceOffset'] + return result + + class SpellCheckStepNode(graphene.ObjectType): # id = graphene.String() # part = graphene.Field(SpellCheckPartNode) sentence = graphene.String() offset = graphene.Int() + sentence_offset = graphene.Int() length = graphene.Int() affected = graphene.String() corrected = graphene.String() @@ -45,13 +51,18 @@ class SpellCheck(relay.ClientIDMutation): if assignment.taskbase_id is None or assignment.taskbase_id == '': # we need to use another user (with more privileges) here, because why not - superclient = TaskbaseClient(settings.TASKBASE_SUPERUSER, settings.TASKBASE_SUPERPASSWORD, settings.TASKBASE_BASEURL) + superclient = TaskbaseClient(settings.TASKBASE_SUPERUSER, settings.TASKBASE_SUPERPASSWORD, + settings.TASKBASE_BASEURL) superclient.register_assignment(assignment) data = json.loads(client.spellcheck(assignment.taskbase_id, text)) - - return cls(correct=data['correct'] == 'CORRECT', results=map(lambda x: x['part'], data['steps'])) + # the property is called sentenceOffset, but graphene expects the property to be called sentence_offset. + # we convert it manually here. fixme: is there a better way to declare this in the SpellCheckStepNode? + transformed_results = list(map(lambda x: x['part'], data['steps'])) + return cls(correct=data['correct'] == 'CORRECT', results=[ + sentence_offset_to_snake_case(result) for result in transformed_results + ]) class SpellCheckMutations: