-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpractice.py
More file actions
38 lines (29 loc) · 969 Bytes
/
practice.py
File metadata and controls
38 lines (29 loc) · 969 Bytes
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
import tkinter as tk
from tkinter import ttk
import nltk
from nltk.tokenize import word_tokenize
from nltk.corpus import wordnet as wn
# Run once if needed:
# nltk.download("punkt")
# nltk.download("wordnet")
# nltk.download("averaged_perceptron_tagger")
def analyze():
text = entry.get().strip()
tokens = word_tokenize(text) if text else []
synsets = wn.synsets(text.split()[0]) if text else []
output.set(
f"Tokens: {tokens}\n"
f"First word synsets: {[s.name() for s in synsets[:5]]}"
)
root = tk.Tk()
root.title("NLTK + Tkinter Smoke Test")
frame = ttk.Frame(root, padding=12)
frame.pack(fill="both", expand=True)
entry = ttk.Entry(frame, width=50)
entry.pack(fill="x")
entry.insert(0, "What is the point of all this?")
ttk.Button(frame, text="Analyze", command=analyze).pack(pady=8)
output = tk.StringVar(value="Ready")
ttk.Label(frame, textvariable=output, justify="left").pack(anchor="w")
root.mainloop()
print(output)