Skip to content

Commit 90ce8a5

Browse files
committed
Create word2word.py
1 parent d0aa6ee commit 90ce8a5

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#-*- coding: utf-8 -*-
2+
from word2word.utils import download_or_load
3+
4+
class Word2word:
5+
def __init__(self, lang1, lang2):
6+
self.word2x, self.y2word, self.x2ys = download_or_load(lang1, lang2)
7+
8+
def __call__(self, query, n_best=5):
9+
if query not in self.word2x:
10+
print("Sorry. There's no such word in the dictionary.")
11+
x = self.word2x[query]
12+
ys = self.x2ys[x]
13+
words = [self.y2word[y] for y in ys]
14+
return words[:n_best]

0 commit comments

Comments
 (0)