-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnlp_wrapper.py
92 lines (68 loc) · 2.92 KB
/
nlp_wrapper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# To add a new cell, type '# %%'
# To add a new markdown cell, type '# %% [markdown]'
# %%
from tkinter import *
from tkinter import messagebox
import langid, ARI, soundex
# %%
class Error(Exception):
pass
class No_plugin_selected(Error):
pass
class No_text_inserted(Error):
pass
# %%
class Application(Frame):
def __init__(self, master=None, active_plugin = None, string = None):
Frame.__init__(self,master)
self.createWidgets()
self.pack()
self.string = string
self.active_plugin = active_plugin
def set_current_plugin(self, plugin_name):
self.active_plugin = plugins_list[plugin_name]
def createWidgets(self):
self.Input_box1 = Text(self)
self.Input_box1["height"] = 10
self.Input_box1.grid(row = 0, column = 0, padx = 10, pady = 10, sticky = "NW")
self.Output_box1 = Text(self)
self.Output_box1["height"] = 10
self.Output_box1.grid(row = 1, column = 0, padx = 10, pady = 10, sticky = "NW")
self.Action_button = Button(self, padx = 50, pady = 20, text = "Run", command= self.print_text)
self.Action_button.grid(row = 0, column = 1, padx = 10, pady = 10, sticky = "NW")
self.Clear_button = Button(self, padx = 50, pady = 20, text = "Clear", command= self.clearall)
self.Clear_button.grid(row = 0, column = 2, padx = 10, pady = 10, sticky = "NW")
self.menubar = Menu(self.master)
self.filemenu = Menu(self.menubar, tearoff=0)
self.menubar.add_cascade(label="Plugins", menu=self.filemenu)
self.master.config(menu=self.menubar)
def print_text(self):
self.string = self.Input_box1.get("1.0","end-1c")
try:
if self.active_plugin is None:
raise No_plugin_selected
elif not self.string:
raise No_text_inserted
self.Output_box1.delete("1.0",END)
tx = self.active_plugin(self.string)
self.Output_box1.insert("1.0", tx)
except (No_plugin_selected, TypeError):
messagebox.showerror(title = "No Plugin", message = "Please select a Plugin")
except No_text_inserted:
messagebox.showerror(title = "No Text", message = "Please enter text")
def clearall(self):
self.Input_box1.delete("1.0",END)
self.Output_box1.delete("1.0",END)
def add_plugins_from_list(self,array):
for plugin in plugins_list.keys():
self.filemenu.add_radiobutton(label=plugin, command= lambda local_plugin = plugin: self.set_current_plugin(local_plugin))
# %%
if __name__ == '__main__':
plugins_list = {
"Language Detector": langid.lang_id,
"ARI Calculator": ARI.ARI_rawtext,
"Soundex": soundex.Soundex
}
app = Application(master=Tk())
app.add_plugins_from_list(plugins_list)
app.mainloop()