Added Free structure column

This commit is contained in:
Luka 2019-12-14 23:25:51 +01:00
parent 53edc3b796
commit 41f87fc8bd
3 changed files with 18 additions and 12 deletions

View File

@ -37,14 +37,18 @@ class ResultTree(object):
def set_children(self, children): def set_children(self, children):
self.children = children self.children = children
def get_key(self): def get_key(self, get_free=False):
# if self.key: # if self.key:
# return self.key # return self.key
key = '' key = ''
write_self_node_to_result = False write_self_node_to_result = False
if self.children: if self.children:
for child in self.children: if get_free:
if child.node.location < self.node.location: 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']: if self.filters['dependency_type']:
# separator = ' <' + deprel[i_child][i_answer] + ' ' # separator = ' <' + deprel[i_child][i_answer] + ' '
separator = ' <' + child.node.deprel + ' ' separator = ' <' + child.node.deprel + ' '
@ -75,7 +79,7 @@ class ResultTree(object):
write_self_node_to_result = False write_self_node_to_result = False
if self.children: if self.children:
for child in 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']: if self.filters['dependency_type']:
# separator = ' <' + deprel[i_child][i_answer] + ' ' # separator = ' <' + deprel[i_child][i_answer] + ' '
separator = ' <' + child.node.deprel + ' ' separator = ' <' + child.node.deprel + ' '
@ -105,7 +109,7 @@ class ResultTree(object):
write_self_node_to_result = False write_self_node_to_result = False
if self.children: if self.children:
for child in 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() order += child.get_order()
else: else:
if not write_self_node_to_result: if not write_self_node_to_result:
@ -127,7 +131,7 @@ class ResultTree(object):
write_self_node_to_result = False write_self_node_to_result = False
if self.children: if self.children:
for child in 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() array += child.get_array()
else: else:
if not write_self_node_to_result: if not write_self_node_to_result:

10
Tree.py
View File

@ -595,8 +595,8 @@ class Tree(object):
# def create_merged_results(self, new_child, new_answers, i_child, indices, deprel, filters): # def create_merged_results(self, new_child, new_answers, i_child, indices, deprel, filters):
def merge_results3(self, child, new_results, filters): def merge_results3(self, child, new_results, filters):
if create_output_string_form(self) == 'Dogodek': # if create_output_string_form(self) == 'Dogodek':
print('HERE!@@!') # print('HERE!@@!')
# if create_output_string_form(self) == 'začelo': # if create_output_string_form(self) == 'začelo':
# print('HERE!@@!') # print('HERE!@@!')
# if create_output_string_form(self) == 'utišal': # if create_output_string_form(self) == 'utišal':
@ -627,8 +627,8 @@ class Tree(object):
# for children in children_groups_sorted: # for children in children_groups_sorted:
# new_result = copy(result) # new_result = copy(result)
# new_result.set_children(children) # new_result.set_children(children)
# order = sorted(new_result.get_order()) # order = tuple(sorted(new_result.get_order()))
# results_sorted.append(new_result) # results_sorted[order] = new_result
results = [] results = []
@ -636,7 +636,7 @@ class Tree(object):
for children in children_groups: for children in children_groups:
new_result = copy(result) new_result = copy(result)
new_result.set_children(children) new_result.set_children(children)
order = new_result.get_order() order = tuple(sorted(new_result.get_order()))
results.append(new_result) results.append(new_result)
return results return results

View File

@ -503,7 +503,7 @@ def main():
for tree_i, tree in enumerate(all_trees): 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[852:]):
# for tree_i, tree in enumerate(all_trees[1689:]): # 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) input_data = (tree, query_tree, create_output_string_functs, filters)
if filters['association_measures']: if filters['association_measures']:
unigrams = get_unigrams(input_data) unigrams = get_unigrams(input_data)
@ -565,6 +565,7 @@ def main():
header += ['Relative frequency'] header += ['Relative frequency']
if filters['node_order']: if filters['node_order']:
header += ['Order'] header += ['Order']
header += ['Free structure']
if filters['nodes_number']: if filters['nodes_number']:
header += ['Number of nodes'] header += ['Number of nodes']
if filters['print_root']: if filters['print_root']:
@ -589,6 +590,7 @@ def main():
row += ['%.4f' % absolute_frequency] row += ['%.4f' % absolute_frequency]
if filters['node_order']: if filters['node_order']:
row += [v['object'].order] row += [v['object'].order]
row += [v['object'].get_key(get_free=True)[1:-1]]
if filters['nodes_number']: if filters['nodes_number']:
row += ['%d' % len(v['object'].array)] row += ['%d' % len(v['object'].array)]
if filters['print_root']: if filters['print_root']: