-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWinEntityDisplay.py
More file actions
69 lines (56 loc) · 2.42 KB
/
WinEntityDisplay.py
File metadata and controls
69 lines (56 loc) · 2.42 KB
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
'''
Copyright 2022 SingerLinks Consulting
This file is part of spaCyWorkbench.
spaCyWorkbench is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
spaCyWorkbench is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with NLPSpacy. If not, see <https://www.gnu.org/licenses/>.
'''
try:
from tkinter import *
from tkinter import ttk
from tkinter.ttk import *
except ImportError:
from Tkinter import *
from Tkinter import ttk
from Tkinter.ttk import *
from tkinterweb import HtmlFrame
#from tkinterweb import HtmlLabel
#from pathlib import Path
from spacy import displacy
class WinEntityDisplay(Toplevel):
def __init__(self, master = None, sentence=None):
super().__init__(master = master)
self.title("Named Entities")
self.master = master
self.sentence = sentence
self.frmMain = Frame(self)
self.HTMLText = HtmlFrame(self.frmMain)
# grid the widgets
self.frmMain.grid(row = 0, column = 0, padx = 5, pady = 5, sticky=NSEW)
self.HTMLText.grid(row = 0, column = 0, padx = 5, pady = 5, sticky=NSEW)
# handle resizing
self.grid_columnconfigure(0, weight=1)
self.grid_rowconfigure(0, weight=1)
self.frmMain.grid_columnconfigure(0, weight=1)
self.frmMain.grid_rowconfigure(0, weight=1)
self.HTMLText.grid_columnconfigure(0, weight=1)
self.HTMLText.grid_rowconfigure(0, weight=1)
self.generateDiagram()
# size the window
self.geometry("{}x{}".format(int(self.winfo_screenwidth()*.8), int(self.winfo_screenheight()*.7)))
def generateDiagram(self):
# generate html
myHTML = displacy.render(self.sentence, style="ent")
# replace mark tags with span tags so htmllabel will work.
fix1 = myHTML.replace("<mark", "<span")
fix2 = fix1.replace("</mark","</span")
# print(fix2)
# display the text
self.HTMLText.load_html(fix2)