From 41f87fc8bd7912e6ff7ee2a75241899a3474259c Mon Sep 17 00:00:00 2001 From: Luka Date: Sat, 14 Dec 2019 23:25:51 +0100 Subject: [PATCH] Added Free structure column --- ResultTree.py | 16 ++++++++++------ Tree.py | 10 +++++----- dependency-parsetree.py | 4 +++- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/ResultTree.py b/ResultTree.py index cdba2bf..2d21184 100644 --- a/ResultTree.py +++ b/ResultTree.py @@ -37,14 +37,18 @@ class ResultTree(object): def set_children(self, children): self.children = children - def get_key(self): + def get_key(self, get_free=False): # if self.key: # return self.key key = '' write_self_node_to_result = False if self.children: - for child in self.children: - if child.node.location < self.node.location: + if get_free: + children = sorted(self.children, key=lambda x: x.node.name) + else: + children = self.children + for child in children: + if self.filters['node_order'] and child.node.location < self.node.location and not get_free: if self.filters['dependency_type']: # separator = ' <' + deprel[i_child][i_answer] + ' ' separator = ' <' + child.node.deprel + ' ' @@ -75,7 +79,7 @@ class ResultTree(object): write_self_node_to_result = False if self.children: for child in self.children: - if child.node.location < self.node.location: + if self.filters['node_order'] and child.node.location < self.node.location: if self.filters['dependency_type']: # separator = ' <' + deprel[i_child][i_answer] + ' ' separator = ' <' + child.node.deprel + ' ' @@ -105,7 +109,7 @@ class ResultTree(object): write_self_node_to_result = False if self.children: for child in self.children: - if child.node.location < self.node.location: + if self.filters['node_order'] and child.node.location < self.node.location: order += child.get_order() else: if not write_self_node_to_result: @@ -127,7 +131,7 @@ class ResultTree(object): write_self_node_to_result = False if self.children: for child in self.children: - if child.node.location < self.node.location: + if self.filters['node_order'] and child.node.location < self.node.location: array += child.get_array() else: if not write_self_node_to_result: diff --git a/Tree.py b/Tree.py index 3749a1b..afa305d 100644 --- a/Tree.py +++ b/Tree.py @@ -595,8 +595,8 @@ class Tree(object): # def create_merged_results(self, new_child, new_answers, i_child, indices, deprel, filters): def merge_results3(self, child, new_results, filters): - if create_output_string_form(self) == 'Dogodek': - print('HERE!@@!') + # if create_output_string_form(self) == 'Dogodek': + # print('HERE!@@!') # if create_output_string_form(self) == 'začelo': # print('HERE!@@!') # if create_output_string_form(self) == 'utišal': @@ -627,8 +627,8 @@ class Tree(object): # for children in children_groups_sorted: # new_result = copy(result) # new_result.set_children(children) - # order = sorted(new_result.get_order()) - # results_sorted.append(new_result) + # order = tuple(sorted(new_result.get_order())) + # results_sorted[order] = new_result results = [] @@ -636,7 +636,7 @@ class Tree(object): for children in children_groups: new_result = copy(result) new_result.set_children(children) - order = new_result.get_order() + order = tuple(sorted(new_result.get_order())) results.append(new_result) return results diff --git a/dependency-parsetree.py b/dependency-parsetree.py index c9d342b..9831f2c 100644 --- a/dependency-parsetree.py +++ b/dependency-parsetree.py @@ -503,7 +503,7 @@ def main(): for tree_i, tree in enumerate(all_trees): # for tree_i, tree in enumerate(all_trees[852:]): # for tree_i, tree in enumerate(all_trees[1689:]): - # for tree_i, tree in enumerate(all_trees[2:]): + # for tree_i, tree in enumerate(all_trees[1:3]): input_data = (tree, query_tree, create_output_string_functs, filters) if filters['association_measures']: unigrams = get_unigrams(input_data) @@ -565,6 +565,7 @@ def main(): header += ['Relative frequency'] if filters['node_order']: header += ['Order'] + header += ['Free structure'] if filters['nodes_number']: header += ['Number of nodes'] if filters['print_root']: @@ -589,6 +590,7 @@ def main(): row += ['%.4f' % absolute_frequency] if filters['node_order']: row += [v['object'].order] + row += [v['object'].get_key(get_free=True)[1:-1]] if filters['nodes_number']: row += ['%d' % len(v['object'].array)] if filters['print_root']: