0% found this document useful (0 votes)
35 views

Pract - 6 Morpholigical Using Add Delete Table

The document describes a Python program that implements morphological analysis of words. It takes user input for a root word and its variant, and checks if the morphological changes like deletion, addition of characters and other attributes match the data in a dictionary. A prettytable is used to display the output. The program runs an interactive loop taking the user's choice of morphological analysis from options provided and verifies the user input against the dictionary data.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views

Pract - 6 Morpholigical Using Add Delete Table

The document describes a Python program that implements morphological analysis of words. It takes user input for a root word and its variant, and checks if the morphological changes like deletion, addition of characters and other attributes match the data in a dictionary. A prettytable is used to display the output. The program runs an interactive loop taking the user's choice of morphological analysis from options provided and verifies the user input against the dictionary data.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

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 = ['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")

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 : 2.bachacha 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

You might also like