Added filtering with &

This commit is contained in:
Luka 2019-11-04 14:35:06 +01:00
parent 2b5478483a
commit 0fdfdb9556

View File

@ -36,42 +36,51 @@ def decode_query(orig_query, dependency_type):
new_query = True new_query = True
orig_query = orig_query[1:-1] orig_query = orig_query[1:-1]
orig_query_split = orig_query.split(' ')[0].split('=')
# if orig_query is '_' return {} # if orig_query is '_' return {}
if dependency_type != '': if dependency_type != '':
decoded_query = {'deprel': dependency_type} decoded_query = {'deprel': dependency_type}
else: else:
decoded_query = {} decoded_query = {}
if orig_query == '_': if orig_query == '_':
return decoded_query return decoded_query
# if no spaces in query then this is query node and do this otherwise further split query # if no spaces in query then this is query node and do this otherwise further split query
elif len(orig_query.split(' ')) == 1: elif len(orig_query.split(' ')) == 1:
if len(orig_query_split) > 1: orig_query_split_parts = orig_query.split(' ')[0].split('&')
if orig_query_split[0] == 'L': for orig_query_split_part in orig_query_split_parts:
decoded_query['lemma'] = orig_query_split[1] orig_query_split = orig_query_split_part.split('=')
return decoded_query if len(orig_query_split) > 1:
elif orig_query_split[0] == 'upos': if orig_query_split[0] == 'L':
decoded_query['upos'] = orig_query_split[1] decoded_query['lemma'] = orig_query_split[1]
return decoded_query # return decoded_query
elif orig_query_split[0] == 'xpos': elif orig_query_split[0] == 'upos':
decoded_query['xpos'] = orig_query_split[1] decoded_query['upos'] = orig_query_split[1]
return decoded_query # return decoded_query
elif orig_query_split[0] == 'form': elif orig_query_split[0] == 'xpos':
decoded_query['form'] = orig_query_split[1] decoded_query['xpos'] = orig_query_split[1]
return decoded_query # return decoded_query
elif orig_query_split[0] == 'feats': elif orig_query_split[0] == 'form':
decoded_query['feats'] = orig_query_split[1] decoded_query['form'] = orig_query_split[1]
return decoded_query # return decoded_query
# elif orig_query_split[0] in feats_list: elif orig_query_split[0] == 'feats':
# decoded_query['feats'] = {} decoded_query['feats'] = orig_query_split[1]
# decoded_query['feats'][orig_query_split[0]] = orig_query_split[1] # return decoded_query
# return decoded_query # elif orig_query_split[0] in feats_list:
# decoded_query['feats'] = {}
# decoded_query['feats'][orig_query_split[0]] = orig_query_split[1]
# return decoded_query
elif not new_query:
raise Exception('Not supported yet!')
else:
print('???')
elif not new_query: elif not new_query:
raise Exception('Not supported yet!') decoded_query['form'] = orig_query_split_part
elif not new_query: # return decoded_query
decoded_query['form'] = orig_query return decoded_query
return decoded_query
# split over spaces if not inside braces # split over spaces if not inside braces
# PATTERN = re.compile(r'''((?:[^ ()]|\([^.]*\))+)''') # PATTERN = re.compile(r'''((?:[^ ()]|\([^.]*\))+)''')