From 9dc71b58c23cde3e79dbdd53682a813b6d25b915 Mon Sep 17 00:00:00 2001 From: Luka Date: Thu, 29 Aug 2019 16:47:33 +0200 Subject: [PATCH] Added some fixes --- Tree.py | 18 +++++++++++------- dependency-parsetree.py | 21 ++++++++++++++++++--- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/Tree.py b/Tree.py index f2fe718..33eaf8d 100644 --- a/Tree.py +++ b/Tree.py @@ -39,11 +39,11 @@ class Tree(object): self.parent = parent def fits_static_requirements(self, query_tree): - return ('form' not in query_tree or query_tree['form'] == self.form.get_value) and \ - ('lemma' not in query_tree or query_tree['lemma'] == self.lemma.get_value) and \ - ('upos' not in query_tree or query_tree['upos'] == self.upos.get_value) and \ - ('xpos' not in query_tree or query_tree['xpos'] == self.xpos.get_value) and \ - ('deprel' not in query_tree or query_tree['deprel'] == self.deprel.get_value) + return ('form' not in query_tree or query_tree['form'] == self.form.get_value()) and \ + ('lemma' not in query_tree or query_tree['lemma'] == self.lemma.get_value()) and \ + ('upos' not in query_tree or query_tree['upos'] == self.upos.get_value()) and \ + ('xpos' not in query_tree or query_tree['xpos'] == self.xpos.get_value()) and \ + ('deprel' not in query_tree or query_tree['deprel'] == self.deprel.get_value()) def generate_children_queries(self, all_query_indices, children): partial_results = {} @@ -220,10 +220,14 @@ class Tree(object): i += 1 completed_subtrees = l_completed_subtrees - for i in range(len(permanent_query_trees)): + # for i in range(len(permanent_query_trees)): + # for i in range(max(len(completed_subtrees), len(r_completed_subtrees), len(active_permanent_query_trees))): + for i in range(len(active_permanent_query_trees)): + # if 0 < len(active_permanent_query_trees): completed_subtrees[i].extend(merged_partial_subtrees[i]) + for i in range(len(r_completed_subtrees)): completed_subtrees[i].extend(r_completed_subtrees[i]) - return merged_partial_subtrees[len(permanent_query_trees):], completed_subtrees + return merged_partial_subtrees[len(active_permanent_query_trees):], completed_subtrees @staticmethod def merge_results(old_results, new_results): diff --git a/dependency-parsetree.py b/dependency-parsetree.py index 78394ce..6340334 100644 --- a/dependency-parsetree.py +++ b/dependency-parsetree.py @@ -18,11 +18,25 @@ def decode_query(orig_query): new_query = True orig_query = orig_query[1:-1] + orig_query_split = orig_query.split(' ')[0].split('=') # if orig_query is '_' return {} if orig_query == '_': return {} - elif not new_query: - raise Exception('Not supported yet!') + # if no spaces in query then this is query node and do this otherwise further split query + elif len(orig_query.split(' ')) == 1: + if len(orig_query_split) > 1: + if orig_query_split[0] == 'L': + return {'lemma': orig_query_split[1]} + elif orig_query_split[0] == 'upos': + return {'upos': orig_query_split[1]} + elif orig_query_split[0] == 'xpos': + return {'xpos': orig_query_split[1]} + elif orig_query_split[0] == 'form': + return {'form': orig_query_split[1]} + elif not new_query: + raise Exception('Not supported yet!') + elif not new_query: + return {'form': orig_query} # split over spaces if not inside braces PATTERN = re.compile(r'''((?:[^ ()]|\([^(]*\))+)''') @@ -128,7 +142,7 @@ def main(): # set filters - assert config.get('settings', 'analyze_type') in ['deprel', 'lemma', 'upos', 'upos', 'xpos', 'form'], '"analyze_type" is not set up correctly' + assert config.get('settings', 'analyze_type') in ['deprel', 'lemma', 'upos', 'xpos', 'form'], '"analyze_type" is not set up correctly' if config.get('settings', 'analyze_type') == 'deprel': create_output_string_funct = create_output_string_deprel elif config.get('settings', 'analyze_type') == 'lemma': @@ -143,6 +157,7 @@ def main(): result_dict = {} # for tree in all_trees[2:]: + # for tree in all_trees[1205:]: for tree in all_trees: # original # r_children = tree.r_children[:1] + tree.r_children[3:4]