コード例 #1
0
ファイル: FleschKincaid.cpp プロジェクト: vlad-alekseev/other
/**
 * Receive information from file, processes and displays the result on the screen.
 */
void processText(TokenScanner & scanner){
    int counterSentences = 0;
    int counterWords = 0;
    int counterSyllable = 0;
    double grade = 0.0;

    scanner.ignoreWhitespace(); // ignores spaces
    scanner.addWordCharacters("'"); // does part of the token is the character "'"

    // processes each token
    while (scanner.hasMoreTokens()){
        string token = scanner.nextToken();
        counterSentences += checkSentences(token);
        if(checkWords(token)){
            counterWords ++;
            counterSyllable += colSyllable(token);
        }
    }
    // If the file does not contain any words or sentences, assume that their one
    if(counterWords == 0 || counterSentences == 0) counterSentences = counterWords = 1;

    grade = getGrade(counterSentences, counterWords, counterSyllable);

    cout << "Words : " << counterWords << endl;
    cout << "Syllable : " << counterSyllable << endl;
    cout << "Sentences : " << counterSentences << endl;
    cout << "Grade : " << grade << endl;
}
コード例 #2
0
void toAlpha(std::string word, Map<std::string, std::string>& symbolTable) {
	TokenScanner scanner;
	scanner.ignoreWhitespace();

	for(char i = 'A'; i < 'Z'; i++)
		scanner.addWordCharacters(symbolTable.get(charToString(i)));

	scanner.setInput(word);

	while(scanner.hasMoreTokens()) {
		std::string symbol = scanner.nextToken();
		cout << symbolTable.get(symbol);
	}
	cout << endl;
}