def build_trees_from_sentence( sentence, syntactic_relations, layer=LAYER_VISLCG3, \
                               sentence_id=0, **kwargs ):
    ''' Given a sentence ( a list of EstNLTK's word tokens ), and a list of 
        dependency syntactic relations ( output of normalise_alignments() ),
        builds trees ( estnltk.syntax.utils.Tree objects ) from the sentence,
        and returns as a list of Trees (roots of trees).
        
        Note that  there  is  one-to-many  correspondence  between  EstNLTK's 
        sentences and dependency syntactic trees, so the resulting list can 
        contain more than one tree (root);
    '''
    trees_of_sentence = []
    nodes = [ -1 ]
    while( len(nodes) > 0 ):
        node = nodes.pop(0)
        # Find tokens in the sentence that take this node as their parent
        for i, syntax_token in enumerate( syntactic_relations ):
            parents = [ o[1] for o in syntax_token[PARSER_OUT] ]
            # There should be only one parent node; If there is more than one, take the 
            # first node;
            parent = parents[0]
            if parent == node:
                labels  = [ o[0] for o in syntax_token[PARSER_OUT] ]
                estnltk_token = sentence[i]
                tree1 = Tree( estnltk_token, i, sentence_id, labels, parser=layer )
                if INIT_PARSER_OUT in syntax_token:
                    tree1.parser_output = syntax_token[INIT_PARSER_OUT]
                tree1.syntax_token = syntax_token
                if parent == -1:
                    # Add the root node
                    trees_of_sentence.append( tree1 )
                elif parent == i:
                    # If, for some strange reason, the node is unnormalised and is still 
                    # linked to itself, add it as a singleton tree
                    trees_of_sentence.append( tree1 )
                else:
                    # For each root node, attempt to add the child
                    for root_node in trees_of_sentence:
                        root_node.add_child_to_subtree( parent, tree1 )
                if parent != i:
                   # Add the current node as a future parent to be examined
                   nodes.append( i )
    return trees_of_sentence
def build_trees_from_sentence ( sentence , syntactic_relations , layer = LAYER_VISLCG3 , sentence_id = 0 , ** kwargs ) : trees_of_sentence = [ ] nodes = [ - 1 ] while ( len ( nodes ) > 0 ) : node = nodes . pop ( 0 ) for i , syntax_token in enumerate ( syntactic_relations ) : parents = [ o [ 1 ] for o in syntax_token [ PARSER_OUT ] ] parent = parents [ 0 ] if parent == node : labels = [ o [ 0 ] for o in syntax_token [ PARSER_OUT ] ] estnltk_token = sentence [ i ] tree1 = Tree ( estnltk_token , i , sentence_id , labels , parser = layer ) if INIT_PARSER_OUT in syntax_token : tree1 . parser_output = syntax_token [ INIT_PARSER_OUT ] tree1 . syntax_token = syntax_token if parent == - 1 : trees_of_sentence . append ( tree1 ) elif parent == i : trees_of_sentence . append ( tree1 ) else : for root_node in trees_of_sentence : root_node . add_child_to_subtree ( parent , tree1 ) if parent != i : nodes . append ( i ) return trees_of_sentence
Given a sentence ( a list of EstNLTK's word tokens ), and a list of 
        dependency syntactic relations ( output of normalise_alignments() ),
        builds trees ( estnltk.syntax.utils.Tree objects ) from the sentence,
        and returns as a list of Trees (roots of trees).
        
        Note that  there  is  one-to-many  correspondence  between  EstNLTK's 
        sentences and dependency syntactic trees, so the resulting list can 
        contain more than one tree (root);