Example #1
0
/*
 * 将一个拼音(包括仅为声母或韵母)转换为拼音映射
 * 返回True为转换成功,否则为False(一般是因为strPY不是一个标准的拼音)
 */
Bool MapPY (char *strPY, char strMap[3], PYPARSEINPUTMODE mode)
{
    char            str[5];
    int             iIndex;

    //特殊处理eng
    if (!strcmp (strPY, "eng") && MHPY_C[1].bMode) {
	strcpy (strMap, "X0");
	return True;
    }

    strMap[2] = '\0';
    iIndex = IsSyllabary (strPY, 0);
    if (-1 != iIndex) {
	strMap[0] = syllabaryMapTable[iIndex].cMap;
	strMap[1] = mode;
	return True;
    }
    iIndex = IsConsonant (strPY, 0);

    if (-1 != iIndex) {
	strMap[0] = mode;
	strMap[1] = consonantMapTable[iIndex].cMap;
	return True;
    }

    str[0] = strPY[0];
    str[1] = '\0';

    if (strPY[1] == 'h' || strPY[1] == 'g') {
	str[0] = strPY[0];
	str[1] = strPY[1];
	str[2] = '\0';
	iIndex = IsSyllabary (str, 0);
	strMap[0] = consonantMapTable[iIndex].cMap;
	iIndex = IsConsonant (strPY + 2, 0);
	strMap[1] = consonantMapTable[iIndex].cMap;
    }
    else {
	str[0] = strPY[0];
	str[1] = '\0';
	iIndex = IsSyllabary (str, 0);
	if (iIndex == -1)
	    return False;
	strMap[0] = consonantMapTable[iIndex].cMap;
	iIndex = IsConsonant (strPY + 1, 0);
	if (iIndex == -1)
	    return False;
	strMap[1] = consonantMapTable[iIndex].cMap;
    }

    return True;
}
Example #2
0
bool InflectRule::IsApplicable(const char *string) const {
  for (int i=0; i<nEndings; i++) {
    const int n = strlen(Ending(i));
    const char *ending, *stringEnd;
    if (Ending(i)[0] == '^') {
      ending = Ending(i) + 1;
      stringEnd = string;
    }
    else
    {
	ending = Ending(i);
#if 0   /* jbfix: len - n may be < 0! */
	stringEnd = string + strlen(string) - n;
#else
	int index = strlen(string) - n;
	if(index < 0)
	    index = 0;
	stringEnd = string + index;
#endif
    }
    if (!strncmp(stringEnd, ending, n) || 
	(ending[0] == 'V' &&
	 IsVowel(stringEnd[0]) &&
	 !strncmp(stringEnd+1, ending+1, n-1)) ||
	(ending[0] == 'C' &&
	 IsConsonant(stringEnd[0]) &&
	 !strncmp(stringEnd+1, ending+1, n-1)))
      return true;
  }
  return false;
}
int CStringCruncher::GetCharPriority(char c, char prev, char next)
{
	if (::isdigit(c))
		return 4;

	if (('-' == c || '.' == c) && ::isdigit(next))
		return 4;

	// Is it the first character of a word?
	if (::isalpha(c) && !::isalnum(prev))
		return 3;

	if (IsConsonant(c))
		return 2;

	if (IsVowel(c))
		return 1;

	return 0;
}
int CStringCruncherU::GetCharPriority(TCHAR c, TCHAR prev, TCHAR next)
{
	if (::isdigit(c))
		return 4;

	if ((_T('-') == c || _T('.') == c) && ::isdigit(next))
		return 4;

	// Is it the first character of a word?
	if (::isalpha(c) && !::isalnum(prev))
		return 3;

	if (IsConsonant(c))
		return 2;

	if (IsVowel(c))
		return 1;

	return 0;
}
Example #5
0
/*
 * 将一个拼音(包括仅为声母或韵母)转换为拼音映射
 * 返回true为转换成功,否则为false(一般是因为strPY不是一个标准的拼音)
 */
boolean MapPY(FcitxPinyinConfig* pyconfig, const char* strPYorigin, char strMap[3], PYPARSEINPUTMODE mode)
{
    char            str[5];
    char            strPY[7];
    int             iIndex;

    strcpy(strPY, strPYorigin);

    size_t          len = strlen(strPY);

    if (pyconfig->bMisstype && strPY[len - 1] == 'n' && strPY[len - 2] == 'g') {
        strPY[len - 2] = 'n';
        strPY[len - 1] = 'g';
    }

    //特殊处理eng
    if (!strcmp(strPY, "eng") && pyconfig->MHPY_C[1].bMode) {
        strcpy(strMap, "X0");
        return true;
    }

    strMap[2] = '\0';

    iIndex = IsSyllabary(strPY, 0);

    if (-1 != iIndex) {
        strMap[0] = syllabaryMapTable[iIndex].cMap;
        strMap[1] = mode;
        return true;
    }

    iIndex = IsConsonant(strPY, 0);

    if (-1 != iIndex) {
        strMap[0] = mode;
        strMap[1] = consonantMapTable[iIndex].cMap;
        return true;
    }

    str[0] = strPY[0];

    str[1] = '\0';

    if (strPY[1] == 'h' || strPY[1] == 'g') {
        str[0] = strPY[0];
        str[1] = strPY[1];
        str[2] = '\0';
        iIndex = IsSyllabary(str, 0);
        strMap[0] = consonantMapTable[iIndex].cMap;
        iIndex = IsConsonant(strPY + 2, 0);
        strMap[1] = consonantMapTable[iIndex].cMap;
    } else {
        str[0] = strPY[0];
        str[1] = '\0';
        iIndex = IsSyllabary(str, 0);

        if (iIndex == -1)
            return false;

        strMap[0] = consonantMapTable[iIndex].cMap;

        iIndex = IsConsonant(strPY + 1, 0);

        if (iIndex == -1)
            return false;

        strMap[1] = consonantMapTable[iIndex].cMap;
    }

    return true;
}
Example #6
0
void ParsePY(FcitxPinyinConfig *pyconfig, const char *strPY, ParsePYStruct * parsePY, PYPARSEINPUTMODE mode, boolean bSP)
{
    const char           *strP;
    int             iIndex;
    int             iTemp;
    char            str_Map[3];
    char            strTemp[7];

    parsePY->iMode = PARSE_SINGLEHZ;
    strP = strPY;
    parsePY->iHZCount = 0;

    if (bSP) {
        char            strQP[7];
        char            strJP[3];

        strJP[2] = '\0';

        while (*strP) {
            strJP[0] = *strP++;
            strJP[1] = *strP;
            SP2QP(pyconfig, strJP, strQP);
            MapPY(pyconfig, strQP, str_Map, mode);

            if (!*strP) {
                strcpy(parsePY->strMap[parsePY->iHZCount], str_Map);
                strcpy(parsePY->strPYParsed[parsePY->iHZCount++], strJP);
                break;
            }

            iIndex = FindPYFAIndex(pyconfig, strQP, 0);

            if (iIndex != -1) {
                strcpy(parsePY->strMap[parsePY->iHZCount], str_Map);
                strcpy(parsePY->strPYParsed[parsePY->iHZCount++], strJP);
                strP++;
            } else {
                strJP[1] = '\0';
                SP2QP(pyconfig, strJP, strQP);

                if (!MapPY(pyconfig, strQP, str_Map, mode))
                    strcpy(parsePY->strMap[parsePY->iHZCount], strJP);
                else
                    strcpy(parsePY->strMap[parsePY->iHZCount], str_Map);

                strcpy(parsePY->strPYParsed[parsePY->iHZCount++], strJP);
            }

            if (*strP == PY_SEPARATOR) {
                strcat(parsePY->strPYParsed[parsePY->iHZCount - 1], PY_SEPARATOR_S);

                while (*strP == PY_SEPARATOR)
                    strP++;
            }
        }
    } else {
        boolean            bSeperator = false;

        do {
            iIndex = FindPYFAIndex(pyconfig, strP, 1);

            if (iIndex != -1) {
                size_t lIndex = strlen(pyconfig->PYTable[iIndex].strPY);
                strTemp[0] = pyconfig->PYTable[iIndex].strPY[lIndex - 1];
                iTemp = -1;

                /*
                 * if the end of pinyin is 'g', 'n', 'e'
                 * there might be another possbility, for example "wanan" can be "wa nan" and "wan an"
                 * try resolve these problem here
                 */
                if (strTemp[0] == 'g' || strTemp[0] == 'n' || strTemp[0] == 'e' || strTemp[0] == 'a') {
                    strncpy(strTemp, strP, lIndex - 1);
                    strTemp[lIndex - 1] = '\0';

                    /* for example we have "wan", so we try to check "wa" is valid or not, with exact match */
                    iTemp = FindPYFAIndex(pyconfig, strTemp, 0);

                    /* if "wa" is valid */
                    if (iTemp != -1) {
                        /* also check "nan" is valid or not */
                        int firstIndex;
                        firstIndex = iTemp;
                        iTemp = FindPYFAIndex(pyconfig, strP + strlen(pyconfig->PYTable[iTemp].strPY), 1);

                        /* if still is valid */
                        if (iTemp != -1) {
                            /*
                             * length 1 split is what we must avoid,
                             * for example, "nin" can be "ni n", but no separator can for "nin" if we split here
                             *
                             * and "ying" can be also "yi ng", for just the same case"
                             */
                            if (strlen(pyconfig->PYTable[iTemp].strPY) == 1 || !strcmp("ng", pyconfig->PYTable[iTemp].strPY))
                                iTemp = -1;
                        }

                        if (iTemp != -1) {
                            /* check the general frequency that this shoud split or not */
                            int index2 = FindPYFAIndex(pyconfig, strP + strlen(pyconfig->PYTable[iIndex].strPY), 1);

                            boolean resplit = false;
                            do {
                                /* prefer longer */
                                if (index2 == -1) {
                                    resplit = true;
                                    break;
                                }

                                size_t length1 = strlen(pyconfig->PYTable[iIndex].strPY) + strlen(pyconfig->PYTable[index2].strPY);
                                size_t length2 = strlen(pyconfig->PYTable[firstIndex].strPY) + strlen(pyconfig->PYTable[iTemp].strPY);
                                if (length1 != length2) {
                                    resplit = (length1 < length2);
                                    break;
                                }

                                double freq1 = LookupPYFreq(pyconfig, iIndex, index2);
                                double freq2 = LookupPYFreq(pyconfig, firstIndex, iTemp);

                                resplit = (freq1 <= freq2);
                            } while(0);

                            if (resplit) {
                                strncpy(strTemp, strP, lIndex - 1);
                                strTemp[lIndex - 1] = '\0';
                            }
                            else
                                iTemp = -1;
                        }
                    }
                }

                if (iTemp == -1)
                    strcpy(strTemp, pyconfig->PYTable[iIndex].strPY);

                MapPY(pyconfig, strTemp, str_Map, mode);

                strcpy(parsePY->strMap[parsePY->iHZCount], str_Map);

                strP += strlen(strTemp);

                if (bSeperator) {
                    bSeperator = false;
                    parsePY->strPYParsed[parsePY->iHZCount][0] = PY_SEPARATOR;
                    parsePY->strPYParsed[parsePY->iHZCount][1] = '\0';
                } else
                    parsePY->strPYParsed[parsePY->iHZCount][0] = '\0';

                strcat(parsePY->strPYParsed[parsePY->iHZCount++], strTemp);
            } else {
                if (pyconfig->bFullPY && *strP != PY_SEPARATOR)
                    parsePY->iMode = PARSE_ERROR;

                iIndex = IsConsonant(strP, 1);

                if (-1 != iIndex) {
                    parsePY->iMode = PARSE_ERROR;

                    if (bSeperator) {
                        bSeperator = false;
                        parsePY->strPYParsed[parsePY->iHZCount][0] = PY_SEPARATOR;
                        parsePY->strPYParsed[parsePY->iHZCount][1] = '\0';
                    } else
                        parsePY->strPYParsed[parsePY->iHZCount][0] = '\0';

                    strcat(parsePY->strPYParsed[parsePY->iHZCount], consonantMapTable[iIndex].strPY);

                    MapPY(pyconfig, consonantMapTable[iIndex].strPY, str_Map, mode);

                    strcpy(parsePY->strMap[parsePY->iHZCount++], str_Map);

                    strP += strlen(consonantMapTable[iIndex].strPY);
                } else {
                    iIndex = IsSyllabary(strP, 1);

                    if (-1 != iIndex) {
                        if (bSeperator) {
                            bSeperator = false;
                            parsePY->strPYParsed[parsePY->iHZCount][0] = PY_SEPARATOR;
                            parsePY->strPYParsed[parsePY->iHZCount][1] = '\0';
                        } else
                            parsePY->strPYParsed[parsePY->iHZCount][0] = '\0';

                        strcat(parsePY->strPYParsed[parsePY->iHZCount], syllabaryMapTable[iIndex].strPY);

                        MapPY(pyconfig, syllabaryMapTable[iIndex].strPY, str_Map, mode);

                        strcpy(parsePY->strMap[parsePY->iHZCount++], str_Map);

                        strP += strlen(syllabaryMapTable[iIndex].strPY);

                        if (parsePY->iMode != PARSE_ERROR)
                            parsePY->iMode = PARSE_ABBR;
                    } else {
                        //必定是分隔符
                        strP++;
                        bSeperator = true;
                        parsePY->strPYParsed[parsePY->iHZCount][0] = PY_SEPARATOR;
                        parsePY->strPYParsed[parsePY->iHZCount][1] = '\0';
                        parsePY->strMap[parsePY->iHZCount][0] = '0';
                        parsePY->strMap[parsePY->iHZCount][1] = '0';
                        parsePY->strMap[parsePY->iHZCount][2] = '\0';
                    }
                }
            }
        } while (*strP);
    }

    if (strPY[strlen(strPY) - 1] == PY_SEPARATOR && !bSP)
        parsePY->iHZCount++;

    if (parsePY->iMode != PARSE_ERROR) {
        parsePY->iMode = parsePY->iMode & PARSE_ABBR;

        if (parsePY->iHZCount > 1)
            parsePY->iMode = parsePY->iMode | PARSE_PHRASE;
        else
            parsePY->iMode = parsePY->iMode | PARSE_SINGLEHZ;
    }
}
Example #7
0
void ParsePY (char *strPY, ParsePYStruct * parsePY, PYPARSEINPUTMODE mode)
{
    char           *strP;
    int             iIndex;
    int             iTemp;
    char            str_Map[3];
    char            strTemp[7];

    parsePY->iMode = PARSE_SINGLEHZ;
    strP = strPY;
    parsePY->iHZCount = 0;

    if (bSP) {
	char            strQP[7];
	char            strJP[3];

	strJP[2] = '\0';

	while (*strP) {
	    strJP[0] = *strP++;
	    strJP[1] = *strP;
	    SP2QP (strJP, strQP);
	    MapPY (strQP, str_Map, mode);

	    if (!*strP) {
		strcpy (parsePY->strMap[parsePY->iHZCount], str_Map);
		strcpy (parsePY->strPYParsed[parsePY->iHZCount++], strJP);
		break;
	    }

	    iIndex = FindPYFAIndex (strQP, 0);
	    if (iIndex != -1) {
		strcpy (parsePY->strMap[parsePY->iHZCount], str_Map);
		strcpy (parsePY->strPYParsed[parsePY->iHZCount++], strJP);
		strP++;
	    }
	    else {
		strJP[1] = '\0';
		SP2QP (strJP, strQP);
		if (!MapPY (strQP, str_Map, mode))
		    strcpy (parsePY->strMap[parsePY->iHZCount], strJP);
		else
		    strcpy (parsePY->strMap[parsePY->iHZCount], str_Map);
		strcpy (parsePY->strPYParsed[parsePY->iHZCount++], strJP);
	    }

	    if (*strP == PY_SEPARATOR) {
		strcat (parsePY->strPYParsed[parsePY->iHZCount - 1], PY_SEPARATOR_S);
		while (*strP == PY_SEPARATOR )
		    strP++;
	    }
	}
    }
    else {
	Bool            bSeperator = False;

	do {
	    iIndex = FindPYFAIndex (strP, 1);

	    if (iIndex != -1) {
		strTemp[0] = PYTable[iIndex].strPY[strlen (PYTable[iIndex].strPY) - 1];
		iTemp = -1;
		if (strTemp[0] == 'g' || strTemp[0] == 'n') {
		    strncpy (strTemp, strP, strlen (PYTable[iIndex].strPY) - 1);
		    strTemp[strlen (PYTable[iIndex].strPY) - 1] = '\0';

		    iTemp = FindPYFAIndex (strTemp, 0);
		    if (iTemp != -1) {
			iTemp = FindPYFAIndex (strP + strlen (PYTable[iTemp].strPY), 1);
			if (iTemp != -1) {
			    if (strlen (PYTable[iTemp].strPY) == 1 || !strcmp ("ng", PYTable[iTemp].strPY))
				iTemp = -1;
			}
			if (iTemp != -1) {
			    strncpy (strTemp, strP, strlen (PYTable[iIndex].strPY) - 1);
			    strTemp[strlen (PYTable[iIndex].strPY) - 1] = '\0';
			}
		    }
		}
		if (iTemp == -1)
		    strcpy (strTemp, PYTable[iIndex].strPY);
		MapPY (strTemp, str_Map, mode);
		strcpy (parsePY->strMap[parsePY->iHZCount], str_Map);
		strP += strlen (strTemp);

		if (bSeperator) {
		    bSeperator = False;
		    parsePY->strPYParsed[parsePY->iHZCount][0] = PY_SEPARATOR;
		    parsePY->strPYParsed[parsePY->iHZCount][1] = '\0';
		}
		else
		    parsePY->strPYParsed[parsePY->iHZCount][0] = '\0';
		strcat (parsePY->strPYParsed[parsePY->iHZCount++], strTemp);
	    }
	    else {
		if (bFullPY && *strP != PY_SEPARATOR)
		    parsePY->iMode = PARSE_ERROR;

		iIndex = IsConsonant (strP, 1);
		if (-1 != iIndex) {
		    parsePY->iMode = PARSE_ERROR;

		    if (bSeperator) {
			bSeperator = False;
			parsePY->strPYParsed[parsePY->iHZCount][0] = PY_SEPARATOR;
			parsePY->strPYParsed[parsePY->iHZCount][1] = '\0';
		    }
		    else
			parsePY->strPYParsed[parsePY->iHZCount][0] = '\0';
		    strcat (parsePY->strPYParsed[parsePY->iHZCount], consonantMapTable[iIndex].strPY);
		    MapPY (consonantMapTable[iIndex].strPY, str_Map, mode);
		    strcpy (parsePY->strMap[parsePY->iHZCount++], str_Map);
		    strP += strlen (consonantMapTable[iIndex].strPY);
		}
		else {
		    iIndex = IsSyllabary (strP, 1);
		    if (-1 != iIndex) {
			if (bSeperator) {
			    bSeperator = False;
			    parsePY->strPYParsed[parsePY->iHZCount][0] = PY_SEPARATOR;
			    parsePY->strPYParsed[parsePY->iHZCount][1] = '\0';
			}
			else
			    parsePY->strPYParsed[parsePY->iHZCount][0] = '\0';
			strcat (parsePY->strPYParsed[parsePY->iHZCount], syllabaryMapTable[iIndex].strPY);
			MapPY (syllabaryMapTable[iIndex].strPY, str_Map, mode);
			strcpy (parsePY->strMap[parsePY->iHZCount++], str_Map);

			strP += strlen (syllabaryMapTable[iIndex].strPY);
			if (parsePY->iMode != PARSE_ERROR)
			    parsePY->iMode = PARSE_ABBR;
		    }
		    else {	//必定是分隔符
			strP++;
			bSeperator = True;
			parsePY->strPYParsed[parsePY->iHZCount][0] = PY_SEPARATOR;
			parsePY->strPYParsed[parsePY->iHZCount][1] = '\0';
			parsePY->strMap[parsePY->iHZCount][0] = '0';
			parsePY->strMap[parsePY->iHZCount][1] = '0';
			parsePY->strMap[parsePY->iHZCount][2] = '\0';
		    }
		}
	    }
	} while (*strP);
    }

    if (strPY[strlen (strPY) - 1] == PY_SEPARATOR && !bSP)
	parsePY->iHZCount++;

    if (parsePY->iMode != PARSE_ERROR) {
	parsePY->iMode = parsePY->iMode & PARSE_ABBR;
	if (parsePY->iHZCount > 1)
	    parsePY->iMode = parsePY->iMode | PARSE_PHRASE;
	else
	    parsePY->iMode = parsePY->iMode | PARSE_SINGLEHZ;
    }
}
int main (int argc, char *argv[])
{
time_t t0;
struct tm *t;

F=fopen((argc>1)? argv[1]: "/usr/share/festival/dicts/cmu/cmudict-0.4.out", "rt");
F2=fopen("cmudict.idx", "wb");
F3=fopen("cmudict.dict", "wb");

fgets(current2, 200, F);

nn=n=off=siz=0;

*prev=0;
for (i=0; i<50; i++) sp[i]=(char *)malloc(10);

while (fgets(current, 200, F))
   {
   i=0;
   
   spell=strchr(current+2, '(');
   p=strchr(current+2, '\"');
   *p=*current2=0;
   *strchr(p+2, ' ')=0;
   same=0;
   if (*prev) if (strcmp(prev, current+2)==0) 
      {
      same=1;
      n--; 
      }
   n++;
   strcpy(prev, current+2);
   if (strcmp(p+2, "nil")!=0)
      {
      switch (p[2])
         {
         case 'd': sprintf(current2, "(article) "); break;
         case 'n': sprintf(current2, "(noun) "); break;
         case 'v': sprintf(current2, "(verb) "); break;
         case 'j': sprintf(current2, "(adjective) "); break;
         default: sprintf(current2, "(%s) ", p+2); break;
         }
      
      }
   strcat(current2, "[");
   nn=ar=ay=lastcons=0;
   laster=preaccent=accent=-1;
   while ((spell=(char *)strtok(spell, " ()\n\r"))!=NULL)
      {
      if (*spell=='0') 
         {
         i++;
         for (j=nn-1; j>lastcons; j--)
            {
            p=LastChar(sp[j]);
            if (*p==':') 
               {
               
               if (*(p-1)=='i') 
                  {
                  *(p-1)='\xC4';
                  *(p)='\xB1';
                  }
               else if (laster!=j) *p=0;
               }
            }
         lastcons=nn-1;
         if (!IsConsonant(sp[lastcons])) lastcons++;
         spell=NULL;
         continue;
         }
      else if (*spell=='1') 
         {
         i++;
         if (accent!=-1) preaccent=accent;
         accent=lastcons;
         if (accent!=0 && IsConsonant(sp[accent]) && IsConsonant(sp[accent+1])) accent++;
         
         if (laster>=lastcons) 
            {
            p=LastChar(sp[laster]);
				if (*p!=':') 
               {
               memmove(p+2, p+1, strlen(p+1)+1);
               p[1]=':';
               }
            }
         lastcons=nn-1;
         if (!IsConsonant(sp[lastcons])) lastcons++;
         spell=NULL;
         continue;
         }
      
      if (strcmp(spell, "er")==0) 
         {
         Ar(); 
         laster=nn;
         strcpy(sp[nn++], "\xC9\x99");
         ar=2;
         }
      else if (strcmp(spell, "eh")==0) 
         {
         Ar(); strcpy(sp[nn++], "e"); 
         }
      else if (strcmp(spell, "ah")==0) 
         {
         Ar(); strcpy(sp[nn++], "\xCA\x8C"); 
         }
      else if (strcmp(spell, "y")==0) strcpy(sp[nn++], "j");
      else if (strcmp(spell, "ng")==0) strcpy(sp[nn++], "\xC5\x8B");
      else if (strcmp(spell, "sh")==0) strcpy(sp[nn++], "\xCA\x83");
      else if (strcmp(spell, "zh")==0) strcpy(sp[nn++], "\xCA\x92");
      else if (strcmp(spell, "ch")==0) strcpy(sp[nn++], "t\xCA\x83");
      else if (strcmp(spell, "dh")==0) strcpy(sp[nn++], "\xC3\xB0");
      else if (strcmp(spell, "th")==0) strcpy(sp[nn++], "\xCE\xB8");
      else if (strcmp(spell, "ay")==0) 
         {
         Ar(); strcpy(sp[nn++], "a\xC4\xB1");
         ay=2; 
         }
      else if (strcmp(spell, "hh")==0) 
         {
         strcpy(sp[nn++], "h"); 
         }
      else if (strcmp(spell, "ey")==0) 
         {
         Ar(); strcpy(sp[nn++], "e\xC4\xB1"); 
         }
      else if (strcmp(spell, "oy")==0) 
         {
         Ar(); strcpy(sp[nn++], "\xC9\x94\xC4\xB1"); 
         }
      else if (strcmp(spell, "iy")==0) 
         {
         Ar(); strcpy(sp[nn++], "i:"); 
         }
      else if (strcmp(spell, "ae")==0) 
         {
         Ar(); strcpy(sp[nn++], "\xC3\xA6"); 
         }
      else if (strcmp(spell, "ao")==0)
         {
         Ar(); strcpy(sp[nn++], "\xC9\x94"); 
         }
      else if (strcmp(spell, "aa")==0)
         {
         Ar(); strcpy(sp[nn++], "\xC9\x91"); 
         }
      else if (strcmp(spell, "ax")==0) 
         {
         Ar(); strcpy(sp[nn++], "\xC9\x99"); 
         }
      else if (strcmp(spell, "aw")==0) 
         {
         Ar(); strcpy(sp[nn++], "au"); 
         }
      else if (strcmp(spell, "ow")==0) 
         {
         Ar(); strcpy(sp[nn++], "\xC9\x99u"); 
         }
      else if (strcmp(spell, "uw")==0 || strcmp(spell, "uh")==0) 
         {
         Ar(); strcpy(sp[nn++], "u:"); 
         }
      else if (strcmp(spell, "ih")==0) 
         {
         Ar(); strcpy(sp[nn++], "\xC4\xB1"); 
         }
      else if (strcmp(spell, "r")==0)
         {
         ar=2;
         if (nn>0)
            {
            if (strcmp(sp[nn-1], "u:")==0)
               {
               strcpy(sp[nn-1], "u\xC9\x99");
               }
            else if (ay || strcmp(sp[nn-1], "\xC4\xB1")==0)
               {
               strcat(sp[nn-1], "\xC9\x99");
               }
            else if (strcmp(sp[nn-1], "\xC9\x94")==0 || strcmp(sp[nn-1], "\xC9\x91")==0)
            strcat(sp[nn-1], ":");
            }
         }
      else if (strcmp(spell, "jh")==0) strcpy(sp[nn++], "d\xCA\x92"); 
      else strcpy(sp[nn++], spell);
      
      if (ar==1 && nn>=2 && strcmp(sp[nn-2], "e")==0 && IsConsonant(sp[nn-1])) strcpy(sp[nn-2], "\xC9\x9B\xC9\x99");
      if (ar) ar--;
      if (ay) ay--;
      if (nn>=2) if (IsConsonant(sp[nn-1]) && strcmp(sp[nn-2], "\xC9\x91")==0) strcpy(sp[nn-2], "\xC9\x94");
      
      spell=NULL;
      }
   
   if (ar) if (strcmp(sp[nn-1], "e")==0) strcpy(sp[nn-1], "\xC9\x9B\xC9\x99");
   
   for (j=0; j<nn; j++) 
      {
      if (i!=1) if (j==accent || j==preaccent) strcat(current2, "\'");
      strcat(current2, sp[j]);
      }
   strcat(current2, "]");
   
   printf("%s\t%s\n", current+2, current2);
   
   if (same) 
      {
      fwrite("\n", 1, 1, F3);
      siz++;
      off++;
      }
   else siz=0;
   
   siz+=strlen(current2);
   
   fwrite(current2, strlen(current2), 1, F3);
   
   if (!same)
      {
      fwrite(current+2, strlen(current+2)+1, 1, F2);
      for (j=3; j>=0; j--)
      fwrite(((char*)&off)+j, 1, 1, F2);
      }
   else fseek(F2, -4L, SEEK_END); 
   
   for (j=3; j>=0; j--)	
   fwrite(((char*)&siz)+j, 1, 1, F2);
   off+=strlen(current2);
   }
fclose(F3);
F3=fopen("cmudict.ifo", "wt");

time(&t0);
t=gmtime(&t0);

fprintf(F3, "StarDict's dict ifo file\nversion=2.4.2\nwordcount=%li\nidxfilesize=%li\n", n, ftell(F2));
fprintf(F3, "bookname=CMU American English spelling\ndate=%i.%02i.%02i\nsametypesequence=m\n",
t->tm_year+1900, t->tm_mon+1, t->tm_mday);

for (i=0; i<50; i++) free (sp[i]);

fclose(F);
fclose(F2);
fclose(F3);
return 0;
}