from collections import OrderedDict


def classification_to_extract(classification):
    extract = OrderedDict([
        ('points', OrderedDict([('x', []), ('y', [])])),
        ('text', []),
        ('frame', [])
    ])
    annotation = classification['annotations'][0]
    for value in annotation['value']:
        text = value['details'][0]['value']
        words = text.split(' ')
        for word, point in zip(words, value['points']):
            extract['frame'].append(value['frame'])
            extract['text'].append(word)
            extract['points']['x'].append(point['x'])
            extract['points']['y'].append(point['y'])
    return extract


def poly_line_text_extractor_request(request):
    data = request.get_json()
    return classification_to_extract(data)

from collections import OrderedDict


def classification_to_extract(classification):
    extract = OrderedDict([
        ('points', OrderedDict([('x', []), ('y', [])])),
        ('text', []),
        ('frame', [])
    ])
    annotation = classification['annotations'][0]
    for value in annotation['value']:
        text = value['details'][0]['value']
        words = text.split(' ')
        # NOTE: if `words` and `points` are differnt lengths
        # the extract will only contain the *shorter* of the
        # two lists (assuming they match from the front)
        for word, point in zip(words, value['points']):
            extract['frame'].append(value['frame'])
            extract['text'].append(word)
            extract['points']['x'].append(point['x'])
            extract['points']['y'].append(point['y'])
    return extract


def poly_line_text_extractor_request(request):
    data = request.get_json()
    return classification_to_extract(data)

Add clarification comment to extractor
Add clarification comment to extractor

Add a comment about the behavior of the extractor when the length of the
`words` list does not match the lenght of the `points` list.  The
extract will only contain the *shorter* of the two lists  and assume
they match from the front.
