Add Wrapper Version 2.0

This commit is contained in:
Stephan Porada 2019-11-19 11:48:00 +01:00
parent e3db29e476
commit 1f74ad8a8e
2 changed files with 19 additions and 17 deletions

View File

@ -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():

View File

@ -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>';