def resolve(self, atoms): if not atoms and not self._atom_needs: return [Phrase(self._type, {}, [])] def fits(need, atom): return need.get_type() == atom.get_type() scenarios = fill_containers(self._atom_needs, atoms, fits) result = [] for scenario in scenarios: need_name_to_atom = {} atoms_used = [] for (need, addressed_atom) in scenario: need_name_to_atom[need.get_name()] = addressed_atom atoms_used.append(addressed_atom) values = {} for name, atom in need_name_to_atom.items(): values[name] = atom.get_value() snippets = {} for k in self._templates: snippets[k] = string.Template(self._templates[k]).substitute(values) result.append(Phrase(self._type, snippets, atoms_used)) return result