Skip to content

Commit 6f7c279

Browse files
Merge pull request prathimacode-hub#428 from akash435/pspeechbranch
Added Part Of Speech Calculator in GUIScript
2 parents d229a71 + 0b0733b commit 6f7c279

File tree

8 files changed

+153
-0
lines changed

8 files changed

+153
-0
lines changed
Loading
Loading
Loading
Loading
Loading
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# ✔ PART OD SPEECH CALCULATOR
2+
- ### A Part of Speech Calculator is an application created in python with tkinter gui.
3+
- ### In this application user can enter any text or sentence or paragraph, and will be able to get the count of each part of speech and what are they.
4+
5+
****
6+
7+
# REQUIREMENTS :
8+
- ### python 3
9+
- ### tkinter module
10+
- ### from tkinter messagebox module
11+
- ### PIL module
12+
- ### nltk
13+
- ### from nltk.corpus import stopwords
14+
- ### from nltk.tokenize import word_tokenize, sent_tokenize
15+
16+
****
17+
18+
# How this Script works :
19+
- ### User just need to download the file and run the part_of_speech_calculator.py on their local system.
20+
- ### Now on the main window of the game the user allowed to enter any text oe paragraph in given text area.
21+
- ### After entering the text in text area provided, when user clicks on the calculate button, a message box will be shown on the screen, showing the count of each part of speech and what are they.
22+
- ### Also there is a POF button, clicking on which user can see the 8 parts of speech in English.
23+
- ### Also there is a clear button, clicking on which user can clears the input text area.
24+
- ### Also there is an exit button, clicking on which exit dialog box appears asking for the permission of the user for closing the window.
25+
26+
****
27+
28+
# SCREENSHOTS :
29+
30+
****
31+
32+
<p align="center">
33+
<img width = 700 src="Images/1.jpg" /><br>
34+
<img width = 700 src="Images/2.jpg" /><br>
35+
<img width = 700 src="Images/3.jpg" /><br>
36+
<img width = 700 src="Images/4.jpg" /><br>
37+
<img width = 700 src="Images/5.jpg" /><br>
38+
</p>
39+
40+
****
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
2+
# Part Of Speech Calculator
3+
4+
import tkinter
5+
from tkinter import *
6+
import tkinter as tk
7+
import tkinter.messagebox as mbox
8+
import nltk
9+
from nltk.corpus import stopwords
10+
from nltk.tokenize import word_tokenize, sent_tokenize
11+
stop_words = set(stopwords.words('english'))
12+
# print(stop_words)
13+
14+
15+
def show_pof():
16+
mbox.showinfo("Parts Of Speech", "There are 8 parts of speech in the English language :\n\n1.) Noun - NN, NNP, NNS, NNPS\n\n2.) Pronoun - PRP\n\n3.) Verb - VB, VBD, VBG, VBN, VBP, VBZ\n\n4.) Adjective - JJ, JJR, JJS\n\n5.) Adverb - RB, RBR, RBS\n\n6.) Preposition - IN\n\n7.) Conjunction - IN, CC and\n\n8.) Interjection - UH")
17+
18+
def calcluate_pof():
19+
nouns1 = []
20+
pronouns1 = []
21+
verbs1 = []
22+
adjectives1 = []
23+
adverbs1 = []
24+
prepositions1 = []
25+
conjunctions1 = []
26+
interjections1 = []
27+
nouns = ""
28+
pronouns = ""
29+
verbs = ""
30+
adjectives = ""
31+
adverbs = ""
32+
prepositions = ""
33+
conjunctions = ""
34+
interjections = ""
35+
text = text_enter.get("1.0", "end-1c")
36+
tokenized = sent_tokenize(text)
37+
for i in tokenized:
38+
wordsList = nltk.word_tokenize(i)
39+
wordsList = [w for w in wordsList if not w in stop_words]
40+
tagged = nltk.pos_tag(wordsList)
41+
# print(tagged)
42+
43+
for word, pos in tagged:
44+
if (pos == 'NN' or pos == 'NNP' or pos == 'NNS' or pos == 'NNPS'): # noun
45+
nouns = nouns + word + " , "
46+
nouns1.append(word)
47+
if (pos == 'PRP'): # pronoun
48+
pronouns = pronouns + word + " , "
49+
pronouns1.append(word)
50+
if (pos == 'VB' or pos == 'VBD' or pos == 'VBG' or pos == 'VBN' or pos == 'VBP' or pos == 'VBZ'): # verb
51+
verbs = verbs + word + " , "
52+
verbs1.append(word)
53+
if (pos == 'JJ' or pos == 'JJR' or pos == 'JJS'): # adjective
54+
adjectives = adjectives + word + " , "
55+
adjectives1.append(word)
56+
if (pos == 'RB' or pos == 'RBR' or pos == 'RBS'): # adverb
57+
adverbs = adverbs + word + " , "
58+
adverbs1.append(word)
59+
if (pos == 'IN'): # prepositon
60+
prepositions = prepositions + word + " , "
61+
prepositions1.append(word)
62+
if (pos == 'IN' or pos == 'CC'): # conjunction
63+
conjunctions = conjunctions + word + " , "
64+
conjunctions1.append(word)
65+
if (pos == 'UH'): # interjection
66+
interjections = interjections + word + " , "
67+
interjections1.append(word)
68+
69+
mbox.showinfo("Count of POF", "Nouns : " + str(len(nouns1)) + "\nNouns are : " + nouns + "\n\nPronouns : " + str(len(pronouns1)) + "\nPronouns are : " + pronouns + "\n\nVerbs : " + str(len(verbs1)) + "\nVerbs are : " + verbs + "\n\nAdjectives : " + str(len(adjectives1)) + "\nAdjectives are : " + adjectives + "\n\nAdverbs : " + str(len(adverbs1)) + "\nAdverbs are : " + adverbs + "\n\nPrepositions : " + str(len(prepositions1)) + "\nPrepositions are : " + prepositions + "\n\nConjunctions : " + str(len(conjunctions1)) + "\nConjunctions are : " + conjunctions + "\n\nInterjection : " + str(len(interjections1)) + "\nInterjections are : " + interjections)
70+
71+
window = Tk()
72+
window.geometry("1000x700")
73+
window.title("Part Of Speech")
74+
# window.iconbitmap(r"icon.ico")
75+
76+
# starting label
77+
start1 = Label(window, text='Part of Speech Calculator', font=("Arial", 35),fg="magenta",underline=0)
78+
start1.place(x=200,y=10)
79+
80+
enter_label = Label(window, text="Enter Your text or paragraph here...", font=("Arial", 30),fg="brown")
81+
enter_label.place(x=150,y=100)
82+
83+
text_enter = tk.Text(window, height=15, width=80, font=("Arial", 15), bg="light yellow", fg="brown",borderwidth=3, relief="solid")
84+
text_enter.place(x=50, y=150)
85+
86+
pofb = Button(window, text="POF",command=show_pof,font=("Arial", 20), bg = "light green", fg = "blue", borderwidth=3, relief="raised")
87+
pofb.place(x =150 , y =570 )
88+
89+
calculateb = Button(window, text="CALCULATE",command=calcluate_pof,font=("Arial", 20), bg = "light green", fg = "blue", borderwidth=3, relief="raised")
90+
calculateb.place(x =280 , y =570 )
91+
92+
def clear_text():
93+
text_enter.delete("1.0","end")
94+
95+
resetb = Button(window, text="CLEAR",command=clear_text,font=("Arial", 20), bg = "light green", fg = "blue", borderwidth=3, relief="raised")
96+
resetb.place(x =530 , y =570 )
97+
98+
def exit_win():
99+
if mbox.askokcancel("Exit", "Do you want to exit?"):
100+
window.destroy()
101+
102+
exitb = Button(window, text="EXIT",command=exit_win,font=("Arial", 20), bg = "red", fg = "blue", borderwidth=3, relief="raised")
103+
exitb.place(x =700 , y =570 )
104+
105+
106+
window.protocol("WM_DELETE_WINDOW", exit_win)
107+
window.mainloop()
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
libraries used : tkinter
2+
messagebox
3+
from random import shuffle
4+
nltk
5+
from nltk.corpus import stopwords
6+
from nltk.tokenize import word_tokenize, sent_tokenize

0 commit comments

Comments
 (0)