Browse Source

cleanup: refactor checking FLAG_COMBINE into a function (#1454)

master
Juho Hiltunen 2 years ago
parent
commit
c92f7b7bfe
No account linked to committer's email address
2 changed files with 68 additions and 57 deletions
  1. 1
    1
      dictsource/da_rules
  2. 67
    56
      src/libespeak-ng/translate.c

+ 1
- 1
dictsource/da_rules View File



// one sylable plus "færdig" - stressed æ // one sylable plus "færdig" - stressed æ
@) færdig f'Erdi // bluf'ærdig @) færdig f'Erdi // bluf'ærdig
@@) færdig fErdi $1 // f'ingerfærdig
_) færdig fardi // f'ingerfærdig


// General rule, most words with af- plus consonant: f => w // General rule, most words with af- plus consonant: f => w
a) f (C w a) f (C w

+ 67
- 56
src/libespeak-ng/translate.c View File

#include "speech.h" // for MAKE_MEM_UNDEFINED #include "speech.h" // for MAKE_MEM_UNDEFINED
#include "translateword.h" #include "translateword.h"


static void CombineFlag(Translator *tr, WORD_TAB *wtab, char *word, int *flags, unsigned char *p, char *word_phonemes);

Translator *translator = NULL; // the main translator Translator *translator = NULL; // the main translator
Translator *translator2 = NULL; // secondary translator for certain words Translator *translator2 = NULL; // secondary translator for certain words
static char translator2_language[20] = { 0 }; static char translator2_language[20] = { 0 };
int source_ix; int source_ix;
int len; int len;
int ix; int ix;
int sylimit; // max. number of syllables in a word to be combined with a preceding preposition
const char *new_language; const char *new_language;
int bad_phoneme; int bad_phoneme;
int word_flags; int word_flags;
} }


if ((flags & FLAG_COMBINE) && !(wtab[1].flags & FLAG_PHONEMES)) { if ((flags & FLAG_COMBINE) && !(wtab[1].flags & FLAG_PHONEMES)) {
char *p2;
bool ok = true;
unsigned int flags2[2];
int c_word2;
char ph_buf[N_WORD_PHONEMES];

flags2[0] = 0;
sylimit = tr->langopts.param[LOPT_COMBINE_WORDS];

// LANG=cs,sk
// combine a preposition with the following word
p2 = word;
while (*p2 != ' ') p2++;

utf8_in(&c_word2, p2+1); // first character of the next word;
if (!iswalpha(c_word2))
ok = false;

if (ok == true) {
strcpy(ph_buf, word_phonemes);

flags2[0] = TranslateWord(translator, p2+1, wtab+1, NULL);
if ((flags2[0] & FLAG_WAS_UNPRONOUNCABLE) || (word_phonemes[0] == phonSWITCH))
ok = false;

if (sylimit & 0x100) {
// only if the second word has $alt attribute
if ((flags2[0] & FLAG_ALT_TRANS) == 0)
ok = false;
}

if ((sylimit & 0x200) && ((wtab+1)->flags & FLAG_LAST_WORD)) {
// not if the next word is end-of-sentence
ok = false;
}

if (ok == false)
strcpy(word_phonemes, ph_buf);
}

if (ok) {
*p2 = '-'; // replace next space by hyphen
wtab[0].flags &= ~FLAG_ALL_UPPER; // prevent it being considered an abbreviation
flags = TranslateWord(translator, word, wtab, NULL); // translate the combined word
if ((sylimit > 0) && (CountSyllables(p) > (sylimit & 0x1f))) {
// revert to separate words
*p2 = ' ';
flags = TranslateWord(translator, word, wtab, NULL);
} else {
if (flags == 0)
flags = flags2[0]; // no flags for the combined word, so use flags from the second word eg. lang-hu "nem december 7-e"
flags |= FLAG_SKIPWORDS;
dictionary_skipwords = 1;
}
}
CombineFlag(tr, wtab, word, &flags, p, word_phonemes);
} }


if (p[0] == phonSWITCH) { if (p[0] == phonSWITCH) {
} }
} }



static void CombineFlag(Translator *tr, WORD_TAB *wtab, char *word, int *flags, unsigned char *p, char *word_phonemes) {
// combine a preposition with the following word


int sylimit; // max. number of syllables in a word to be combined with a preceding preposition
sylimit = tr->langopts.param[LOPT_COMBINE_WORDS];


char *p2;
p2 = word;
while (*p2 != ' ') p2++;

bool ok = true;
int c_word2;

utf8_in(&c_word2, p2+1); // first character of the next word;

if (!iswalpha(c_word2))
ok = false;

int flags2[2];
flags2[0] = 0;


if (ok) {
char ph_buf[N_WORD_PHONEMES];
strcpy(ph_buf, word_phonemes);

flags2[0] = TranslateWord(tr, p2+1, wtab+1, NULL);
if ((flags2[0] & FLAG_WAS_UNPRONOUNCABLE) || (word_phonemes[0] == phonSWITCH))
ok = false;

if ((sylimit & 0x100) && ((flags2[0] & FLAG_ALT_TRANS) == 0)) {
// only if the second word has $alt attribute
ok = false;
}

if ((sylimit & 0x200) && ((wtab+1)->flags & FLAG_LAST_WORD)) {
// not if the next word is end-of-sentence
ok = false;
}

if (ok == false)
strcpy(word_phonemes, ph_buf);
}

if (ok) {
*p2 = '-'; // replace next space by hyphen
wtab[0].flags &= ~FLAG_ALL_UPPER; // prevent it being considered an abbreviation
*flags = TranslateWord(translator, word, wtab, NULL); // translate the combined word
if ((sylimit > 0) && (CountSyllables(p) > (sylimit & 0x1f))) {
// revert to separate words
*p2 = ' ';
*flags = TranslateWord(translator, word, wtab, NULL);
} else {
if (*flags == 0)
*flags = flags2[0]; // no flags for the combined word, so use flags from the second word eg. lang-hu "nem december 7-e"
*flags |= FLAG_SKIPWORDS;
dictionary_skipwords = 1;
}
}
}

void InitText(int control) void InitText(int control)
{ {
count_sentences = 0; count_sentences = 0;

Loading…
Cancel
Save