def questionObjectBuilder()

in data/question-gen/engine.py [0:0]


    def questionObjectBuilder(self, template, q_ent, a_str, q_type=None):
        if q_type == None:
            q_type = template

        q_str = self.templates[template]
        bbox = []

        if template == 'room_count':
            # if this condition holds, the question type is 'room_count' and the q_ent[0] is a room entity
            q_str = self.q_str_builder.prepareString(q_str, '',
                                                     q_ent[0].name[0])
            return {
                'question':
                q_str,
                'answer':
                a_str,
                'type':
                q_type,
                'meta': {},
                'bbox': [{
                    'type': x.type,
                    'box': x.bbox,
                    'name': x.name,
                    'target': True
                } for x in q_ent]
            }

        if template == 'room_object_count':
            q_str = self.q_str_builder.prepareString(q_str, q_ent[0].name, '')
            return {
                'question':
                q_str,
                'answer':
                a_str,
                'type':
                q_type,
                'meta': {},
                'bbox': [{
                    'type': x.type,
                    'box': x.bbox,
                    'name': x.name,
                    'target': True
                } for x in q_ent]
            }

        if template == 'global_object_count':
            # if (len(q_ent) == 1) and (not isinstance(q_ent[0], tuple)) and (q_ent[0].type == 'object'):
            # if this condition holds, the question type is 'global_object_count' and the q_ent[0] is an obj entity
            q_str = self.q_str_builder.prepareString(q_str, q_ent[0].name,
                                                     q_ent[0].rooms[0].name[0])
            return {
                'question': q_str,
                'answer': a_str,
                'type': q_type,
                'meta': {},
                'bbox': [{}]
            }

        for ent in q_ent:
            # if ent is a tuple, it means exist_logic questions
            if isinstance(ent, tuple):
                if 'or' in q_type:
                    q_str = self.q_str_builder.prepareStringForLogic(
                        q_str, ent[0].name, ent[1].name,
                        ent[0].rooms[0].name[0], "or")
                else:
                    q_str = self.q_str_builder.prepareStringForLogic(
                        q_str, ent[0].name, ent[1].name,
                        ent[0].rooms[0].name[0], "and")
                return {
                    'question':
                    q_str,
                    'answer':
                    a_str,
                    'type':
                    q_type,
                    'meta': {},
                    'bbox': [{
                        'type': ent[0].rooms[0].type,
                        'box': ent[0].rooms[0].bbox,
                        'name': ent[0].rooms[0].name,
                        'target': True
                    }]
                }

            bbox.append({
                'type': ent.type,
                'box': ent.bbox,
                'name': ent.name,
                'target': True
            })
            if not isinstance(ent, tuple) and len(ent.rooms[0].name) != 0:
                q_str = self.q_str_builder.prepareString(
                    q_str, ent.name, ent.rooms[0].name[0])
            else:
                q_str = self.q_str_builder.prepareString(q_str, ent.name, '')

            if not isinstance(ent, tuple):
                if len(ent.rooms[0].name) == 0:
                    name = []
                else:
                    name = ent.rooms[0].name
                bbox.append({
                    'type': ent.rooms[0].type,
                    'box': ent.rooms[0].bbox,
                    'name': name,
                    'target': False
                })

        if 'mat' in q_ent[0].meta:
            mat = q_ent[0].meta['mat']
        else:
            mat = {}

        return {
            'question': q_str,
            'answer': a_str,
            'type': q_type,
            'meta': mat,
            'bbox': bbox
        }