Skip to content
This repository was archived by the owner on Apr 24, 2025. It is now read-only.

Commit 3ad3576

Browse files
committed
adjactive compartive suplerlative finder, with customized JSON file
1 parent 4755518 commit 3ad3576

3 files changed

Lines changed: 113 additions & 0 deletions

File tree

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
from nltk.corpus import wordnet
2+
import nltk
3+
import re
4+
import json
5+
6+
nltk.download('wordnet', quiet=True)
7+
8+
# Load irregular adjectives from a JSON file
9+
with open('irregular_adjectives.json', 'r') as f:
10+
IRREGULAR_ADJECTIVES = json.load(f)
11+
12+
13+
def get_comp_sup(adjs):
14+
comp_sup = []
15+
16+
for adj in adjs:
17+
synsets = wordnet.synsets(adj, pos=wordnet.ADJ)
18+
if synsets:
19+
syn = synsets[0]
20+
comp_forms = [lemma.name().replace('_', ' ')
21+
for lemma in syn.lemmas()]
22+
if len(comp_forms) >= 2:
23+
comp_form = comp_forms[1]
24+
else:
25+
comp_form = get_comparative_form(adj)
26+
if len(comp_forms) >= 3:
27+
superl_form = comp_forms[2]
28+
else:
29+
superl_form = get_superlative_form(adj)
30+
comp_sup.append((adj, comp_form, superl_form))
31+
else:
32+
comp_sup.append((adj, get_comparative_form(adj), get_superlative_form(adj)))
33+
34+
return comp_sup
35+
36+
37+
def get_comparative_form(adj):
38+
if adj in IRREGULAR_ADJECTIVES:
39+
return IRREGULAR_ADJECTIVES[adj][0]
40+
elif re.match(r"^[aeiou][a-z]*$", adj):
41+
return adj + "er"
42+
else:
43+
return "more " + adj
44+
45+
46+
def get_superlative_form(adj):
47+
if adj in IRREGULAR_ADJECTIVES:
48+
return IRREGULAR_ADJECTIVES[adj][1]
49+
elif re.match(r"^[aeiou][a-z]*$", adj):
50+
return adj + "est"
51+
else:
52+
return "most " + adj
53+
54+
55+
def main():
56+
adjs = input("Enter a list of adjectives (comma-separated): ").split(',')
57+
adjs = [adj.strip() for adj in adjs]
58+
59+
comp_sup = get_comp_sup(adjs)
60+
61+
print("\nAdjective\tComparative\tSuperlative")
62+
print("------------------------------------------")
63+
for adj, c, s in comp_sup:
64+
print(f"{adj}\t\t{c}\t\t{s}")
65+
66+
67+
if __name__ == "__main__":
68+
main()
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"good": ["better", "best"],
3+
"fat":["fatter", "fattest"],
4+
"nice":["nice", "nicest"],
5+
"bad": ["worse", "worst"],
6+
"little": ["less", "least"],
7+
"much": ["more", "most"],
8+
"many": ["more", "most"],
9+
"far": ["further", "furthest"],
10+
"old": ["older", "oldest"],
11+
"late": ["later", "latest"],
12+
"early": ["earlier", "earliest"],
13+
"well": ["better", "best"],
14+
"ill": ["worse", "worst"],
15+
"near": ["nearer", "nearest"],
16+
"low": ["lower", "lowest"],
17+
"high": ["higher", "highest"],
18+
"deep": ["deeper", "deepest"],
19+
"long": ["longer", "longest"],
20+
"short": ["shorter", "shortest"],
21+
"wide": ["wider", "widest"],
22+
"narrow": ["narrower", "narrowest"],
23+
"big": ["bigger", "biggest"],
24+
"small": ["smaller", "smallest"],
25+
"young": ["younger", "youngest"],
26+
"full": ["fuller", "fullest"],
27+
"hot": ["hotter", "hottest"],
28+
"cold": ["colder", "coldest"],
29+
"happy": ["happier", "happiest"],
30+
"sad": ["sadder", "saddest"],
31+
"easy": ["easier", "easiest"],
32+
"hard": ["harder", "hardest"],
33+
"heavy": ["heavier", "heaviest"],
34+
"light": ["lighter", "lightest"],
35+
"fast": ["faster", "fastest"],
36+
"slow": ["slower", "slowest"],
37+
"strong": ["stronger", "strongest"],
38+
"weak": ["weaker", "weakest"],
39+
"rich": ["richer", "richest"],
40+
"poor": ["poorer", "poorest"],
41+
"dirty": ["dirtier", "dirtiest"],
42+
"clean": ["cleaner", "clearest"],
43+
"new": ["newer", "newest"]
44+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nltk

0 commit comments

Comments
 (0)