1 /* ----------------------------------------------------------------- */
2 /* The Japanese TTS System "Open JTalk" */
3 /* developed by HTS Working Group */
4 /* http://open-jtalk.sourceforge.net/ */
5 /* ----------------------------------------------------------------- */
7 /* Copyright (c) 2008-2011 Nagoya Institute of Technology */
8 /* Department of Computer Science */
10 /* All rights reserved. */
12 /* Redistribution and use in source and binary forms, with or */
13 /* without modification, are permitted provided that the following */
14 /* conditions are met: */
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. */
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 /* ----------------------------------------------------------------- */
41 #ifndef NJD2JPCOMMON_C
42 #define NJD2JPCOMMON_C
45 #define NJD2JPCOMMON_C_START extern "C" {
46 #define NJD2JPCOMMON_C_END }
48 #define NJD2JPCOMMON_C_START
49 #define NJD2JPCOMMON_C_END
50 #endif /* __CPLUSPLUS */
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"
68 #error CHARSET is not specified
71 #define MAXBUFLEN 1024
73 static void convert_pos(char *buff, char *pos, char *pos_group1, char *pos_group2, char *pos_group3)
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]);
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]);
92 static void convert_ctype(char *buff, char *ctype)
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]);
103 "WARING: convert_ctype() in njd2jpcommon.c: %s is not appropriate conjugation type.\n",
105 strcpy(buff, njd2jpcommon_ctype_list[1]);
108 static void convert_cform(char *buff, char *cform)
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]);
119 "WARING: convert_cform() in njd2jpcommon.c: %s is not appropriate conjugation form.\n",
121 strcpy(buff, njd2jpcommon_cform_list[1]);
124 void njd2jpcommon(JPCommon * jpcommon, NJD * njd)
126 char buff[MAXBUFLEN];
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);
149 #endif /* !NJD2JPCOMMON_C */