Added multiple attribute results
This commit is contained in:
parent
471b333df9
commit
b1370b2ee2
12
Result.py
12
Result.py
|
@ -2,10 +2,16 @@ import copy
|
||||||
|
|
||||||
|
|
||||||
class Result(object):
|
class Result(object):
|
||||||
def __init__(self, string, architecture_order):
|
def __init__(self, node, architecture_order, create_output_strings):
|
||||||
self.key = string
|
self.array = [[create_output_string(node) for create_output_string in create_output_strings]]
|
||||||
|
if len(self.array[0]) > 1:
|
||||||
|
self.key = '{' + ','.join(self.array[0]) + '}'
|
||||||
|
else:
|
||||||
|
# output_string = create_output_strings[0](node)
|
||||||
|
self.key = self.array[0][0]
|
||||||
|
# self.array = [[output_string]]
|
||||||
self.order_key = str([architecture_order])
|
self.order_key = str([architecture_order])
|
||||||
self.array = [string]
|
|
||||||
# order with original numbers in sentences
|
# order with original numbers in sentences
|
||||||
# self.order = str([architecture_order])
|
# self.order = str([architecture_order])
|
||||||
# order with numbers from 0 to n of n-gram
|
# order with numbers from 0 to n of n-gram
|
||||||
|
|
8
Tree.py
8
Tree.py
|
@ -324,11 +324,11 @@ class Tree(object):
|
||||||
# self.create_output_children(partial_subtrees_architecture[i_answer], [str([self.index])], filters, partial_subtrees_index[i_answer], partial_subtrees_deprel[i_answer]))
|
# self.create_output_children(partial_subtrees_architecture[i_answer], [str([self.index])], filters, partial_subtrees_index[i_answer], partial_subtrees_deprel[i_answer]))
|
||||||
|
|
||||||
merged_partial_subtrees.append(
|
merged_partial_subtrees.append(
|
||||||
self.create_output_children(partial_subtrees[i_answer], [Result(create_output_string(self), self.index)], filters, partial_subtrees_index[i_answer], partial_subtrees_deprel[i_answer]))
|
self.create_output_children(partial_subtrees[i_answer], [Result(self, self.index, create_output_string)], filters, partial_subtrees_index[i_answer], partial_subtrees_deprel[i_answer]))
|
||||||
|
|
||||||
i_answer += 1
|
i_answer += 1
|
||||||
else:
|
else:
|
||||||
merged_partial_subtrees.append([Result(create_output_string(self), self.index)])
|
merged_partial_subtrees.append([Result(self, self.index, create_output_string)])
|
||||||
# merged_partial_subtrees.append([create_output_string(self)])
|
# merged_partial_subtrees.append([create_output_string(self)])
|
||||||
# merged_partial_subtrees_architecture.append([str([self.index])])
|
# merged_partial_subtrees_architecture.append([str([self.index])])
|
||||||
|
|
||||||
|
@ -341,11 +341,11 @@ class Tree(object):
|
||||||
# self.create_output_children(partial_subtrees_architecture[i_answer], [str([self.index])], filters, partial_subtrees_index[i_answer], partial_subtrees_deprel[i_answer]))
|
# self.create_output_children(partial_subtrees_architecture[i_answer], [str([self.index])], filters, partial_subtrees_index[i_answer], partial_subtrees_deprel[i_answer]))
|
||||||
|
|
||||||
merged_partial_subtrees.append(
|
merged_partial_subtrees.append(
|
||||||
self.create_output_children(partial_subtrees[i_answer], [Result(create_output_string(self), self.index)], filters, partial_subtrees_index[i_answer], partial_subtrees_deprel[i_answer]))
|
self.create_output_children(partial_subtrees[i_answer], [Result(self, self.index, create_output_string)], filters, partial_subtrees_index[i_answer], partial_subtrees_deprel[i_answer]))
|
||||||
|
|
||||||
i_answer += 1
|
i_answer += 1
|
||||||
else:
|
else:
|
||||||
merged_partial_subtrees.append([Result(create_output_string(self), self.index)])
|
merged_partial_subtrees.append([Result(self, self.index, create_output_string)])
|
||||||
# merged_partial_subtrees.append([create_output_string(self)])
|
# merged_partial_subtrees.append([create_output_string(self)])
|
||||||
# merged_partial_subtrees_architecture.append([str([self.index])])
|
# merged_partial_subtrees_architecture.append([str([self.index])])
|
||||||
|
|
||||||
|
|
|
@ -384,20 +384,24 @@ def main():
|
||||||
|
|
||||||
|
|
||||||
# set filters
|
# set filters
|
||||||
assert config.get('settings', 'node_type') in ['deprel', 'lemma', 'upos', 'xpos', 'form', 'feats'], '"node_type" is not set up correctly'
|
node_types = config.get('settings', 'node_type').split('+')
|
||||||
cpu_cores = config.getint('settings', 'cpu_cores')
|
create_output_string_functs = []
|
||||||
if config.get('settings', 'node_type') == 'deprel':
|
for node_type in node_types:
|
||||||
create_output_string_funct = create_output_string_deprel
|
assert node_type in ['deprel', 'lemma', 'upos', 'xpos', 'form', 'feats'], '"node_type" is not set up correctly'
|
||||||
elif config.get('settings', 'node_type') == 'lemma':
|
cpu_cores = config.getint('settings', 'cpu_cores')
|
||||||
create_output_string_funct = create_output_string_lemma
|
if node_type == 'deprel':
|
||||||
elif config.get('settings', 'node_type') == 'upos':
|
create_output_string_funct = create_output_string_deprel
|
||||||
create_output_string_funct = create_output_string_upos
|
elif node_type == 'lemma':
|
||||||
elif config.get('settings', 'node_type') == 'xpos':
|
create_output_string_funct = create_output_string_lemma
|
||||||
create_output_string_funct = create_output_string_xpos
|
elif node_type == 'upos':
|
||||||
elif config.get('settings', 'node_type') == 'feats':
|
create_output_string_funct = create_output_string_upos
|
||||||
create_output_string_funct = create_output_string_feats
|
elif node_type == 'xpos':
|
||||||
else:
|
create_output_string_funct = create_output_string_xpos
|
||||||
create_output_string_funct = create_output_string_form
|
elif node_type == 'feats':
|
||||||
|
create_output_string_funct = create_output_string_feats
|
||||||
|
else:
|
||||||
|
create_output_string_funct = create_output_string_form
|
||||||
|
create_output_string_functs.append(create_output_string_funct)
|
||||||
|
|
||||||
result_dict = {}
|
result_dict = {}
|
||||||
filters = {}
|
filters = {}
|
||||||
|
@ -447,7 +451,7 @@ def main():
|
||||||
|
|
||||||
# 1.02 s (16 cores)
|
# 1.02 s (16 cores)
|
||||||
if cpu_cores > 1:
|
if cpu_cores > 1:
|
||||||
all_subtrees = p.map(tree_calculations, [(tree, query_tree, create_output_string_funct, filters) for tree in all_trees])
|
all_subtrees = p.map(tree_calculations, [(tree, query_tree, create_output_string_functs, filters) for tree in all_trees])
|
||||||
|
|
||||||
# for subtrees in all_subtrees:
|
# for subtrees in all_subtrees:
|
||||||
for tree_i, subtrees in enumerate(all_subtrees):
|
for tree_i, subtrees in enumerate(all_subtrees):
|
||||||
|
@ -471,7 +475,7 @@ def main():
|
||||||
# text = Če pa ostane odrasel otrok doma, se starši le težko sprijaznijo s tem, da je "velik", otrok pa ima ves čas občutek, da se njegovi starši po nepotrebnem vtikajo v njegovo življenje.
|
# text = Če pa ostane odrasel otrok doma, se starši le težko sprijaznijo s tem, da je "velik", otrok pa ima ves čas občutek, da se njegovi starši po nepotrebnem vtikajo v njegovo življenje.
|
||||||
# for tree_i, tree in enumerate(all_trees[5170:]):
|
# for tree_i, tree in enumerate(all_trees[5170:]):
|
||||||
# for tree in all_trees:
|
# for tree in all_trees:
|
||||||
subtrees = tree_calculations((tree, query_tree, create_output_string_funct, filters))
|
subtrees = tree_calculations((tree, query_tree, create_output_string_functs, filters))
|
||||||
for query_results in subtrees:
|
for query_results in subtrees:
|
||||||
for r in query_results:
|
for r in query_results:
|
||||||
# if r == '(" < , < je < velik) < tem':
|
# if r == '(" < , < je < velik) < tem':
|
||||||
|
@ -512,7 +516,7 @@ def main():
|
||||||
len_words = tree_size_range[-1]
|
len_words = tree_size_range[-1]
|
||||||
else:
|
else:
|
||||||
len_words = int(len(config.get('settings', 'query').split(" "))/2 + 1)
|
len_words = int(len(config.get('settings', 'query').split(" "))/2 + 1)
|
||||||
header = ["Structure"] + ["Word #" + str(i) for i in range(1, len_words + 1)] + ['Number of occurences']
|
header = ["Structure"] + ["Word #" + str(i) + "-" + node_type for i in range(1, len_words + 1) for node_type in node_types] + ['Number of occurences']
|
||||||
if config.get('settings', 'relative_number'):
|
if config.get('settings', 'relative_number'):
|
||||||
header += ['Relative frequency']
|
header += ['Relative frequency']
|
||||||
if config.get('settings', 'nodes_number'):
|
if config.get('settings', 'nodes_number'):
|
||||||
|
@ -522,7 +526,7 @@ def main():
|
||||||
|
|
||||||
# body
|
# body
|
||||||
for k, v in sorted_list:
|
for k, v in sorted_list:
|
||||||
words_only = v['object'].array + ['' for i in range(tree_size_range[-1] - len(v['object'].array))]
|
words_only = [word_att for word in v['object'].array for word_att in word] + ['' for i in range((tree_size_range[-1] - len(v['object'].array)) * len(v['object'].array[0]))]
|
||||||
# words_only = printable_answers(k)
|
# words_only = printable_answers(k)
|
||||||
row = [k] + words_only + [str(v['number'])]
|
row = [k] + words_only + [str(v['number'])]
|
||||||
if config.get('settings', 'relative_number'):
|
if config.get('settings', 'relative_number'):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user