void NJDNode_sprint(NJDNode * node, char *buff, const char *split_code) { sprintf(buff, "%s%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%d/%d,%s,%d%s", buff, NJDNode_get_string(node), NJDNode_get_pos(node), NJDNode_get_pos_group1(node), NJDNode_get_pos_group2(node), NJDNode_get_pos_group3(node), NJDNode_get_ctype(node), NJDNode_get_cform(node), NJDNode_get_orig(node), NJDNode_get_read(node), NJDNode_get_pron(node), NJDNode_get_acc(node), NJDNode_get_mora_size(node), NJDNode_get_chain_rule(node), NJDNode_get_chain_flag(node), split_code); }
void NJDNode_fprint(NJDNode * node, FILE * fp) { fprintf(fp, "%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%d/%d,%s,%d\n", NJDNode_get_string(node), NJDNode_get_pos(node), NJDNode_get_pos_group1(node), NJDNode_get_pos_group2(node), NJDNode_get_pos_group3(node), NJDNode_get_ctype(node), NJDNode_get_cform(node), NJDNode_get_orig(node), NJDNode_get_read(node), NJDNode_get_pron(node), NJDNode_get_acc(node), NJDNode_get_mora_size(node), NJDNode_get_chain_rule(node), NJDNode_get_chain_flag(node)); }
void njd_set_accent_type(NJD * njd) { NJDNode *node; NJDNode *top_node = NULL; char rule[MAXBUFLEN]; int add_type = 0; int mora_size = 0; if (njd == NULL || njd->head == NULL) return; for (node = njd->head; node != NULL; node = node->next) { if (NJDNode_get_string(node) == NULL) continue; if ((node == njd->head) || (NJDNode_get_chain_flag(node) != 1)) { /* store the top node */ top_node = node; mora_size = 0; } else if (node->prev != NULL && NJDNode_get_chain_flag(node) == 1) { /* get accent change type */ get_rule(NJDNode_get_chain_rule(node), NJDNode_get_pos(node->prev), rule, &add_type); /* change accent type */ if (strcmp(rule, "*") == 0) { /* no chnage */ } else if (strcmp(rule, "F1") == 0) { /* for ancillary word */ } else if (strcmp(rule, "F2") == 0) { if (NJDNode_get_acc(top_node) == 0) NJDNode_set_acc(top_node, mora_size + add_type); } else if (strcmp(rule, "F3") == 0) { if (NJDNode_get_acc(top_node) != 0) NJDNode_set_acc(top_node, mora_size + add_type); } else if (strcmp(rule, "F4") == 0) { NJDNode_set_acc(top_node, mora_size + add_type); } else if (strcmp(rule, "F5") == 0) { NJDNode_set_acc(top_node, 0); } else if (strcmp(rule, "C1") == 0) { /* for noun */ NJDNode_set_acc(top_node, mora_size + NJDNode_get_acc(node)); } else if (strcmp(rule, "C2") == 0) { NJDNode_set_acc(top_node, mora_size + 1); } else if (strcmp(rule, "C3") == 0) { NJDNode_set_acc(top_node, mora_size); } else if (strcmp(rule, "C4") == 0) { NJDNode_set_acc(top_node, 0); } else if (strcmp(rule, "C5") == 0) { } else if (strcmp(rule, "P1") == 0) { /* for postfix */ if (NJDNode_get_acc(node) == 0) NJDNode_set_acc(top_node, 0); else NJDNode_set_acc(top_node, mora_size + NJDNode_get_acc(node)); } else if (strcmp(rule, "P2") == 0) { if (NJDNode_get_acc(node) == 0) NJDNode_set_acc(top_node, mora_size + 1); else NJDNode_set_acc(top_node, mora_size + NJDNode_get_acc(node)); } else if (strcmp(rule, "P6") == 0) { NJDNode_set_acc(top_node, 0); } else if (strcmp(rule, "P14") == 0) { if (NJDNode_get_acc(node) != 0) NJDNode_set_acc(top_node, mora_size + NJDNode_get_acc(node)); } } /* change accent type for digit */ if (node->prev != NULL && NJDNode_get_chain_flag(node) == 1 && strcmp(NJDNode_get_pos_group1(node->prev), NJD_SET_ACCENT_TYPE_KAZU) == 0 && strcmp(NJDNode_get_pos_group1(node), NJD_SET_ACCENT_TYPE_KAZU) == 0) { if (strcmp(NJDNode_get_string(node), NJD_SET_ACCENT_TYPE_JYUU) == 0) { /* 10^1 */ if (NJDNode_get_string(node->prev) != NULL && (strcmp(NJDNode_get_string(node->prev), NJD_SET_ACCENT_TYPE_SAN) == 0 || strcmp(NJDNode_get_string(node->prev), NJD_SET_ACCENT_TYPE_YON) == 0 || strcmp(NJDNode_get_string(node->prev), NJD_SET_ACCENT_TYPE_KYUU) == 0 || strcmp(NJDNode_get_string(node->prev), NJD_SET_ACCENT_TYPE_NAN) == 0 || strcmp(NJDNode_get_string(node->prev), NJD_SET_ACCENT_TYPE_SUU) == 0)) { NJDNode_set_acc(node->prev, 1); } else { NJDNode_set_acc(node->prev, 1); } if (NJDNode_get_string(node->prev) != NULL && (strcmp(NJDNode_get_string(node->prev), NJD_SET_ACCENT_TYPE_GO) == 0 || strcmp(NJDNode_get_string(node->prev), NJD_SET_ACCENT_TYPE_ROKU) == 0 || strcmp(NJDNode_get_string(node->prev), NJD_SET_ACCENT_TYPE_HACHI) == 0)) { if (node->next != NULL && NJDNode_get_string(node->next) != NULL && (strcmp(NJDNode_get_string(node->next), NJD_SET_ACCENT_TYPE_ICHI) == 0 || strcmp(NJDNode_get_string(node->next), NJD_SET_ACCENT_TYPE_NI) == 0 || strcmp(NJDNode_get_string(node->next), NJD_SET_ACCENT_TYPE_SAN) == 0 || strcmp(NJDNode_get_string(node->next), NJD_SET_ACCENT_TYPE_YON) == 0 || strcmp(NJDNode_get_string(node->next), NJD_SET_ACCENT_TYPE_GO) == 0 || strcmp(NJDNode_get_string(node->next), NJD_SET_ACCENT_TYPE_ROKU) == 0 || strcmp(NJDNode_get_string(node->next), NJD_SET_ACCENT_TYPE_NANA) == 0 || strcmp(NJDNode_get_string(node->next), NJD_SET_ACCENT_TYPE_HACHI) == 0 || strcmp(NJDNode_get_string(node->next), NJD_SET_ACCENT_TYPE_KYUU) == 0)) NJDNode_set_acc(node->prev, 0); } } else if (strcmp(NJDNode_get_string(node), NJD_SET_ACCENT_TYPE_HYAKU) == 0) { /* 10^2 */ if (NJDNode_get_string(node->prev) != NULL && strcmp(NJDNode_get_string(node->prev), NJD_SET_ACCENT_TYPE_NANA) == 0) { NJDNode_set_acc(node->prev, 2); } else if (NJDNode_get_string(node->prev) != NULL && (strcmp(NJDNode_get_string(node->prev), NJD_SET_ACCENT_TYPE_SAN) == 0 || strcmp(NJDNode_get_string(node->prev), NJD_SET_ACCENT_TYPE_YON) == 0 || strcmp(NJDNode_get_string(node->prev), NJD_SET_ACCENT_TYPE_KYUU) == 0 || strcmp(NJDNode_get_string(node->prev), NJD_SET_ACCENT_TYPE_NAN) == 0)) { NJDNode_set_acc(node->prev, 1); } else { NJDNode_set_acc(node->prev, NJDNode_get_mora_size(node->prev) + NJDNode_get_mora_size(node)); } } else if (strcmp(NJDNode_get_string(node), NJD_SET_ACCENT_TYPE_SEN) == 0) { /* 10^3 */ NJDNode_set_acc(node->prev, NJDNode_get_mora_size(node->prev) + 1); } else if (strcmp(NJDNode_get_string(node), NJD_SET_ACCENT_TYPE_MAN) == 0) { /* 10^4 */ NJDNode_set_acc(node->prev, NJDNode_get_mora_size(node->prev) + 1); } else if (strcmp(NJDNode_get_string(node), NJD_SET_ACCENT_TYPE_OKU) == 0) { /* 10^8 */ if (NJDNode_get_string(node->prev) != NULL && (strcmp(NJDNode_get_string(node->prev), NJD_SET_ACCENT_TYPE_ICHI) == 0 || strcmp(NJDNode_get_string(node->prev), NJD_SET_ACCENT_TYPE_ROKU) == 0 || strcmp(NJDNode_get_string(node->prev), NJD_SET_ACCENT_TYPE_NANA) == 0 || strcmp(NJDNode_get_string(node->prev), NJD_SET_ACCENT_TYPE_HACHI) == 0 || strcmp(NJDNode_get_string(node->prev), NJD_SET_ACCENT_TYPE_IKU) == 0)) { NJDNode_set_acc(node->prev, 2); } else { NJDNode_set_acc(node->prev, 1); } } else if (strcmp(NJDNode_get_string(node), NJD_SET_ACCENT_TYPE_CHOU) == 0) { /* 10^12 */ if (NJDNode_get_string(node->prev) != NULL && (strcmp(NJDNode_get_string(node->prev), NJD_SET_ACCENT_TYPE_ROKU) == 0 || strcmp(NJDNode_get_string(node->prev), NJD_SET_ACCENT_TYPE_NANA) == 0)) { NJDNode_set_acc(node->prev, 2); } else { NJDNode_set_acc(node->prev, 1); } } } if (strcmp(NJDNode_get_string(node), NJD_SET_ACCENT_TYPE_JYUU) == 0 && NJDNode_get_chain_flag(node) != 1 && node->next != NULL && strcmp(NJDNode_get_pos_group1(node->next), NJD_SET_ACCENT_TYPE_KAZU) == 0) { NJDNode_set_acc(node, 0); } mora_size += NJDNode_get_mora_size(node); } }