Max_Len=4
def MM(query,your_dict,Max_Len):
mm_query_label=[]
len_query=len(query)
while(len_query>0):
cur_len = min(len_query,Max_Len)
cur_text =query[:cur_len]
ner_flag = False
while cur_len > 0:
if cur_text in your_dict:
ner_flag = True
mm_query_label.append(cur_text)
query = query[cur_len:]
len_query = len(query)
break
if not ner_flag:
cur_text = cur_text[:-1]
cur_len -= 1
if not ner_flag:
mm_query_label.append(query[0])
query = query[1:]
len_query=len(query)
return mm_query_label
def RMM(query,your_dict,Max_Len):
rmm_query_label=[]
len_query=len(query)
while(len_query>0):
cur_len = min(len_query,Max_Len)
cur_text =query[-cur_len:]
ner_flag = False
while cur_len > 0:
if cur_text in your_dict:
ner_flag = True
rmm_query_label.append(cur_text)
query = query[:-cur_len]
len_query = len(query)
print(cur_text)
break
if not ner_flag:
cur_text = cur_text[1:]
cur_len -= 1
if not ner_flag:
rmm_query_label.append(query[-1])
query = query[:-1]
len_query=len(query)
return rmm_query_label[::-1]