Click here to Skip to main content
15,904,494 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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:

C++
#include <iostream>
#include <string>
#include <fstream>
#include <cctype>
using namespace std; 


void splitOnSpace(string s, string & before, string & after) {
    // reset strings
    before = ""; 
    after = "";
    // accumulate before space
    int i = 0;
    while (i < s.size() && not isspace(s[i])) { before += s[i]; i++; }
      // skip the space
    i++;
    // accumulate after space
    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;
    
  
  
 
 }
Posted
Updated 30-Mar-18 11:50am
v4

This is your homework, and getting it working is part of the task - and to be honest, it's a big, important part of the task!

So, it's going to be up to you.
Fortunately, you have a tool available to you which will help you find out what is going on: the debugger. How you use it depends on your compiler system, but a quick Google for the name of your IDE and "debugger" should give you the info you need.

Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.

Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!
 
Share this answer
 
Comments
Member 13754626 30-Mar-18 6:48am    
I have tried that and I have been working all night its 7am and im desperate for any help. I would really appreciate it. I just do not know what to do...HAVE MERCY. Not to mention its due very soon and im crammed with a lot of other work. I wouldnt ask a question without spending a least a good couple of hours debugging it(or trying).
OriginalGriff 30-Mar-18 7:17am    
And what has the debugger shown you?
Member 13754626 30-Mar-18 7:43am    
I orginally used cout statments and i noticed that at getline(input, str) is the only thing that is not working. To be honest at this point im just desperate for even a hint because i niether have time or the knowledge to install the debugger. If my college campus wasnt closed i would have gone there to do it. Please Give me just one hint of why it wont print out identical i need my sleep. i am only a begginer and i have a deadline coming up. I promise you I am not like the others i actually try for several hours before coming for help. I debug with cout statments unless im in my college campus
Member 13754626 30-Mar-18 7:45am    
I really am terribly sorry to bother you and I appreciate your time and effort. I promise it wont be invain.
Looking at the preceding comments, I feel I need to point something out to you.

Being "Up All Night" programming is not very unusual. If you're desperate because you waited until the last minute to solve the problem then consider that a lesson you should learn - don't wait until the last minute! Something you may have already known and just need to actually think about.

On the other hand, if it's not the last minute, spend some time breaking the problem down into all of its individual task. Not the tasks from the instructor, but those that make up the steps in each of the tasks.

  1. What do you need to do to find a word in your dictionary?
  2. What do you do to get the phonetic form of that word?
  3. How do you search the dictionary for other words with the proper parts of that phonetic form matching?
  4. How do you convert that back to a "real word" and report it back to the user.


 
Share this answer
 
Comments
Member 13754626 30-Mar-18 13:58pm    
I am not looking for the soultuion to all of it. I am just stuck on the identical part please help

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900