Here is my project:
ntroduction
In this project you are going to implement a linguistic application that uses a pronunciation dictionary for finding words with similar pronunciation.
Example. You enter a word, and it reports similar-sounding words:
> donut
Pronunciation : D OW1 N AH2 T
Identical : DOUGHNUT
We are going to use The CMU Pronouncing Dictionary as our reference. It is available as a simply formatted plain text file, a direct link to it is: cmudict.0.7a
An excerpt from it is shown below:
PROGRAM P R OW1 G R AE2 M
PROGRAM'S P R OW1 G R AE2 M Z
PROGRAMME P R OW1 G R AE2 M
PROGRAMMER P R OW1 G R AE2 M ER0
PROGRAMMERS P R OW1 G R AE2 M ER0 Z
PROGRAMS P R OW1 G R AE2 M Z
PROGRAMS' P R OW1 G R AE2 M Z
PROGRESS P R AA1 G R EH2 S
PROGRESS(1) P R AH0 G R EH1 S
PROGRESS(2) P R OW0 G R EH1 S
PROGRESSED P R AH0 G R EH1 S T
PROGRESSES P R AA1 G R EH2 S AH0 Z
PUSH-UP P UH1 SH AH2 P
PUSH-UPS P UH1 SH AH2 P S
So, your program should ignore entries like:
PROGRESS(1) P R AH0 G R EH1 S < ignore
PROGRESS(2) P R OW0 G R EH1 S < ignore
PUSH-UP P UH1 SH AH2 P < ignore
PUSH-UPS P UH1 SH AH2 P S < ignore
%PERCENT P ER0 S EH1 N T < ignore
&ERSAND AE1 M P ER0 S AE2 N D < ignore
However, the following entries are considered good:
PROGRAM P R OW1 G R AE2 M < good
PROGRAM'S P R OW1 G R AE2 M Z < good
PROGRAMS' P R OW1 G R AE2 M Z < good
'BOUT B AW1 T < good
Programming Task
Write a program pronounce.cpp that
Lets the user input a word (let’s call the input word W).
If the word is not found in the dictionary, print “Not found”. Otherwise, report:
Pronunciation : the pronunciation of the word W (as given in the dictionary),
Identical : other words from the dictionary with the same pronunciation as W,
Add phoneme : words that can be obtained from W by adding one phoneme,
Remove phoneme : words that can be obtained from W by removing one phoneme,
Replace phoneme : words that can be obtained from W by replacing one phoneme.
When listing words, include all words from the dictionary that meet the criteria, the order of listed words should be the same as they appear in the dictionary.
Your program should expect that the dictionary file cmudict.0.7a is located in the current working directory.
User input should be case-insensitive (accepting donut, DONUT, DOnUt, etc.)
Please, don’t make complex user interface that allows multiple queries. The program should just ask for one word, report the answer, and exit. See examples below.
You are allowed to use only the constructs of the language that were mentioned in lecture slides and covered in class. For strings, you can use only the operations mentioned in class.
Examples:
> accord
Pronunciation : AH0 K AO1 R D
Identical : ACORD
I JUST NEED HELP WITH IDENTICAL PART I AM STUCK.
What I have tried:
#include <iostream>
#include <string>
#include <fstream>
#include <cctype>
using namespace std;
void splitOnSpace(string s, string & before, string & after) {
before = "";
after = "";
int i = 0;
while (i < s.size() && not isspace(s[i])) { before += s[i]; i++; }
i++;
while (i < s.size()) { after += s[i]; i++; }
}
int main()
{
ifstream input;
input.open("cmudict.0.7a.txt");
if(input.fail()){
cout << "File did not open";
}
string word;
string str;
string w;
cout << "What is the word you want to look up?" << endl;
cin>>word;
while(input >> str)
{
if(str == word){
getline(input, word);
break;
}
}
string afterSpace;
string beforeSpace;
splitOnSpace(str + word, beforeSpace, afterSpace);
splitOnSpace(str + word, beforeSpace, afterSpace);
cout << "Pronounciation: " << afterSpace << endl;
do{
getline(input, str);
splitOnSpace(str, beforeSpace, afterSpace);
if(str == afterSpace)
{
getline(input, str);
}
}while(!input.eof());
splitOnSpace(str, beforeSpace, afterSpace);
cout << "Identical: " << beforeSpace << afterSpace << endl;
}