This program is in python and thanks fro whoever help me.
In this program, you will build an English to Hmong translator program. Hmong is a language widely spoken by most Southeast Asian living in the twin cities.
The program lets the user type in a sentence in English and then translate it to a Hmong sentence. The program does not care about grammar or punctuation marks. That means your program should remove punctuation marks from the English words before attempt to translate them. Make sure it is case insensitive. You are given a file containing tuples of entry number, English word, and Hmong word.
If the dictionary does not contain the English word, simply put a question mark (?) as the translation.
Your program should consists of the following functions:
|
load_dictionary(filename) |
Read the file containing the tuples, insert the entries into the dictionary and return the dictionary object. |
|
translate(sentence) |
Take a sentence in English and return a sentence in English. |
|
print_word_frequency() |
Print the frequency of English words that were translated. |
|
main |
The main logic loop. |
The main loop:
The program prompts the user for an English sentence. It translate each word in Hmong and print the Hmong words in a sentence. If an English word does not exist in the dictionary, it uses ? as the Hmong translation of that word. Each time the program finishes translating, it asks the user if they want to continue. If not, it displays the English words and the number of time the words have been entered into the program. See sample run below.
Sample run:
Type your English sentence: I can help you help him.
Hmong: kuv tau pab koj pab nws
Another translation (Y/N): Y
Type your English sentence: You can help me.
Hmong: koj tau pab kuv.
Another translation (Y/N): N
Word Frequency
-----------------------
i 1
can 2
you 2
help 2
him 1
Hi. I have answered this same question before.
Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks
Note: Please maintain proper code spacing (indentation), just copy the code part and paste it in your compiler/IDE directly, no modifications required (except if you want to change input file name)
#code
import string
#method to load hmong dictionary from file
def load_dictionary(filename):
#opening file
file=open(filename)
#creating empty dict
data=dict()
#looping through each line
for line in file:
#splitting line by comma
fields=line.strip().split(',')
#ensuring the length of result list
if len(fields)==3:
#extracting value at index 1 as hmong word, index2 as english word
hmong=fields[1].lower()
eng=fields[2].lower()
#adding to dict, with eng word being key an hmong word being value
data[eng]=hmong
#closing file
file.close()
#returning data
return data
#helper method to format a text
def format(text):
#converting text to lower
text = text.lower()
#looping and removing all puntuation symbols from text
for i in string.punctuation:
text = text.replace(i, ' ')
#returning formatted text
return text
#method to translate a sentence
def translate(sentence, data):
#variable to store translated text
translated=''
#looping through each word in sentence
for word in sentence.split():
#if word is in dict, appending corresponding hmong word to translated
if word in data:
translated+=data[word]+' '
else:
#else, appending a ? symbol
translated+='? '
#returning translated text, after removing trailing white space
return translated.strip()
#method to print word frequency
def print_word_frequency(text):
counts=dict()
#looping and counting frequency of each word in text
for word in text.split():
#if word already in counts, adding 1 to count, else adding with 1 as count
if word in counts:
counts[word]+=1
else:
counts[word]=1
#displaying heading
print('{:10s} {:10s}'.format('Word', 'Frequency'))
print('---------------------')
#looping and printing each word and count
for word in counts:
print('{:10s} {:10d}'.format(word,counts[word]))
#main method
def main():
#loading dictionary from a file called dictionary.txt, make sure that the file name
#is correct, or else, use correct file name as in your system
data=load_dictionary('dictionary.txt')
loop=True #loop controller
text='' #variable to store all text entered by user
#looping as long as loop is True
while loop:
#reading sentence, formatting it
sentence=input("Type your English sentence: ")
sentence=format(sentence)
#translating it, printing translation
translated=translate(sentence,data)
print('Hmong:',translated)
#appending to text
text+=sentence+' '
#setting loop to True if input is y or Y, else False
loop=input("Another translation (Y/N): ").lower()=='y'
#at the end, printing word frequency
print_word_frequency(text)
#calling main()
main()
#input file name format

#output

This program is in python and thanks fro whoever help me. In this program, you will...
Please complete the following: Write a Python script to do the following: 1. Ask the use to enter several sentences, one at a time in a loop). To end the sentence entry, the user enters a blank (empty) sentence. 2. Extract each word from each sentence and put it in a list. This will require at least one loop to go through each sentence in the list. It is up to you how you want to get the words in...
Please use PYTHON3 to Create a program that translates English into Pig Latin. The function will take the first letter of each word in the sentence only if it’s a not a vowel, and place it at the end of the word followed by “ay”. Your program must be case insensitive. You must write the function translate() that takes in a single English word and returns its Pig Latin translation. Remember translate must take only one word as input. #############################################################...
In this lab you will write a spell check program. The program has two input files: one is the dictionary (a list of valid words) and the other is the document to be spellchecked. The program will read in the words for the dictionary, then will read the document and check whether each word is found in the dictionary. If not, the user will be prompted to leave the word as is or type in a replacement word and add...
Write a program IN PYTHON that checks the spelling of all words in a file. It should read each word of a file and check whether it is contained in a word list. A word list available below, called words.txt. The program should print out all words that it cannot find in the word list. Requirements Your program should implement the follow functions: main() The main function should prompt the user for a path to the dictionary file and a...
Dictionary.java
DictionaryInterface.java
Spell.java
SpellCheck.java
In this lab you will write a spell check program. The program has two input files: one is the dictionary (a list of valid words) and the other is the input file to be spell checked. The program will read in the words for the dictionary, then will read the input file and check whether each word is found in the dictionary. If not, the user will be prompted to leave the word as is, add...
In Java please
Only use methods in the purpose.
Thank you
The purpose of this assignment is to help you learn Java identifiers, assignments, input/output nested if and if/else statements, switch statements and non-nested loops. Purpose Question 2-String variables/Selection & loops. (8.5 points) Write a complete Java program which prompts the user for a sentence on one line where each word is separated by one space, reads the line into one String variable using nextline), converts the string into Ubbi...
Write a structured (procedural) Python program that solves the following spec: Soundex System Coding: Soundex is a system that encodes a word into a letter followed by three numbers that roughly describe how the word sounds. Therefore, similar sounding words have the same four-character code. Use the following set of (slightly modified #4) rules to create a translator from English words to Soundex Code: Retain the first letter of the word. For letters 2 …n, delete any/all occurrences of the...
Write a Java Program that performs the following functionalities: and you can use if statements, cases, and string methods Enter a new main sentence Find a String Find all incidents of a String Find and Replace a String Replace all the incidents of a String Count the number of words Count a letter’s occurrences Count the total number of letters Delete all the occurrences of a word Exit The program will display a menu with each option above, and then...
All the white space among words in a text file was lost. Write a C++ program which using dynamic programming to get all of the possible original text files (i.e. with white spaces between words) and rank them in order of likelihood with the best possible runtime. You have a text file of dictionary words and the popularity class of the word (words are listed from popularity 1-100 (being most popular words), 101-200, etc) - Input is a text file...
I need help with my Java code. A user enters a sentence and the program will tell you what words were duplicated and how many times. If the same word is in the sentence twice, but one is capitalized, it will not count it as a duplicate. How can I make the program read the same word as the same word, even if one is capitalized and the other is not? For example, "the" and "The" should be counted as...