Ejemplo n.º 1
0
def prune_parent(roots, depth, gate_dist):
	def set_score(node):
		node.score = max(score(hyp, gate_dist) for hyp in node.tracks())
	if depth == 0:
		map(set_score, roots)
		## We don't have any conflicts at depth = 0 (yet)
		# Tracks ARE in order here so we can be smart when removing them
	else:
		parents = get_nodes_at_depth(roots, depth - 1)
		parentless = (node for node in roots if node.base_depth == depth)

		e_instances, child_score = get_eddy_instances(parents, parentless, gate_dist)

		if consts.DEBUG:
			io.fmt_print_with_no_root(e_instances, child_score)

		for parent in parents:
			if len(parent.children) > 1:
				big = max([(score(hyp, gate_dist), hyp[1]) for hyp in parent.tracks()])
				parent.set_child(big[1])
				if big[1].obj in e_instances.keys():
					for child in e_instances[big[1].obj]:
						if child is not big[1]:
							if child_score[child][1] is None:
								roots.remove(child)
							elif not child_score[child][1].final:
								child_score[child][1].remove_child(child)
Ejemplo n.º 2
0
def prune(roots, depth, gate_dist):
    def set_score(node):
        node.score = max(score(hyp, gate_dist) for hyp in node.tracks())

    if depth == 0:
        map(set_score, roots)
        ## We don't have any conflicts at depth = 0 (yet)
        # Tracks ARE in order here so we can be smart when removing them
    else:
        parents = get_nodes_at_depth(roots, depth - 1)
        parentless = (node for node in roots if node.base_depth == depth)

        e_instances, child_score = get_eddy_instances(parents, parentless,
                                                      gate_dist)

        if consts.DEBUG:
            io.fmt_print_with_no_root(e_instances, child_score)

        for instances in e_instances.values():
            big = max(child_score[child] + (child, ) for child in instances)
            if big[1] is not None:
                for child in big[1].children:
                    if child is not big[2] and child.obj in e_instances.keys():
                        e_instances[child.obj].remove(child)
                big[1].set_child(big[2])
            for child in instances:
                if child is not big[2]:
                    if child_score[child][1] is None:
                        roots.remove(child)
                    else:
                        child_score[child][1].remove_child(child)
Ejemplo n.º 3
0
def prune(roots, depth, gate_dist):
	def set_score(node):
		node.score = max(score(hyp, gate_dist) for hyp in node.tracks())
	if depth == 0:
		map(set_score, roots)
		## We don't have any conflicts at depth = 0 (yet)
		# Tracks ARE in order here so we can be smart when removing them
	else:
		parents = get_nodes_at_depth(roots, depth - 1)
		parentless = (node for node in roots if node.base_depth == depth)

		e_instances, child_score = get_eddy_instances(parents, parentless, gate_dist)

		if consts.DEBUG:
			io.fmt_print_with_no_root(e_instances, child_score)

		for instances in e_instances.values():
			big = max(child_score[child] + (child,) for child in instances)
			if big[1] is not None:
				for child in big[1].children:
					if child is not big[2] and child.obj in e_instances.keys():
						e_instances[child.obj].remove(child)
				big[1].set_child(big[2])
			for child in instances:
				if child is not big[2]:
					if child_score[child][1] is None:
						roots.remove(child)
					else:
						child_score[child][1].remove_child(child)
Ejemplo n.º 4
0
def prune_parent(roots, depth, gate_dist):
    def set_score(node):
        node.score = max(score(hyp, gate_dist) for hyp in node.tracks())

    if depth == 0:
        map(set_score, roots)
        ## We don't have any conflicts at depth = 0 (yet)
        # Tracks ARE in order here so we can be smart when removing them
    else:
        parents = get_nodes_at_depth(roots, depth - 1)
        parentless = (node for node in roots if node.base_depth == depth)

        e_instances, child_score = get_eddy_instances(parents, parentless,
                                                      gate_dist)

        if consts.DEBUG:
            io.fmt_print_with_no_root(e_instances, child_score)

        for parent in parents:
            if len(parent.children) > 1:
                big = max([(score(hyp, gate_dist), hyp[1])
                           for hyp in parent.tracks()])
                parent.set_child(big[1])
                if big[1].obj in e_instances.keys():
                    for child in e_instances[big[1].obj]:
                        if child is not big[1]:
                            if child_score[child][1] is None:
                                roots.remove(child)
                            elif not child_score[child][1].final:
                                child_score[child][1].remove_child(child)