Skip to content

Commit 3f7375c

Browse files
Merge pull request avinashkranjan#2927 from smty2018/nlp4
Adjective Comparative and Superlative Generator using NLP
2 parents f0cf66d + 860843c commit 3f7375c

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Adjective Comparative and Superlative Generator using NLTK
2+
3+
This Python script takes a list of adjectives and generates their comparative and superlative forms using the `nltk` library and WordNet dataset. It's a simple tool to explore adjective transformations and language processing using NLTK.
4+
5+
Requirements:
6+
7+
pip install nltk
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import nltk
2+
nltk.download('wordnet')
3+
4+
from nltk.corpus import wordnet
5+
6+
def get_comp_sup(adjs):
7+
comp_sup = []
8+
9+
for adj in adjs:
10+
synsets = wordnet.synsets(adj)
11+
if synsets:
12+
syn = synsets[0]
13+
comp_forms = [lemma.name().replace('_', ' ') for lemma in syn.lemmas()]
14+
if len(comp_forms) >= 2:
15+
comp_form = comp_forms[1]
16+
else:
17+
comp_form = adj + "er"
18+
if len(comp_forms) >= 3:
19+
superl_form = comp_forms[2]
20+
else:
21+
superl_form = adj + "est"
22+
comp_sup.append((adj, comp_form, superl_form))
23+
24+
return comp_sup
25+
26+
def main():
27+
adjs = input("Enter a list of adjectives (comma-separated): ").split(',')
28+
29+
comp_sup = get_comp_sup(adjs)
30+
31+
print("\nAdjective\tComparative\tSuperlative")
32+
print("------------------------------------------")
33+
for adj, c, s in comp_sup:
34+
print(f"{adj}\t\t{c}\t\t{s}")
35+
36+
if __name__ == "__main__":
37+
main()

0 commit comments

Comments
 (0)