def _iter_new_relations(self, init_match, subject_graph, edges0, constraints0, edges1):
<EOL>num_new_relations = len(set(j for i, j in edges0))<EOL>def combine_small(relations, num):<EOL><INDENT>"""<STR_LIT>"""<EOL>if len(relations) == <NUM_LIT:0>:<EOL><INDENT>return<EOL><DEDENT>for i, pivot in enumerate(relations):<EOL><INDENT>if num == <NUM_LIT:1>:<EOL><INDENT>yield (pivot, )<EOL><DEDENT>else:<EOL><INDENT>compatible_relations = list(<EOL>item for item in relations[:i]<EOL>if pivot[<NUM_LIT:0>]!=item[<NUM_LIT:0>] and pivot[<NUM_LIT:1>]!=item[<NUM_LIT:1>]<EOL>)<EOL>for tail in combine_small(compatible_relations, num-<NUM_LIT:1>):<EOL><INDENT>yield (pivot, ) + tail<EOL><DEDENT><DEDENT><DEDENT><DEDENT>candidate_relations = []<EOL>icg = self._iter_candidate_groups(init_match, edges0, edges1)<EOL>for end_vertices0, end_vertices1 in icg:<EOL><INDENT>if len(end_vertices0) > len(end_vertices1):<EOL><INDENT>return <EOL><DEDENT>elif not self.pattern.sub andlen(end_vertices0) != len(end_vertices1):<EOL><INDENT>return <EOL><DEDENT>l = []<EOL>for end_vertex0 in end_vertices0:<EOL><INDENT>for end_vertex1 in end_vertices1:<EOL><INDENT>if self.pattern.compare(end_vertex0, end_vertex1, subject_graph):<EOL><INDENT>l.append((end_vertex0, end_vertex1))<EOL><DEDENT><DEDENT><DEDENT>if len(l) > <NUM_LIT:0>:<EOL><INDENT>l = list(combine_small(l, len(end_vertices0)))<EOL>candidate_relations.append(l)<EOL><DEDENT><DEDENT>if len(candidate_relations) == <NUM_LIT:0>:<EOL><INDENT>return<EOL><DEDENT>self.print_debug("<STR_LIT>" % candidate_relations)<EOL>def combine_big(pos=<NUM_LIT:0>):<EOL><INDENT>"""<STR_LIT>"""<EOL>crs = candidate_relations[pos]<EOL>if pos == len(candidate_relations)-<NUM_LIT:1>:<EOL><INDENT>for relations in crs:<EOL><INDENT>yield relations<EOL><DEDENT><DEDENT>else:<EOL><INDENT>for tail in combine_big(pos+<NUM_LIT:1>):<EOL><INDENT>for relations in crs:<EOL><INDENT>yield relations + tail<EOL><DEDENT><DEDENT><DEDENT><DEDENT>for new_relations in combine_big():<EOL><INDENT>new_relations = set(new_relations)<EOL>self.print_debug("<STR_LIT>" % (new_relations, ))<EOL>if len(new_relations) != num_new_relations:<EOL><INDENT>continue<EOL><DEDENT>forward = dict(new_relations)<EOL>if len(forward) != num_new_relations:<EOL><INDENT>continue<EOL><DEDENT>reverse = dict((j, i) for i, j in new_relations)<EOL>if len(reverse) != num_new_relations:<EOL><INDENT>continue<EOL><DEDENT>for a0, b0 in constraints0:<EOL><INDENT>if forward[a0] not in subject_graph.neighbors[forward[b0]]:<EOL><INDENT>forward = None<EOL>break<EOL><DEDENT><DEDENT>if forward is None:<EOL><INDENT>continue<EOL><DEDENT>yield forward<EOL><DEDENT>
Given an onset for a match, iterate over all possible new key-value pairs