def generate(self, references): references = form_choice.variation_bayes(references) references = sorted(references, key=lambda x: (x['sentence'], x['pos'])) prev_references = [] for reference in references: realization = self._realize(prev_references, reference).lower() reference['realization'] = realization prev_references.append(reference) return references
def generate(self, references): references = form_choice.variation_bayes(references) references = sorted(references, key=lambda x: (x['sentence'], x['pos'])) prev_references = [] for reference in references: try: realization = self._realize(prev_references, reference).lower() except: realization = ' '.join(reference['entity'].replace('\'', '').replace('\"', '').split('_')) reference['realization'] = realization prev_references.append(reference) return references
def generate(self, template, entitymap, topic=''): self.template = template.lower() self.entitymap = dict(map(lambda x: (x[0].lower(), x[1]), entitymap.items())) references = self._extract_references() references = form_choice.variation_bayes(references) references = sorted(references, key=lambda x: (x['sentence'], x['pos'])) prev_references = [] for reference in references: reference['realization'] = self._realize(prev_references, reference, topic).lower() prev_references.append(reference) for reference in references: template = template.replace(reference['tag'], unicode(reference['realization']), 1) return template