Java Icon
Java Section 1 Project 2
July 23, 2018
Credit Cards
Data Structure Project 1
June 5, 2018

Dictionary

Personal Project

Description


The dictionary program that I have built is a program that will take a English word and give you the definition in return. For words that have two or more definition related to it, this program gives returns all definitions. Another feature of this program is when words are spelled incorrectly, it will give back a list of similar words to choose from. Other important features of this program is checking for lowercase, title, and uppercase versions of the word. With the program running a command line interface, you are passing the input through the command line and getting the output from the command line prompt. In the near future, I would like to expand this into web applications to make it more user friendly and with a web interface where the users can enter the input through a web form. I hope that you like this program! See you in the update!

Final Output

Personal Project


import json 
from difflib import get_close_matches
data = json.load(open('data.json'))


def translate(user_input):
    lower_word = user_input.lower()
    if lower_word in data:
        return data[lower_word]
    elif lower_word.title() in data:
        return data[lower_word.title()]
    elif lower_word.upper() in data:  # in case user enters words like USA or NATO
        return data[lower_word.upper()]
    elif len(get_close_matches(lower_word, data.keys())) > 0:
       ans = input("Did you mean %s instead? \nEnter yes or no " % get_close_matches(lower_word, data.keys())[0])
       lower_ans = ans.lower()
       if lower_ans == 'y' or lower_ans == 'yes':
            return data[get_close_matches(lower_word, data.keys())[0]]
       elif lower_ans == 'n' or lower_ans == 'n':
           return 'The word: ' + word + ' does not exist.\nPlease double check the word.'
       else:
           return 'I did not understand your entry'
    else:
        return 'The word: ' + word + ' does not exist.\nPlease double check the word.'


word = input("Enter Word: ")
output = translate(word)
if type(output) == list :
    for define in output:
        print(define)
else:
    print(output)

Would you like to look closer at this project?
Click a button