PageRenderTime 26ms CodeModel.GetById 11ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 0ms

/native/external/espeak/src/tr_english.cpp

http://eyes-free.googlecode.com/
C++ | 138 lines | 81 code | 30 blank | 27 comment | 22 complexity | 43eaedc04ad377afef903ac5ca31aa87 MD5 | raw file
  1/***************************************************************************
  2 *   Copyright (C) 2005 to 2007 by Jonathan Duddington                     *
  3 *   email: jonsd@users.sourceforge.net                                    *
  4 *                                                                         *
  5 *   This program is free software; you can redistribute it and/or modify  *
  6 *   it under the terms of the GNU General Public License as published by  *
  7 *   the Free Software Foundation; either version 3 of the License, or     *
  8 *   (at your option) any later version.                                   *
  9 *                                                                         *
 10 *   This program is distributed in the hope that it will be useful,       *
 11 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 12 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 13 *   GNU General Public License for more details.                          *
 14 *                                                                         *
 15 *   You should have received a copy of the GNU General Public License     *
 16 *   along with this program; if not, write see:                           *
 17 *               <http://www.gnu.org/licenses/>.                           *
 18 ***************************************************************************/
 19
 20#include "StdAfx.h"
 21
 22#include <stdio.h>
 23#include <ctype.h>
 24#include <wctype.h>
 25#include <stdlib.h>
 26#include <string.h>
 27#include <locale.h>
 28
 29#include "speak_lib.h"
 30#include "speech.h"
 31#include "phoneme.h"
 32#include "synthesize.h"
 33#include "translate.h"
 34#include "tr_languages.h"
 35
 36
 37Translator_English::Translator_English() : Translator()
 38{//===================================
 39//	static int stress_lengths2[8] = {182,140, 220,220, 220,240, 248,270};
 40	static const short stress_lengths2[8] = {182,140, 220,220, 0,0, 248,275};
 41
 42	memcpy(stress_lengths,stress_lengths2,sizeof(stress_lengths));
 43	langopts.stress_rule = 0;
 44
 45	langopts.numbers = 0x841 + NUM_ROMAN;
 46	langopts.param[LOPT_COMBINE_WORDS] = 2;       // allow "mc" to cmbine with the following word
 47}
 48
 49
 50
 51static unsigned char initials_bitmap[86] = {
 52 0x00, 0x00, 0x00, 0x00, 0x22, 0x08, 0x00, 0x88,  //  0
 53 0x20, 0x24, 0x20, 0x80, 0x10, 0x00, 0x00, 0x00,
 54 0x00, 0x28, 0x08, 0x00, 0x88, 0x22, 0x04, 0x00,  // 16
 55 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 56 0x00, 0x88, 0x22, 0x04, 0x00, 0x02, 0x00, 0x04,  // 32
 57 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 58 0x00, 0x28, 0x8a, 0x03, 0x00, 0x00, 0x40, 0x00,  // 48
 59 0x02, 0x00, 0x41, 0xca, 0x9b, 0x06, 0x20, 0x80,
 60 0x91, 0x00, 0x00, 0x00, 0x00, 0x20, 0x08, 0x00,  // 64
 61 0x08, 0x20, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
 62 0x00, 0x00, 0x22, 0x00, 0x01, 0x00, };
 63
 64
 65
 66int Translator_English::Unpronouncable(char *word)
 67{//===============================================
 68/* Determines whether a word in 'unpronouncable', i.e. whether it should
 69	be spoken as individual letters.
 70
 71	This function is language specific.
 72*/
 73
 74	int  c;
 75	int  vowel_posn=9;
 76	int  index;
 77	int  count;
 78	int  ix;
 79	int  apostrophe=0;
 80
 81	// words which we pass through to the dictionary, even though they look unpronouncable
 82	static const char *exceptions[] = {
 83		"'s ", "st ","nd ","rd ","th ",NULL };
 84
 85	if((*word == ' ') || (*word == 0))
 86		return(0);
 87
 88	for(ix=0; exceptions[ix] != NULL; ix++)
 89	{
 90		// Seemingly uncpronouncable words, but to be looked in the dictionary rules instead
 91		if(memcmp(word,exceptions[ix],3)==0)
 92			return(0);
 93	}
 94
 95	index=0;
 96	count=0;
 97	for(;;)
 98	{
 99		index += utf8_in(&c,&word[index],0);
100		count++;
101
102		if((c==0) || (c==' '))
103			break;
104
105		if(IsVowel(c) || (c == 'y'))
106		{
107			vowel_posn = count;
108			break;
109		}
110
111		if(c == '\'')
112			apostrophe = 1;
113		else
114		if(!IsAlpha(c))
115			return(0);        // letter (not vowel) outside Latin character range or apostrophe, abort test
116	}
117	if((vowel_posn > 5) || ((word[0]!='s') && (vowel_posn > 4)))
118		return(1);  // no vowel, or no vowel in first four letters
119
120	/* there is at least one vowel, is the initial letter combination valid ? */
121
122	if(vowel_posn < 3)
123		return(0);   /* vowel in first two letters, OK */
124
125	if(apostrophe)
126		return(0);   // first two letters not a-z, abort test
127
128	index = (word[0]-'a') * 26 + (word[1]-'a');
129	if(initials_bitmap[index >> 3] & (1L << (index & 7)))
130		return(0);
131	else
132		return(1);   /****/
133}   /* end of Unpronounceable */
134
135
136
137
138