Pract - 6 Morpholigical Using Add Delete Table
Pract - 6 Morpholigical Using Add Delete Table
#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 = ['1.boys to boy','2.bachacha to bachacaa','3.bachacha to bachache','4.bachacha
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")
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
localhost:8888/notebooks/Desktop/NLP/pract_6_nlp.ipynb 4/4