コード例 #1
0
ファイル: testpinyin.c プロジェクト: 13572293130/fcitx
int main()
{
    FcitxPinyinConfig pyconfig;
    ParsePYStruct parse;
    memset(&pyconfig, 0, sizeof(pyconfig));
    memset(&parse, 0, sizeof(parse));
    InitPYTable(&pyconfig);
    InitPYSplitData(&pyconfig);
    ParsePY(&pyconfig, "wanan", &parse, PY_PARSE_INPUT_USER, false);
    PrintParsedPY(&parse, "wan an");
    ParsePY(&pyconfig, "dier", &parse, PY_PARSE_INPUT_USER, false);
    PrintParsedPY(&parse, "di er");
    ParsePY(&pyconfig, "dierge", &parse, PY_PARSE_INPUT_USER, false);
    PrintParsedPY(&parse, "di er ge");
    ParsePY(&pyconfig, "dieru", &parse, PY_PARSE_INPUT_USER, false);
    PrintParsedPY(&parse, "die ru");
    ParsePY(&pyconfig, "diepian", &parse, PY_PARSE_INPUT_USER, false);
    PrintParsedPY(&parse, "die pian");
    ParsePY(&pyconfig, "bier", &parse, PY_PARSE_INPUT_USER, false);
    PrintParsedPY(&parse, "bi er");
    ParsePY(&pyconfig, "bingan", &parse, PY_PARSE_INPUT_USER, false);
    PrintParsedPY(&parse, "bing an");
    ParsePY(&pyconfig, "xiai", &parse, PY_PARSE_INPUT_USER, false);
    PrintParsedPY(&parse, "xi ai");
    return 0;
}
コード例 #2
0
ファイル: createPYMB.c プロジェクト: eguopt/fcitx
void CreatePYPhrase(void)
{
    char            strPY[256];
    char            strPhrase[256];
    char            strMap[256];
    ParsePYStruct   strTemp;
    int             iIndex, i, s1, s2, j, k;
    _PyPhrase      *phrase, *t, *tt;
    FILE           *f = fopen("pyERROR", "w");
    FILE           *fg = fopen("pyPhrase.ok", "w");
    int             kkk;
    unsigned int    uIndex, uTemp;
    FcitxPinyinConfig pyconfig;

    memset(&pyconfig, 0 , sizeof(pyconfig));
    InitMHPY(&pyconfig.MHPY_C, MHPY_C_TEMPLATE);
    InitMHPY(&pyconfig.MHPY_S, MHPY_S_TEMPLATE);
    InitPYTable(&pyconfig);

    s1 = 0;
    s2 = 0;
    uIndex = 0;
    printf("Start Loading Phrase...\n");

    while (!feof(fpt)) {
        fscanf(fpt, "%s", strPY);
        fscanf(fpt, "%s\n", strPhrase);

        if (strlen(strPhrase) < 3)
            continue;

        ParsePY(&pyconfig, strPY, &strTemp, PY_PARSE_INPUT_SYSTEM, false);

        s2++;

        kkk = 0;

        if (strTemp.iHZCount != fcitx_utf8_strlen(strPhrase) || (strTemp.iMode & PARSE_ABBR)) {
            fprintf(f, "%s %s\n", strPY, strPhrase);
            continue;
        }

        strMap[0] = '\0';

        for (iIndex = 0; iIndex < strTemp.iHZCount; iIndex++)
            strcat(strMap, strTemp.strMap[iIndex]);

        for (iIndex = 0; iIndex < iPYFACount; iIndex++) {
            if (!strncmp(PYFAList[iIndex].strMap, strMap, 2)) {
                for (i = 0; i < PYFAList[iIndex].iHZCount; i++) {
                    if (!fcitx_utf8_strncmp(PYFAList[iIndex].pyBase[i].strHZ, strPhrase, 1)) {
                        t = PYFAList[iIndex].pyBase[i].phrase;

                        for (j = 0; j < PYFAList[iIndex].pyBase[i].iPhraseCount; j++) {
                            tt = t;
                            t = t->next;

                            if (!strcmp(t->strMap, strMap + 2) && !strcmp(t->strPhrase, strPhrase + fcitx_utf8_char_len(strPhrase))) {
                                printf("\n\t%d: %s %s ----->deleted.\n", s2, strPY, strPhrase);
                                goto _next;
                            }

                            if (strcmp(t->strMap, strMap + 2) > 0) {
                                t = tt;
                                break;
                            }
                        }

                        phrase = (_PyPhrase *) malloc(sizeof(_PyPhrase));

                        phrase->strPhrase = (char *) malloc(sizeof(char) * (strlen(strPhrase) - fcitx_utf8_char_len(strPhrase) + 1));
                        phrase->strMap = (char *) malloc(sizeof(char) * ((strTemp.iHZCount - 1) * 2 + 1));
                        phrase->uIndex = uIndex++;
                        strcpy(phrase->strPhrase, strPhrase + fcitx_utf8_char_len(strPhrase));
                        strcpy(phrase->strMap, strMap + 2);

                        tt = t->next;
                        t->next = phrase;
                        phrase->next = tt;
                        PYFAList[iIndex].pyBase[i].iPhraseCount++;
                        s1++;
                        kkk = 1;

                    _next:
                        ;
                    }
                }
            }
        }

        if (!kkk)
            fprintf(f, "%s %s %s\n", strPY, strPhrase, (char *)(strTemp.strPYParsed));
        else
            fprintf(fg, "%s %s\n", strPY, strPhrase);
    }

    printf("%d Phrases, %d Converted!\nWriting Phrase file ...", s2, s1);

    for (i = 0; i < iPYFACount; i++) {
        for (j = 0; j < PYFAList[i].iHZCount; j++) {
            iIndex = PYFAList[i].pyBase[j].iPhraseCount;

            if (iIndex) {
                int8_t clen = strlen(PYFAList[i].pyBase[j].strHZ);
                fwrite(&i, sizeof(int), 1, fp2);
                fwrite(&clen, sizeof(int8_t), 1, fp2);
                fwrite(PYFAList[i].pyBase[j].strHZ, sizeof(char) * clen, 1, fp2);

                fwrite(&iIndex, sizeof(int), 1, fp2);
                t = PYFAList[i].pyBase[j].phrase->next;

                for (k = 0; k < PYFAList[i].pyBase[j].iPhraseCount; k++) {
                    int slen = strlen(t->strPhrase);
                    iIndex = strlen(t->strMap);
                    fwrite(&iIndex, sizeof(int), 1, fp2);
                    fwrite(t->strMap, sizeof(char), iIndex, fp2);
                    fwrite(&slen, sizeof(int), 1, fp2);
                    fwrite(t->strPhrase, sizeof(char), strlen(t->strPhrase), fp2);
                    uTemp = uIndex - 1 - t->uIndex;
                    fwrite(&uTemp, sizeof(unsigned int), 1, fp2);
                    t = t->next;
                }
            }
        }
    }

    printf("\nOK!\n");

    fclose(fp2);
    fclose(fpt);
}