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) p_attrs = self.corpus_positional_attributes(self.corpus_name)
struct_attrs = self.corpus_structural_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 = {}
self.attr_strings['positional_attrs'] = {} self.attr_strings['positional_attrs'] = {}
self.attr_strings['struct_attrs'] = {} self.attr_strings['struct_attrs'] = {}
@ -51,7 +50,7 @@ class CQiWrapper(CQiClient):
self.attr_strings['positional_attrs'][p_attr] = (self.corpus_name self.attr_strings['positional_attrs'][p_attr] = (self.corpus_name
+ '.' + '.'
+ p_attr) + 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 self.attr_strings['struct_attrs'][struct_attr] = (self.corpus_name
+ '.' + '.'
+ struct_attr) + struct_attr)
@ -65,6 +64,7 @@ class CQiWrapper(CQiClient):
logger.warning('{} does exist.'.format(corpus_name)) logger.warning('{} does exist.'.format(corpus_name))
else: else:
logger.warning('{} does not exist.'.format(corpus_name)) logger.warning('{} does not exist.'.format(corpus_name))
pass
def disconnect(self): def disconnect(self):
""" """
@ -197,6 +197,7 @@ class CQiWrapper(CQiClient):
ordered_matches[key]['context_before_cpos_list'] = before_context_infos ordered_matches[key]['context_before_cpos_list'] = before_context_infos
except UnboundLocalError: except UnboundLocalError:
logger.warning('Context before cpos list is empty.') logger.warning('Context before cpos list is empty.')
pass
try: try:
# loops over cpos in ordered_matches[key]['context_after_cpos_list'] # loops over cpos in ordered_matches[key]['context_after_cpos_list']
# which holds all cpos of the before context # 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 ordered_matches[key]['context_after_cpos_list'] = after_context_infos
except UnboundLocalError: except UnboundLocalError:
logger.warning('Context after cpos list is empty.') logger.warning('Context after cpos list is empty.')
pass
return ordered_matches return ordered_matches
def get_cpos_infos(self, all_cpos): def get_cpos_infos(self, all_cpos):
@ -218,21 +220,20 @@ class CQiWrapper(CQiClient):
all cpos entries specified in the parameter all_cpos. all cpos entries specified in the parameter all_cpos.
''' '''
cpos_infos = {} cpos_infos = {}
for attr_dict in self.attr_strings: for key in self.attr_strings.keys():
if attr_dict == 'positional_attrs': if key == 'positional_attrs':
for p_attr_key in self.attr_strings[attr_dict].keys(): for p_attr_key in self.attr_strings[key].keys():
match_str = self.cl_cpos2str(self.attr_strings[attr_dict][p_attr_key], match_strs = self.cl_cpos2str(self.attr_strings[key][p_attr_key],
all_cpos) all_cpos)
cpos_infos[p_attr_key] = match_str cpos_infos[p_attr_key] = match_strs
elif attr_dict == 'struct_attrs': elif key == 'struct_attrs':
# for struct_attr_key in self.attr_strings[attr_dict].keys(): for struct_attr_key in self.attr_strings[key].keys():
# logger.warning('HIER:' + struct_attr_key + " " + " " + self.attr_strings[attr_dict][struct_attr_key]) struct_entry = self.cl_cpos2struc(self.attr_strings[key][struct_attr_key],
# struct_entry = self.cl_cpos2struc(self.attr_strings['struct_attrs'][self.meta_struct_element], all_cpos)
# all_cpos) logger.warning("{}: {}".format(self.attr_strings[key][struct_attr_key], struct_entry))
# logger.warning(struct_entry) match_strs = self.cl_struc2str(self.attr_strings[key][struct_attr_key], struct_entry)
# match_str = self.cl_struc2str(self.attr_strings[attr_dict][struct_attr_key], struct_entry) logger.warning('{}:{}'.format(self.attr_strings[key][struct_attr_key], match_strs))
# cpos_infos[struct_attr_key] = match_str cpos_infos[struct_attr_key] = zip(struct_entry, match_strs)
pass
tmp_list = [] tmp_list = []
attr_key_list = [] attr_key_list = []
for key in cpos_infos.keys(): for key in cpos_infos.keys():

View File

@ -117,6 +117,7 @@
}); });
socket.on('query', function(results) { socket.on('query', function(results) {
queryResultsElement.innerHTML = ''; queryResultsElement.innerHTML = '';
console.log(results)
for (let key in results) { for (let key in results) {
console.log(results[key]); console.log(results[key]);
queryResultsElement.innerHTML += '<p>' + results[key]['match_cpos_list'] + '</p>'; queryResultsElement.innerHTML += '<p>' + results[key]['match_cpos_list'] + '</p>';