From 1f74ad8a8e926264aefc8b814919ec57007f2827 Mon Sep 17 00:00:00 2001
From: Stephan Porada <sporada@uni-bielefeld.de>
Date: Tue, 19 Nov 2019 11:48:00 +0100
Subject: [PATCH] Add Wrapper Version 2.0

---
 app/corpora/CQiWrapper/CQiWrapper.py         | 35 ++++++++++----------
 app/templates/corpora/analyse_corpus.html.j2 |  1 +
 2 files changed, 19 insertions(+), 17 deletions(-)

diff --git a/app/corpora/CQiWrapper/CQiWrapper.py b/app/corpora/CQiWrapper/CQiWrapper.py
index 133157a0..96d1f442 100644
--- a/app/corpora/CQiWrapper/CQiWrapper.py
+++ b/app/corpora/CQiWrapper/CQiWrapper.py
@@ -43,7 +43,6 @@ class CQiWrapper(CQiClient):
         """
         p_attrs = self.corpus_positional_attributes(self.corpus_name)
         struct_attrs = self.corpus_structural_attributes(self.corpus_name)
-        self.meta_struct_element = struct_attrs[0]
         self.attr_strings = {}
         self.attr_strings['positional_attrs'] = {}
         self.attr_strings['struct_attrs'] = {}
@@ -51,7 +50,7 @@ class CQiWrapper(CQiClient):
             self.attr_strings['positional_attrs'][p_attr] = (self.corpus_name
                                                              + '.'
                                                              + p_attr)
-        for struct_attr in struct_attrs[2:-1]:
+        for struct_attr in struct_attrs:
             self.attr_strings['struct_attrs'][struct_attr] = (self.corpus_name
                                                               + '.'
                                                               + struct_attr)
@@ -65,6 +64,7 @@ class CQiWrapper(CQiClient):
             logger.warning('{} does exist.'.format(corpus_name))
         else:
             logger.warning('{} does not exist.'.format(corpus_name))
+            pass
 
     def disconnect(self):
         """
@@ -197,6 +197,7 @@ class CQiWrapper(CQiClient):
                 ordered_matches[key]['context_before_cpos_list'] = before_context_infos
             except UnboundLocalError:
                 logger.warning('Context before cpos list is empty.')
+                pass
             try:
                 # loops over cpos in ordered_matches[key]['context_after_cpos_list']
                 # which holds all cpos of the before context
@@ -210,6 +211,7 @@ class CQiWrapper(CQiClient):
                 ordered_matches[key]['context_after_cpos_list'] = after_context_infos
             except UnboundLocalError:
                 logger.warning('Context after cpos list is empty.')
+                pass
         return ordered_matches
 
     def get_cpos_infos(self, all_cpos):
@@ -218,21 +220,20 @@ class CQiWrapper(CQiClient):
         all cpos entries specified in the parameter all_cpos.
         '''
         cpos_infos = {}
-        for attr_dict in self.attr_strings:
-            if attr_dict == 'positional_attrs':
-                for p_attr_key in self.attr_strings[attr_dict].keys():
-                    match_str = self.cl_cpos2str(self.attr_strings[attr_dict][p_attr_key],
-                                                 all_cpos)
-                    cpos_infos[p_attr_key] = match_str
-            elif attr_dict == 'struct_attrs':
-                # for struct_attr_key in self.attr_strings[attr_dict].keys():
-                #     logger.warning('HIER:' + struct_attr_key + " " + " " + self.attr_strings[attr_dict][struct_attr_key])
-                #     struct_entry = self.cl_cpos2struc(self.attr_strings['struct_attrs'][self.meta_struct_element],
-                #                                       all_cpos)
-                #     logger.warning(struct_entry)
-                #     match_str = self.cl_struc2str(self.attr_strings[attr_dict][struct_attr_key], struct_entry)
-                #     cpos_infos[struct_attr_key] = match_str
-                pass
+        for key in self.attr_strings.keys():
+            if key == 'positional_attrs':
+                for p_attr_key in self.attr_strings[key].keys():
+                    match_strs = self.cl_cpos2str(self.attr_strings[key][p_attr_key],
+                                                  all_cpos)
+                    cpos_infos[p_attr_key] = match_strs
+            elif key == 'struct_attrs':
+                for struct_attr_key in self.attr_strings[key].keys():
+                    struct_entry = self.cl_cpos2struc(self.attr_strings[key][struct_attr_key],
+                                                      all_cpos)
+                    logger.warning("{}: {}".format(self.attr_strings[key][struct_attr_key], struct_entry))
+                    match_strs = self.cl_struc2str(self.attr_strings[key][struct_attr_key], struct_entry)
+                    logger.warning('{}:{}'.format(self.attr_strings[key][struct_attr_key], match_strs))
+                    cpos_infos[struct_attr_key] = zip(struct_entry, match_strs)
         tmp_list = []
         attr_key_list = []
         for key in cpos_infos.keys():
diff --git a/app/templates/corpora/analyse_corpus.html.j2 b/app/templates/corpora/analyse_corpus.html.j2
index 64794325..003458c4 100644
--- a/app/templates/corpora/analyse_corpus.html.j2
+++ b/app/templates/corpora/analyse_corpus.html.j2
@@ -117,6 +117,7 @@
   });
   socket.on('query', function(results) {
     queryResultsElement.innerHTML = '';
+    console.log(results)
     for (let key in results) {
       console.log(results[key]);
       queryResultsElement.innerHTML += '<p>' + results[key]['match_cpos_list'] + '</p>';
-- 
GitLab