OSDN Git Service

openJtalk結合
[nlite/nlite.git] / open_jtalk_lib / open_jtalk / njd2jpcommon / njd2jpcommon.c
1 /* ----------------------------------------------------------------- */
2 /*           The Japanese TTS System "Open JTalk"                    */
3 /*           developed by HTS Working Group                          */
4 /*           http://open-jtalk.sourceforge.net/                      */
5 /* ----------------------------------------------------------------- */
6 /*                                                                   */
7 /*  Copyright (c) 2008-2011  Nagoya Institute of Technology          */
8 /*                           Department of Computer Science          */
9 /*                                                                   */
10 /* All rights reserved.                                              */
11 /*                                                                   */
12 /* Redistribution and use in source and binary forms, with or        */
13 /* without modification, are permitted provided that the following   */
14 /* conditions are met:                                               */
15 /*                                                                   */
16 /* - Redistributions of source code must retain the above copyright  */
17 /*   notice, this list of conditions and the following disclaimer.   */
18 /* - Redistributions in binary form must reproduce the above         */
19 /*   copyright notice, this list of conditions and the following     */
20 /*   disclaimer in the documentation and/or other materials provided */
21 /*   with the distribution.                                          */
22 /* - Neither the name of the HTS working group nor the names of its  */
23 /*   contributors may be used to endorse or promote products derived */
24 /*   from this software without specific prior written permission.   */
25 /*                                                                   */
26 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND            */
27 /* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,       */
28 /* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF          */
29 /* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE          */
30 /* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS */
31 /* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,          */
32 /* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED   */
33 /* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,     */
34 /* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */
35 /* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,   */
36 /* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY    */
37 /* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE           */
38 /* POSSIBILITY OF SUCH DAMAGE.                                       */
39 /* ----------------------------------------------------------------- */
40
41 #ifndef NJD2JPCOMMON_C
42 #define NJD2JPCOMMON_C
43
44 #ifdef __cplusplus
45 #define NJD2JPCOMMON_C_START extern "C" {
46 #define NJD2JPCOMMON_C_END   }
47 #else
48 #define NJD2JPCOMMON_C_START
49 #define NJD2JPCOMMON_C_END
50 #endif                          /* __CPLUSPLUS */
51
52 NJD2JPCOMMON_C_START;
53
54 #include <stdio.h>
55 #include <stdlib.h>
56 #include <string.h>
57
58 #include "njd.h"
59 #include "jpcommon.h"
60
61 #if defined(CHARSET_EUC_JP)
62 #include "njd2jpcommon_rule_euc_jp.h"
63 #elif defined(CHARSET_SHIFT_JIS)
64 #include "njd2jpcommon_rule_shift_jis.h"
65 #elif defined(CHARSET_UTF_8)
66 #include "njd2jpcommon_rule_utf_8.h"
67 #else
68 #error CHARSET is not specified
69 #endif
70
71 #define MAXBUFLEN 1024
72
73 static void convert_pos(char *buff, char *pos, char *pos_group1, char *pos_group2, char *pos_group3)
74 {
75    int i;
76
77    for (i = 0; njd2jpcommon_pos_list[i] != NULL; i += 5) {
78       if (strcmp(njd2jpcommon_pos_list[i], pos) == 0 &&
79           strcmp(njd2jpcommon_pos_list[i + 1], pos_group1) == 0 &&
80           strcmp(njd2jpcommon_pos_list[i + 2], pos_group2) == 0 &&
81           strcmp(njd2jpcommon_pos_list[i + 3], pos_group3) == 0) {
82          strcpy(buff, njd2jpcommon_pos_list[i + 4]);
83          return;
84       }
85    }
86    fprintf(stderr,
87            "WARING: convert_pos() in njd2jpcommon.c: %s %s %s %s are not appropriate POS.\n", pos,
88            pos_group1, pos_group2, pos_group3);
89    strcpy(buff, njd2jpcommon_pos_list[4]);
90 }
91
92 static void convert_ctype(char *buff, char *ctype)
93 {
94    int i;
95
96    for (i = 0; njd2jpcommon_ctype_list[i] != NULL; i += 2) {
97       if (strcmp(njd2jpcommon_ctype_list[i], ctype) == 0) {
98          strcpy(buff, njd2jpcommon_ctype_list[i + 1]);
99          return;
100       }
101    }
102    fprintf(stderr,
103            "WARING: convert_ctype() in njd2jpcommon.c: %s is not appropriate conjugation type.\n",
104            ctype);
105    strcpy(buff, njd2jpcommon_ctype_list[1]);
106 }
107
108 static void convert_cform(char *buff, char *cform)
109 {
110    int i;
111
112    for (i = 0; njd2jpcommon_cform_list[i] != NULL; i += 2) {
113       if (strcmp(njd2jpcommon_cform_list[i], cform) == 0) {
114          strcpy(buff, njd2jpcommon_cform_list[i + 1]);
115          return;
116       }
117    }
118    fprintf(stderr,
119            "WARING: convert_cform() in njd2jpcommon.c: %s is not appropriate conjugation form.\n",
120            cform);
121    strcpy(buff, njd2jpcommon_cform_list[1]);
122 }
123
124 void njd2jpcommon(JPCommon * jpcommon, NJD * njd)
125 {
126    char buff[MAXBUFLEN];
127    NJDNode *inode;
128    JPCommonNode *jnode;
129
130    for (inode = njd->head; inode != NULL; inode = inode->next) {
131       jnode = (JPCommonNode *) calloc(1, sizeof(JPCommonNode));
132       JPCommonNode_initialize(jnode);
133       JPCommonNode_set_pron(jnode, NJDNode_get_pron(inode));
134       convert_pos(buff, NJDNode_get_pos(inode), NJDNode_get_pos_group1(inode),
135                   NJDNode_get_pos_group2(inode), NJDNode_get_pos_group3(inode));
136       JPCommonNode_set_pos(jnode, buff);
137       convert_ctype(buff, NJDNode_get_ctype(inode));
138       JPCommonNode_set_ctype(jnode, buff);
139       convert_cform(buff, NJDNode_get_cform(inode));
140       JPCommonNode_set_cform(jnode, buff);
141       JPCommonNode_set_acc(jnode, NJDNode_get_acc(inode));
142       JPCommonNode_set_chain_flag(jnode, NJDNode_get_chain_flag(inode));
143       JPCommon_push(jpcommon, jnode);
144    }
145 }
146
147 NJD2JPCOMMON_C_END;
148
149 #endif                          /* !NJD2JPCOMMON_C */