def get_min_span_no_valid_tag()

in modeling/coval/conll/mention.py [0:0]


    def get_min_span_no_valid_tag(self, root):
        if not root:
            return
        
        terminal_shortest_depth = float('inf')
        queue = [(root, 0)]

        accepted_tags = None
    
        while queue:
            node, depth = queue.pop(0)

            if not accepted_tags:
                if node.tag[0:2] in ['NP', 'NM']:
                    accepted_tags=['NP', 'NM', 'QP', 'NX']
                elif node.tag[0:2]=='VP':
                    accepted_tags=['VP']

            if node.isTerminal and depth <= terminal_shortest_depth:
                if self.is_a_valid_terminal_node(node.tag, node.pos):
                    self.min_spans.add((node.tag, node.index))
                    terminal_shortest_depth = min(terminal_shortest_depth, depth)
                    
            elif (not self.min_spans or depth < terminal_shortest_depth )and node.children and \
                 (depth== 0 or not accepted_tags or node.tag[0:2] in accepted_tags): 
                for child in node.children:
                    if not child.isTerminal or (accepted_tags and node.tag[0:2] in accepted_tags):
                        queue.append((child, depth+1))