def run(self, edit):
self.selection = self.view.sel()
self.pos = self.view.sel()[0]
if self.view.sel()[0].a == self.view.sel()[0].b:
self.view.run_command("expand_selection", {"to": "word"})
phrase = self.view.substr(self.selection[0]).lower()
if not phrase:
return # nothing selected
try:
word2vec_rst = word2vec_topn_outproc(self.word2vec_port, phrase, self.topn)
except URLError:
print('FancyWord: word2vec-api server is not reachable')
print('FancyWord: Will start word2vec-api server')
word2vec_rst = []
wordnet_rst = wordnet_topn(phrase, self.topn, self.lang)
self.suggestions = []
self.index_suggestions = []
if word2vec_rst:
self.index_suggestions += ['{}: {}'.format(idx + 1, sug) + (''.join(
[' ' * 4, '=' * 4, ' Word2Vec results:']) if idx == 0 else '') for idx, sug in enumerate(word2vec_rst)]
self.suggestions += word2vec_rst
len_word2vec_sug = len(word2vec_rst)
if wordnet_rst:
self.index_suggestions += ['{}: {}'.format(idx + len_word2vec_sug + 1, sug) + (''.join(
[' ' * 4, '=' * 4, ' Wordnet results:']) if idx == 0 else '') for idx, sug in enumerate(wordnet_rst)]
self.suggestions += wordnet_rst
if self.suggestions:
self.view.window().show_quick_panel(self.index_suggestions,
self.on_done,
sublime.MONOSPACE_FONT)
else:
sublime.status_message(
"FancyWord: can't find similar words for {}!".format(phrase))
self.on_done(-1)
评论列表
文章目录