def simple_deep_copy_analysis(self):
     """
     :return: copy of this analysis (that is deep copy of dependency tree used for creation of this analysis), note
     that a new analysis with values given for instantiation of this analysis is created;
     sets valence holder lemma and primary analysis for new analysis, does NOT include any analyses of subsentences
     (i.e. analysis in lists of own DependencyAanalysisSubTypeI or DependencyAanalysisSubTypeII)
     """
     new_tree_root = Node.recursive_deep_copy_tree(self.raw_tree)
     new_avz_nodes = self.raw_avz_nodes.copy()
     new_aux_nodes = self.raw_aux_nodes.copy()
     new_analysis = None
     if self.__class__ == DependencyAnalysis:
         new_analysis = DependencyAnalysis(new_tree_root, self.raw_verb,
                                           new_avz_nodes, new_aux_nodes,
                                           list(), list())
     elif self.__class__ == DependencyAnalysisSubTypeI:
         new_analysis = DependencyAnalysisSubTypeI(new_tree_root,
                                                   self.raw_verb,
                                                   new_avz_nodes,
                                                   new_aux_nodes, list(),
                                                   list())
     elif self.__class__ == DependencyAnalysisSubTypeII:
         new_analysis = DependencyAnalysisSubTypeII(new_tree_root,
                                                    self.raw_verb,
                                                    new_avz_nodes,
                                                    new_aux_nodes, list(),
                                                    list())
     new_analysis.set_valence_holder_lemma(self.valence_holder_lemma)
     new_analysis.set_primary_analysis(self.primary_analysis)
     return new_analysis
Example #2
0
 def get_complete_subtree_as_list(root):
     """
     :param root: a tree, given by its root
     :type root: Node
     :return: list() of all nodes (as objects of class Node) that are children (or children of children) of node,
              ordered by depth-first-search
     """
     sub_tree_as_list = Node.recursive_tree_to_list_conversion(root)
     return sub_tree_as_list
Example #3
0
 def slice_tree_by_label(self, labels):
     """
     slice tree (complete tree given by self.tree_root) on all levels at first occurrence of label
     :param labels: list() of labels to slice at
     :type labels: List
     :return: list() of all children of all nodes (with label given by labels) that were cut off
     """
     new_raw_trees_with_label = Node.recursive_search_and_cut(
         self.tree_root, labels)
     return new_raw_trees_with_label
Example #4
0
 def get_word_ids_in_order(self):
     """
     :return: list of all word ids in this complement, sorted in ascending order
     """
     node_list = Node.recursive_tree_to_list_conversion(
         self.complement_as_tree)
     new_node_list = list()
     for node in node_list:
         new_node_list.append([node.get_node()])
     new_node_list.sort()
     return new_node_list
 def recursive_deep_copy_analysis(self):
     """
     :return: deep copy (of current state, i.e. sets all complement codings to current codings of complements in
     self) of analysis
     """
     new_tree_root = Node.recursive_deep_copy_tree(self.raw_tree)
     new_verb = Node.recursive_deep_copy_tree(self.raw_verb)
     new_avz_nodes = self.raw_avz_nodes.copy()
     new_aux_nodes = self.raw_aux_nodes.copy()
     class_i_sub_analyses = list()
     for analysis in self.class_i_sub_analysis:
         class_i_sub_analyses.append(
             analysis.recursive_deep_copy_analysis())
     class_ii_sub_analysis = list()
     for analysis in self.class_ii_sub_analysis:
         class_ii_sub_analysis.append(
             analysis.recursive_deep_copy_analysis())
     new_analysis = None
     if self.__class__ == DependencyAnalysis:
         new_analysis = DependencyAnalysis(new_tree_root, new_verb,
                                           new_avz_nodes, new_aux_nodes,
                                           class_i_sub_analyses,
                                           class_ii_sub_analysis)
         new_analysis.updated_complement_class_coding(self)
     elif self.__class__ == DependencyAnalysisSubTypeI:
         new_analysis = DependencyAnalysisSubTypeI(new_tree_root, new_verb,
                                                   new_avz_nodes,
                                                   new_aux_nodes,
                                                   class_i_sub_analyses,
                                                   class_ii_sub_analysis)
         new_analysis.updated_complement_class_coding(self)
     elif self.__class__ == DependencyAnalysisSubTypeII:
         new_analysis = DependencyAnalysisSubTypeII(new_tree_root, new_verb,
                                                    new_avz_nodes,
                                                    new_aux_nodes,
                                                    class_i_sub_analyses,
                                                    class_ii_sub_analysis)
         new_analysis.updated_complement_class_coding(self)
     new_analysis.set_valence_holder_lemma(self.valence_holder_lemma)
     new_analysis.set_primary_analysis(self.primary_analysis)
     return new_analysis
Example #6
0
 def get_word_ids_and_labels_in_order(self):
     """
     :return: list() of lists(), each element in outer list contains word ids at position [0] and labels at position [1]
     for each word in this complement, list is sorted in ascending order by word ids
     """
     node_list = Node.recursive_tree_to_list_conversion(
         self.complement_as_tree)
     new_node_list = list()
     for node in node_list:
         new_node_list.append([node.get_node(), node.get_label()])
     new_node_list.sort(key=lambda x: x[0])
     return new_node_list
Example #7
0
 def deep_copy_tree(root, children):
     """
     creates new tree with new object of class Node as root of tree and recursive deep copeies of children as new
     children of new root, does absolutely no checks for tree consistency!
     :param root: single object of class Node
     :type root: Node
     :param children: list() of objects of class Node
     :type children: List
     :return: root (as object of class Node) of the new tree
     """
     new_tree_root = WorkingTreeRootNode(0, 'label')
     if root.__class__ == new_tree_root.__class__:
         new_root = WorkingTreeRootNode(root.get_node(), root.get_label())
     else:
         new_root = Node(root.get_node(), root.get_label())
     new_children = list()
     for child in children:
         new_child = Node.recursive_deep_copy_tree(child)
         new_children.append(new_child)
     new_root.set_new_children_list(new_children)
     return new_root
Example #8
0
 def initialize_dependency_tree(words, raw_dep_tree):
     """
     tries to create dependency tree from raw tree data from database
     :raises various IncorrectTreeErrors
     :param words: words (as strings) for given sentence
     :type words: List
     :param raw_dep_tree: edges for dependency tree
     :type raw_dep_tree: List with format [vertex1, vertex2, label], where vertex1 and vertex2 are integers and label
     is string
     :return: new object of class DependencyTree (with Object of class Node set as tree_root) or exception
     """
     try:
         DependencyTree.check_tree_validity(words, raw_dep_tree)
     except IncorrectTreeError as err:
         raise err
     else:
         new_node_value = DependencyTree.determine_root(raw_dep_tree)
         new_node_value = new_node_value[0]
         new_tree_root = Node(new_node_value, 'root')
         queue = list()
         queue += [new_tree_root]
         while len(queue) > 0:
             current_node = queue[0]
             current_node_value = current_node.get_node()
             new_raw_nodes = DependencyTree.get_outbound_edges(
                 raw_dep_tree, current_node_value)
             new_children = list()
             for node in new_raw_nodes:
                 new_children.append(Node(node[1], node[2]))
             current_node.set_new_children_list(new_children)
             new_queue = current_node.get_children()
             queue.pop(0)
             for old_object in queue:
                 new_queue.append(old_object)
             if len(new_queue) > 0:
                 queue = new_queue
         new_dependency_tree = DependencyTree(new_tree_root)
         return new_dependency_tree
Example #9
0
 def append_any_node_by_children_list(self, new_children, given_node):
     """
     uses recursive_tree_look_up_by_node_value() to look for value of given node, appends children of this node via
     append_children_by_list()
     :param new_children: list() of objects of class Node used as new children of given_node
     :type new_children: List
     :param given_node: object of class Node to append new_children to, object to append children is searched for
     in own dependency tree, given_node is only checked regarding is node value
     :type given_node: Node
     :return: none, alters children of a node in own dependency tree (indicated by node value)
     """
     node_to_alter = Node.recursive_tree_look_up_by_node_value(
         self.tree_root, given_node.get_node())
     if node_to_alter is not None:
         node_to_alter.append_children_by_list(new_children)