4/12/23, 10:45 PM pract_6_nlp - Jupyter Notebook
Name : Gaurang Prabhakar Manchekar
PRN : 2043110118 Roll no:12
CODE/OP : Practical 6
#write a python program to implement morephological anaylsis of a given word using add/de
#importing prettytable library
from prettytable import PrettyTable
table = PrettyTable()
table.field_names = ["Delete", "Add",'Number','Gender','Case']
#adding rows to the table
table.add_row(["-","-","-","-","-"])
def display_table():
print(table)
display_table()
list_root = {'boys':['boy'],
'bachacha':{'bachacaa':['cha','aa','sg','m','dr'],'bachache':['cha','e','pl','m','obl'],'
'ladaki':{'ladaki':['i','i','sg','f','dr'],'ladakiya':['i','iya','pl','f','obl']},
'books':{'book':['s','-','sg','-','-']}
}
a = """add delete
1. boys to boy
2. bachacha to bachacaa
3. bachacha to bachache
4. bachacha to bachachon
5. ladaki to ladaki
6. ladaki to ladakiya
7. books to book
"""
print(a)
options = ['[Link] to boy','[Link] to bachacaa','[Link] to bachache','[Link]
i=1
while i:
table.del_row(0)
op = int(input("Enter your choice: "))
print("Selected option :",options[op-1])
root = input("Enter the root word: ")
variant = input("Enter the variant: ")
delete = input("Enter the delete: ")
add = input("Enter the add: ")
number = input("Enter the number: ")
gender = input("Enter the gender: ")
case = input("Enter the case: ")
input_given = [delete,add,number,gender,case]
#seraching for the root word and the variant and check the input given and the databa
if root in list_root:
if variant in list_root[root]:
if input_given == list_root[root][variant]:
#adding the row to the table
table.add_row([delete,add,number,gender,case])
display_table()
else:
print("Wrong")
else:
print("Variant not found")
i = int(input("Do you want to continue? 1/0: "))
localhost:8888/notebooks/Desktop/NLP/pract_6_nlp.ipynb 3/4
4/12/23, 10:45 PM pract_6_nlp - Jupyter Notebook
+--------+-----+--------+--------+------+
| Delete | Add | Number | Gender | Case |
+--------+-----+--------+--------+------+
| - | - | - | - | - |
+--------+-----+--------+--------+------+
add delete
1. boys to boy
2. bachacha to bachacaa
3. bachacha to bachache
4. bachacha to bachachon
5. ladaki to ladaki
6. ladaki to ladakiya
7. books to book
Enter your choice: 2
Selected option : [Link] to bachacaa
Enter the root word: bachacha
Enter the variant: bachacaa
Enter the delete: cha
Enter the add: aa
Enter the number: sg
Enter the gender: m
Enter the case: dr
+--------+-----+--------+--------+------+
| Delete | Add | Number | Gender | Case |
+--------+-----+--------+--------+------+
| cha | aa | sg | m | dr |
+--------+-----+--------+--------+------+
Do you want to continue? 1/0: 0
localhost:8888/notebooks/Desktop/NLP/pract_6_nlp.ipynb 4/4