def caption(self, predication, world): if predication.num_agreeing == 0: return None entity = predication.random_agreeing_entity() attributes = list() for predtype in self.attributes: if predtype == 'shape': attributes.append( Attribute(predtype='shape', value=entity.shape.name)) elif predtype == 'color': attributes.append( Attribute(predtype='color', value=entity.color.name)) elif predtype == 'texture': attributes.append( Attribute(predtype='texture', value=entity.texture.name)) for n in range(len(attributes) - 1, -1, -1): if predication.contradictory(predicate=attributes[n]): assert False elif not self.pragmatical_redundancy and predication.num_entities > 1 and predication.redundant( predicate=attributes[n]): attributes.pop(n) entity_type = EntityType(attributes=attributes) entity_type.apply_to_predication(predication=predication) return entity_type
def caption(self, predication, world): if predication.num_agreeing == 0: return None entity_type = EntityType() entity_type.apply_to_predication(predication=predication) return entity_type
def caption(self, predication, world): if predication.num_agreeing == 0: return None entity = predication.random_agreeing_entity() attributes = dict() if 'shape' in self.attributes: attributes['shape'] = Attribute(predtype='shape', value=entity.shape.name) if 'color' in self.attributes: attributes['color'] = Attribute(predtype='color', value=entity.color.name) if 'texture' in self.attributes: attributes['texture'] = Attribute(predtype='texture', value=entity.texture.name) for predtype, attribute in list(attributes.items()): if predication.contradictory(predicate=attribute): assert False elif not self.pragmatical_redundancy and predication.redundant( predicate=attribute): attributes.pop(predtype) entity_type = EntityType(predicates=attributes) self.apply_caption_to_predication(caption=entity_type, predication=predication) return entity_type
def caption(self, predication, world): if predication.num_agreeing == 0: return None attributes = set() for entity in predication.agreeing: if self.attribute == 'shape' and entity.shape.name in self.attributes: attributes.add(entity.shape.name) elif self.attribute == 'color' and entity.color.name in self.attributes: attributes.add(entity.color.name) elif self.attribute == 'texture' and entity.texture.name in self.attributes: attributes.add(entity.texture.name) attribute = choice(list(attributes)) if self.attribute == 'shape': attribute = Attribute(predtype='shape', value=attribute) elif self.attribute == 'color': attribute = Attribute(predtype='color', value=attribute) elif self.attribute == 'texture': attribute = Attribute(predtype='texture', value=attribute) if predication.contradictory(predicate=attribute): raise NotImplementedError elif not self.pragmatical_redundancy and predication.num_entities > 1 and predication.implies(predicate=attribute): raise NotImplementedError entity_type = EntityType(attributes=[attribute]) if not self.correct(caption=entity_type, predication=predication): return None return entity_type
def caption(self, predication, world): if predication.num_agreeing == 0: return None entity_type = EntityType() if not self.correct(caption=entity_type, predication=predication): return None return entity_type
def caption(self, predication, world): if predication.num_agreeing == 0: return None entities = list() for entity in predication.agreeing: entity_attributes = list() for predtype in self.attributes: if predtype == 'shape' and entity.shape.name in self.shapes: entity_attributes.append(entity.shape.name) elif predtype == 'color' and entity.color.name in self.colors: entity_attributes.append(entity.color.name) elif predtype == 'texture' and entity.texture.name in self.textures: entity_attributes.append(entity.texture.name) else: break else: entity = tuple(entity_attributes) entities.append(entity) entity = choice(entities) attributes = list() for n, predtype in enumerate(self.attributes): if predtype == 'shape': attributes.append(Attribute(predtype='shape', value=entity[n])) elif predtype == 'color': attributes.append(Attribute(predtype='color', value=entity[n])) elif predtype == 'texture': attributes.append(Attribute(predtype='texture', value=entity[n])) for n in range(len(attributes) - 1, -1, -1): if predication.contradictory(predicate=attributes[n]): assert False elif not self.pragmatical_redundancy and predication.num_entities > 1 and predication.redundant(predicate=attributes[n]): assert False attributes.pop(n) entity_type = EntityType(attributes=attributes) entity_type.apply_to_predication(predication=predication) return entity_type
def caption(self, predication, world): if predication.num_agreeing == 0: return None entities = dict() for entity in predication.agreeing: entity_attributes = list() for predtype in self.attributes: if predtype == 'shape' and entity.shape.name in self.shapes: entity_attributes.append(entity.shape.name) elif predtype == 'color' and entity.color.name in self.colors: entity_attributes.append(entity.color.name) elif predtype == 'texture' and entity.texture.name in self.textures: entity_attributes.append(entity.texture.name) else: break else: entity = tuple(entity_attributes) if entity in entities: entities[entity] += 1 else: entities[entity] = 1 entities = [entity for entity, count in entities.items() if count == 1] if len(entities) == 0: return None entity = choice(entities) attributes = list() for n, predtype in enumerate(self.attributes): if predtype == 'shape': attributes.append(Attribute(predtype='shape', value=entity[n])) elif predtype == 'color': attributes.append(Attribute(predtype='color', value=entity[n])) elif predtype == 'texture': attributes.append( Attribute(predtype='texture', value=entity[n])) for n in range(len(attributes) - 1, -1, -1): if predication.contradictory(predicate=attributes[n]): raise NotImplementedError elif not self.pragmatical_redundancy and predication.num_entities > 1 and predication.redundant( predicate=attributes[n]): raise NotImplementedError attributes.pop(n) entity_type = Selector(predtype='unique', scope=EntityType(attributes=attributes)) if not self.correct(caption=entity_type, predication=predication): return None return entity_type