7 Replies - 385 Views - Last Post: 22 October 2013 - 08:32 PM Rate Topic: -----

#1 pbivens85  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 67
  • Joined: 22-October 13

inputting syllables

Posted 22 October 2013 - 04:38 PM

well I am trying to input a text file. I am able to count the number of words but I want to count the number of syllables and the number of sentences.
#include <iostream>
#include <string>
#include <math.h>
#include <fstream>

using namespace std;

int main()
{
	double index=0;

	int syllabus,words=0,sentences=0;
	string filename;

	cout << "Enter the data file name: ";
	cin >> filename;

	ifstream infile;
	infile.open(filename.c_str());

	if(infile.fail())
	{
		cout << "Error opening " << filename << endl;
		system("pause");
		return 1;
	}
	
	while(!infile.eof())
	{
	string word;
	
	infile >> word;

	cout << word << endl;
	
	if(word.size() > 0)
		words++;

	}

	cout << words << endl;

	infile.close();

	infile.open(filename.c_str());

	while(!infile.eof())
	{
	char sentence;
	
	infile >> sentence;

	cout << sentence << endl;
	
	if(sentence=='.'|| sentence=='?'||sentence=='!'||sentence==':'||sentence==';')
	{
		sentences++;
	}

	}

	cout << sentences << endl;

	infile.close();

	system("pause");
	return 0;
}



Is This A Good Question/Topic? 0
  • +

Replies To: inputting syllables

#2 mojo666  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 352
  • View blog
  • Posts: 771
  • Joined: 27-June 09

Re: inputting syllables

Posted 22 October 2013 - 07:30 PM

Syllables are going to be difficult because there isn't a set pattern. I would read character by character and increment the count when you read a vowel, but then don't increment until you read another non-vowel. For example, if the word is "about", you would increment on the 'a' and the 'o', but not the 'u'. This will fail miserably on silent vowels, but there really isn't a way to determine what is pronounced and what is not from the characters.
Was This Post Helpful? 0
  • +
  • -

#3 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3565
  • View blog
  • Posts: 11,074
  • Joined: 05-May 12

Re: inputting syllables

Posted 22 October 2013 - 07:36 PM

Counting syllables is relatively difficult if the language you are counting syllables for is English. You need to have a huge rule table to handle all the idiosyncrasies of the English language. You maybe able to get by with some heuristics like treating independent groups of vowels plus the letter 'y' as a the basis of a syllable, but you'll still need to determine if the last 'e' of a word is silent as in 'language', or pronounced as in 'syllable'. You would probably have more luck if you tackling a phonetic language like Filipino or Cherokee (Tsalagi).
Was This Post Helpful? 0
  • +
  • -

#4 pbivens85  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 67
  • Joined: 22-October 13

Re: inputting syllables

Posted 22 October 2013 - 07:44 PM

well I am trying to implement the flesch readability index, I found this exercise in the big c++ text which I am studying. this is not homework. I am not in class I am studying on my own.
Was This Post Helpful? 0
  • +
  • -

#5 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3565
  • View blog
  • Posts: 11,074
  • Joined: 05-May 12

Re: inputting syllables

Posted 22 October 2013 - 07:52 PM

You may consider using the CMU Pronouncing Dictionary to get the phonemes. By counting the phonemes that build up syllables, you may have a better chance at accuracy.
Was This Post Helpful? 0
  • +
  • -

#6 pbivens85  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 67
  • Joined: 22-October 13

Re: inputting syllables

Posted 22 October 2013 - 08:08 PM

well this might be too complex for me. but thanks for all the help.
Was This Post Helpful? 0
  • +
  • -

#7 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3565
  • View blog
  • Posts: 11,074
  • Joined: 05-May 12

Re: inputting syllables

Posted 22 October 2013 - 08:17 PM

Good luck! Specially when you stumble across the words 'crwth' and 'tsktsks'. :)

Alternately, you could pick up an good dictionary text file (there's several on the net) and spend the afternoon manually adding an extra column which has the number of syllables. After that, investment in time, your program can then load the dictionary into memory and you can do lookups against it to count the syllables.
Was This Post Helpful? 0
  • +
  • -

#8 pbivens85  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 67
  • Joined: 22-October 13

Re: inputting syllables

Posted 22 October 2013 - 08:32 PM

well I am going to move on to another exercise, but thanks for all the help skydiver
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1