def incorrect(self, caption, predication, world):
        if not self.correct:

            if self.attribute == 'shape':  # random (existing) shape
                if self.existing_attribute:
                    values = util.unique_list(
                        entity.shape.name for entity in world.entities
                        if entity.shape.name in self.shapes)
                else:
                    values = self.shapes

            elif self.attribute == 'color':  # random (existing) color
                if self.existing_attribute:
                    values = util.unique_list(
                        entity.color.name for entity in world.entities
                        if entity.color.name in self.colors)
                else:
                    values = self.colors

            elif self.attribute == 'texture':  # random (existing) texture
                if self.existing_attribute:
                    values = util.unique_list(
                        entity.texture.name for entity in world.entities
                        if entity.texture.name in self.textures)
                else:
                    values = self.textures

            caption.value = choice(values)

        self.apply_caption_to_predication(caption=caption,
                                          predication=predication)

        return True
Example #2
0
    def incorrect(self, caption, predication, world):
        if self.incorrect_mode == 1:  # random (existing) shape
            if self.existing_attribute:
                shapes = util.unique_list(entity.shape.name
                                          for entity in world.entities
                                          if entity.shape.name in self.shapes)
            else:
                shapes = self.shapes
            caption.value['shape'] = Attribute(predtype='shape',
                                               value=choice(shapes))

        elif self.incorrect_mode == 2:  # random (existing) color
            if self.existing_attribute:
                colors = util.unique_list(entity.color.name
                                          for entity in world.entities
                                          if entity.color.name in self.colors)
            else:
                colors = self.colors
            caption.value['color'] = Attribute(predtype='color',
                                               value=choice(colors))

        elif self.incorrect_mode == 3:  # random (existing) texture
            if self.existing_attribute:
                textures = util.unique_list(
                    entity.texture.name for entity in world.entities
                    if entity.texture.name in self.textures)
            else:
                textures = self.textures
            caption.value['texture'] = Attribute(predtype='texture',
                                                 value=choice(textures))

        elif self.incorrect_mode == 4:  # random (existing) attributes
            if self.existing_attribute:
                shapes = util.unique_list(entity.shape.name
                                          for entity in world.entities
                                          if entity.shape.name in self.shapes)
                colors = util.unique_list(entity.color.name
                                          for entity in world.entities
                                          if entity.color.name in self.colors)
                textures = util.unique_list(
                    entity.texture.name for entity in world.entities
                    if entity.texture.name in self.textures)
            else:
                shapes = self.shapes
                colors = self.colors
                textures = self.textures
            if 'shape' in self.attributes:
                caption.value['shape'] = Attribute(predtype='shape',
                                                   value=choice(shapes))
            if 'color' in self.attributes:
                caption.value['color'] = Attribute(predtype='color',
                                                   value=choice(colors))
            if 'texture' in self.attributes:
                caption.value['texture'] = Attribute(predtype='texture',
                                                     value=choice(textures))

        self.apply_caption_to_predication(caption=caption,
                                          predication=predication)

        return True
Example #3
0
    def incorrect(self, caption, predication, world):
        if self.incorrect_mode == 0:  # random (existing) shape
            if self.existing_attribute:
                caption_shape = None
                for predicate in caption.value:
                    if predicate.predtype == 'shape':
                        caption_shape = predicate.value
                shapes = util.unique_list(
                    entity.shape.name for entity in world.entities
                    if entity.shape.name in self.shapes
                    and entity.shape.name != caption_shape)
            if not self.existing_attribute or len(shapes) == 0:
                shapes = self.shapes
            if len(caption.value) == 0:
                caption.value.append(
                    Attribute(predtype='shape', value=choice(shapes)))
            else:
                for n, predicate in enumerate(caption.value):
                    if predicate.predtype == 'shape':
                        caption.value[n] = Attribute(predtype='shape',
                                                     value=choice(shapes))

        elif self.incorrect_mode == 1:  # random (existing) color
            if self.existing_attribute:
                caption_color = None
                for predicate in caption.value:
                    if predicate.predtype == 'color':
                        caption_color = predicate.value
                colors = util.unique_list(
                    entity.color.name for entity in world.entities
                    if entity.color.name in self.colors
                    and entity.color.name != caption_color)
            if not self.existing_attribute or len(colors) == 0:
                colors = self.colors
            if len(caption.value) == 0:
                caption.value.append(
                    Attribute(predtype='color', value=choice(colors)))
            else:
                for n, predicate in enumerate(caption.value):
                    if predicate.predtype == 'color':
                        caption.value[n] = Attribute(predtype='color',
                                                     value=choice(colors))

        elif self.incorrect_mode == 2:  # random (existing) texture
            if self.existing_attribute:
                caption_texture = None
                for predicate in caption.value:
                    if predicate.predtype == 'texture':
                        caption_texture = predicate.value
                textures = util.unique_list(
                    entity.texture.name for entity in world.entities
                    if entity.texture.name in self.textures
                    and entity.texture.name != caption_texture)
            if not self.existing_attribute or len(textures) == 0:
                textures = self.textures
            if len(caption.value) == 0:
                caption.value.append(
                    Attribute(predtype='texture', value=choice(textures)))
            else:
                for n, predicate in enumerate(caption.value):
                    if predicate.predtype == 'texture':
                        caption.value[n] = Attribute(predtype='texture',
                                                     value=choice(textures))

        elif self.incorrect_mode == 3:  # random (existing) attributes
            if self.existing_attribute:
                caption_shape = caption_color = caption_texture = None
                for predicate in caption.value:
                    if predicate.predtype == 'shape':
                        caption_shape = predicate.value
                    elif predicate.predtype == 'color':
                        caption_color = predicate.value
                    elif predicate.predtype == 'texture':
                        caption_texture = predicate.value
                shapes = util.unique_list(
                    entity.shape.name for entity in world.entities
                    if entity.shape.name in self.shapes
                    and entity.shape.name != caption_shape)
                colors = util.unique_list(
                    entity.color.name for entity in world.entities
                    if entity.color.name in self.colors
                    and entity.color.name != caption_color)
                textures = util.unique_list(
                    entity.texture.name for entity in world.entities
                    if entity.texture.name in self.textures
                    and entity.texture.name != caption_texture)
            if not self.existing_attribute or len(shapes) == 0:
                shapes = self.shapes
            if not self.existing_attribute or len(colors) == 0:
                colors = self.colors
            if not self.existing_attribute or len(textures) == 0:
                textures = self.textures
            if len(caption.value) == 0:
                attribute = choice(self.valid_attributes)
                if attribute == 'shape':
                    caption.value.append(
                        Attribute(predtype='shape', value=choice(shapes)))
                elif attribute == 'color':
                    caption.value.append(
                        Attribute(predtype='color', value=choice(colors)))
                elif attribute == 'texture':
                    caption.value.append(
                        Attribute(predtype='texture', value=choice(textures)))
            else:
                for n, predicate in enumerate(caption.value):
                    if predicate.predtype == 'shape':
                        caption.value[n] = Attribute(predtype='shape',
                                                     value=choice(shapes))
                    elif predicate.predtype == 'color':
                        caption.value[n] = Attribute(predtype='color',
                                                     value=choice(colors))
                    elif predicate.predtype == 'texture':
                        caption.value[n] = Attribute(predtype='texture',
                                                     value=choice(textures))

        caption.apply_to_predication(predication=predication)

        return True