Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commit 117c2dd

Browse files
jmamoupeteriz
authored andcommitted
cancel case feature if grouping (#263)
* cancel case feature if grouping * remove vocab assertion * adjust table selection callback to comply with latest bokeh
1 parent 0177f28 commit 117c2dd

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

solutions/set_expansion/set_expand.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,11 @@ def __id2term(self, id):
9494
"""
9595
norm = id.replace(self.mark_char, ' ')[:-1]
9696
if self.grouping:
97-
assert(norm in self.id2rep)
98-
return self.id2rep[norm]
97+
if norm in self.id2rep:
98+
return self.id2rep[norm]
99+
else:
100+
logger.warning("id:#%s#, norm:#%s# is not in id2rep")
101+
return ""
99102
return norm
100103

101104
def get_vocab(self):
@@ -137,17 +140,19 @@ def expand(self, seed, topn=500):
137140
lower = True
138141
for np in seed:
139142
np = np.strip()
140-
if np[0].islower():
141-
upper = False
142-
else:
143-
lower = False
143+
if not self.grouping and (upper or lower):
144+
# case feature is relevant only if we don't have grouping
145+
if np[0].islower():
146+
upper = False
147+
else:
148+
lower = False
144149
id = self.__term2id(np)
145150
if id is not None:
146151
seed_ids.append(id)
147152
else:
148153
logger.warning("The term: '%s' is out-of-vocabulary.", np)
149154
if len(seed_ids) > 0:
150-
if upper or lower:
155+
if not self.grouping and (upper or lower):
151156
res_id = self.np2vec_model.most_similar(seed_ids, topn=2 * topn)
152157
else:
153158
res_id = self.np2vec_model.most_similar(seed_ids, topn=topn)
@@ -156,7 +161,7 @@ def expand(self, seed, topn=500):
156161
if len(res) == topn:
157162
break
158163
# pylint: disable=R0916
159-
if (not lower and not upper) or (upper and r[0][0].isupper()) or \
164+
if self.grouping or (not lower and not upper) or (upper and r[0][0].isupper()) or \
160165
(lower and r[0][0].islower()):
161166
res.append((self.__id2term(r[0]), r[1]))
162167
return res

solutions/set_expansion/ui/main.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,15 @@ def send_request_to_server(request):
147147
sock.close()
148148

149149

150-
def row_selected_callback(attr, old, new):
150+
def row_selected_callback(indices, old, new):
151+
logger.info('row selected callback')
151152
global clear_flag, all_selected_phrases
152153
if not clear_flag and expand_table_source.data != empty_table:
153154
logger.info('row selected callback. old indices=%s. new indices=%s',
154-
str(old.indices), str(new.indices))
155+
str(old), str(new))
155156
# sync phrases lists:
156-
old_phrases = [expand_table_source.data['res'][p] for p in old.indices]
157-
new_phrases = [expand_table_source.data['res'][p] for p in new.indices]
157+
old_phrases = [expand_table_source.data['res'][p] for p in old]
158+
new_phrases = [expand_table_source.data['res'][p] for p in new]
158159
logger.info('selected_expand was updated: old=%s ,new=%s', str(
159160
old_phrases), str(new_phrases))
160161
# phrase was de-selected from expand list:
@@ -372,7 +373,7 @@ def get_selected_phrases_for_seed():
372373
return phrases
373374

374375

375-
def expand_data_changed_callback(attr, old, new):
376+
def expand_data_changed_callback(data, old, new):
376377
"""
377378
remove the selected indices when table is empty
378379
"""
@@ -384,7 +385,7 @@ def expand_data_changed_callback(attr, old, new):
384385

385386
expand_button.on_click(get_expand_results_callback)
386387
# save_button.on_click(save_data_callback)
387-
expand_table_source.on_change('selected', row_selected_callback)
388+
expand_table_source.selected.on_change('indices', row_selected_callback)
388389
expand_table_source.on_change('data', expand_data_changed_callback)
389390
checkbox_group.on_click(show_phrases_callback)
390391
search_input_box.on_change('value', search_callback)

0 commit comments

Comments
 (0)