Esempio n. 1
0
    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]):
                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 = Selector(predtype='unique',
                               scope=EntityType(attributes=attributes))

        entity_type.apply_to_predication(predication=predication)

        return entity_type
Esempio n. 2
0
    def caption(self, predication, world):
        scope_predication = predication.sub_predication(reset=True)

        scope = self.scope_captioner.caption(predication=predication,
                                             world=world)
        if scope is None:
            return None
        scope.apply_to_predication(predication=scope_predication)

        if self.predtype in Selector.reference_selectors or self.incorrect_predtype in Selector.reference_selectors:
            ref_predication = predication.sub_predication(reset=True)
            reference = self.reference_captioner.caption(
                predication=ref_predication, world=world)
            if reference is None:
                return None
            if not ref_predication.disjoint(other=scope_predication):
                return None
        else:
            ref_predication = None
            reference = None

        selector = Selector(predtype=self.predtype,
                            value=self.value,
                            scope=scope,
                            reference=reference)

        predication.apply(predicate=selector,
                          scope_predication=scope_predication,
                          ref_predication=ref_predication)

        return selector
Esempio n. 3
0
    def caption(self, predication, world):
        if self.predtype in Selector.comparison_selectors or self.incorrect_predtype in Selector.comparison_selectors:
            comp_predication = predication.copy(reset=True)
            comparison = self.comparison_captioner.caption(
                predication=comp_predication, world=world)
            if comparison is None:
                return None
        else:
            comp_predication = None
            comparison = None

        scope_predication = predication.copy()
        scope = self.scope_captioner.caption(predication=scope_predication,
                                             world=world)
        if scope is None:
            return None

        selector = Selector(predtype=self.predtype,
                            value=self.value,
                            scope=scope,
                            comparison=comparison)

        if not self.correct(caption=selector, predication=predication):
            return None

        return selector
Esempio n. 4
0
    def caption(self, predication, world):
        scope_predication = predication.sub_predication(reset=True)

        scope = self.scope_captioner.caption(predication=predication,
                                             world=world)
        if scope is None:
            return None
        scope.apply_to_predication(predication=scope_predication)

        if self.predtype in Selector.comparison_selectors or self.incorrect_predtype in Selector.comparison_selectors:
            comp_predication = predication.sub_predication(reset=True)
            comparison = self.comparison_captioner.caption(
                predication=comp_predication, world=world)
            if comparison is None:
                return None
            if not comp_predication.disjoint(other=scope_predication):
                return None
        else:
            comp_predication = None
            comparison = None

        selector = Selector(predtype=self.predtype,
                            value=self.value,
                            scope=scope,
                            comparison=comparison)

        predication.apply(predicate=selector,
                          scope_predication=scope_predication,
                          comp_predication=comp_predication)

        return selector