-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGrammer_Sorting.py
More file actions
70 lines (64 loc) · 2.55 KB
/
Copy pathGrammer_Sorting.py
File metadata and controls
70 lines (64 loc) · 2.55 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
69
70
# Dictionary of grammatical terms
grammar_terms = {
"verbs": [
"run", "walk", "jump", "eat", "sleep", "go", "play", "talk", "think", "work", "am",
"write", "sing", "dance", "is", "are", "was", "were", "have", "has", "do", "make", "give"
],
"adverbs": [
"quickly", "slowly", "happily", "sadly", "very", "well", "fast", "loudly",
"quietly", "carefully", "easily", "soon", "yesterday", "often", "sometimes",
"never", "always", "here", "there", "now"
],
"adjectives": [
"big", "small", "tall", "short", "happy", "sad", "fast", "slow", "bright",
"dark", "beautiful", "ugly", "easy", "difficult", "strong", "weak", "young",
"old", "new", "good", "bad"
],
"prepositions": [
"in", "on", "at", "over", "under", "through", "between", "behind", "before",
"after", "with", "without", "about", "around", "across", "against", "near",
"by", "for", "during"
],
"nouns": [
"dog", "cat", "house", "car", "book", "park", "computer", "phone", "apple",
"tree", "chair", "city", "water", "teacher", "student", "sky", "sun",
"table", "friend", "family"
],
"pronouns": [
"i", "you", "he", "she", "it", "we", "they", "me", "him", "her", "them",
"us", "my", "your", "his", "her", "their", "its", "mine", "yours"
],
"conjunctions": [
"and", "but", "or", "so", "because", "although", "if", "when", "while",
"since", "though", "unless", "as", "yet", "nor"
],
"determiners": [
"a", "an", "the", "this", "that", "these", "those", "my", "your", "his",
"her", "its", "our", "their", "some", "any", "many", "few", "several"
],
"interjections": [
"wow", "oh", "ouch", "hey", "oops", "ah", "hmm", "yay", "ugh", "alas"
],
"articles": [
"a", "an", "the"
]
}
# Function to check if a word is in the dictionary
def is_word_in_dictionary(word):
for key in grammar_terms:
if word in grammar_terms[key]:
return True, key
return False, None
text = input("enter your desirable text: ").split()
sorted_dict = {}
print(text)
# sorting the input list in dictnory as per the grammar
for i in text:
if is_word_in_dictionary(i)[0]:
if is_word_in_dictionary(i)[1] in sorted_dict:
sorted_dict[is_word_in_dictionary(i)[1]].append(i)
else:
sorted_dict[is_word_in_dictionary(i)[1]] = [i]
else:
print(f"'{i}' is not in the dictionary")
print(sorted_dict)