def caption(self, predication, world): caption = self.captioner.caption(predication=predication, world=world) if caption is None: return None elif isinstance(caption, Attribute): return Relation(predtype='attribute', value=caption) elif isinstance(caption, EntityType): return Relation(predtype='type', value=caption) else: assert False
def caption(self, predication, world): caption = self.attribute_type_captioner.caption( predication=predication, world=world) if caption is None: return None elif isinstance(caption, Attribute): return Relation(predtype='attribute', value=caption) elif isinstance(caption, EntityType): return Relation(predtype='type', value=caption) else: raise NotImplementedError
def caption(self, predication, world): ref_predication = predication.sub_predication(reset=True) reference = self.reference_captioner.caption( predication=ref_predication, world=world) if reference is None: return None if self.predtype in Relation.ternary_relations or self.incorrect_predtype in Relation.ternary_relations: comp_predication = predication.sub_predication(reset=True) comparison = self.comparison_captioner.caption( predication=comp_predication, world=world) if comparison is None: return None if ref_predication.equals(other=comp_predication): # reference and comparison should not be equal return None else: comp_predication = None comparison = None relation = Relation(predtype=self.predtype, value=self.value, reference=reference, comparison=comparison) predication.apply(predicate=relation, ref_predication=ref_predication, comp_predication=comp_predication) return relation
def caption(self, predication, world): ref_predication = predication.sub_predication(reset=True) if self.negation: predication_copy = ref_predication.copy() reference = self.relation_captioner.caption( predication=predication_copy, world=world) if reference is None: return None if not self.relation_captioner.incorrect( caption=reference, predication=ref_predication, world=world): return None else: reference = self.relation_captioner.caption( predication=ref_predication, world=world) if reference is None: return None relation = Relation(predtype='negation', value=(-1 if self.negation else 1), reference=reference) predication.apply(predicate=relation, ref_predication=ref_predication) return relation
def caption(self, predication, world): rel_predication = predication.copy(reset=True) if self.negation: relation = self.relation_captioner.caption( predication=rel_predication, world=world) if relation is None: return None rel_predication = predication.copy(reset=True) if not self.relation_captioner.incorrect( caption=relation, predication=rel_predication, world=world): return None relation = Relation(predtype='negation', value=1, reference=relation) else: relation = self.relation_captioner.caption( predication=rel_predication, world=world) if relation is None: return None if not self.correct(caption=relation, predication=predication): return None return relation
def incorrect(self, caption, predication, world): if self.incorrect_mode == 0: # 0: incorrect relation ref_predication = predication.copy(reset=True) if self.negation: caption.reference = self.relation_captioner.caption( predication=ref_predication, world=world) if caption.reference is None: return False else: if not self.relation_captioner.incorrect( caption=caption, predication=ref_predication, world=world): return False elif self.incorrect_mode == 1: # 0: inverse negation if self.negation: caption.predtype = caption.reference.predtype caption.value = caption.reference.value caption.comparison = caption.reference.comparison caption.reference = caption.reference.reference else: caption.reference = Relation(predtype=caption.predtype, value=caption.value, reference=caption.reference, comparison=caption.comparison) caption.predtype = 'negation' caption.value = 1 caption.comparison = None return self.correct(caption=caption, predication=predication)
def caption(self, predication, world): ref_predication = predication.copy(reset=True) reference = self.reference_captioner.caption( predication=ref_predication, world=world) if reference is None: return None if self.predtype in Relation.ternary_relations or self.incorrect_predtype in Relation.ternary_relations: comp_predication = predication.copy(reset=True) comparison = self.comparison_captioner.caption( predication=comp_predication, world=world) if comparison is None: return None if comp_predication.implies( predicate=reference) or comp_predication.implied_by( predicate=reference): # reference and comparison should not overlap return None else: comparison = None relation = Relation(predtype=self.predtype, value=self.value, reference=reference, comparison=comparison) if not self.correct(caption=relation, predication=predication): return None return relation