OSDN Git Service

Bumped version 2.4.4.
[chasen-legacy/chasen.git] / lib / getid.c
1 /*
2  * Copyright (c) 2003 Nara Institute of Science and Technology
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  *   notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. The name Nara Institute of Science and Technology may not be used to
15  *    endorse or promote products derived from this software without
16  *    specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY Nara Institute of Science and Technology 
19  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 
21  * PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE Nara Institute
22  * of Science and Technology BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
24  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
25  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
26  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 
27  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  *
30  * $Id: getid.c,v 1.1.1.1 2007/03/13 07:40:10 masayu-a Exp $
31  */
32
33 #include "chadic.h"
34
35 /*
36  * get POS str id
37  *
38  */
39 int
40 cha_get_nhinsi_str_id(char **hinsi)
41 {
42     int id, i, d;
43
44     if (!*hinsi)
45         cha_exit_file(1, "an empty string for POS");
46
47     for (id = 0; *hinsi; hinsi++) {
48         if (!**hinsi)
49             cha_exit_file(1, "an empty string for POS");
50         for (i = 0; (d = Cha_hinsi[id].daughter[i]) != 0; i++) {
51             if (!strcmp(Cha_hinsi[d].name, *hinsi))
52                 break;
53         }
54         if (!d) {
55             cha_exit_file(1, "POS `%s' is undefined", *hinsi);
56         }
57         id = d;
58     }
59
60     return id;
61 }
62
63 /*
64  * get POS id 
65  */
66 int
67 cha_get_nhinsi_id(chasen_cell_t * cell)
68 {
69     char *hinsi_str[256];
70     char **hinsi = hinsi_str;
71
72     for (; !nullp(cell); cell = cha_cdr(cell))
73         *hinsi++ = cha_s_atom(cha_car(cell));
74
75     *hinsi = NULL;
76
77     return cha_get_nhinsi_str_id(hinsi_str);
78 }
79
80 /*
81  * get ctype id 
82  */
83 int
84 cha_get_type_id(char *x)
85 {
86     int i;
87
88     if (x == NULL) {
89         cha_exit_file(1, "null string for type");
90         return 0;
91     }
92
93     if (x[0] == '*' && x[1] == '\0')
94         return 0;
95
96     for (i = 1; strcmp(Cha_type[i].name, x);) {
97         if (!Cha_type[++i].name) {
98             cha_exit_file(1, "type `%s' is undefined", x);
99         }
100     }
101
102     return i;
103 }
104
105 /*
106  * get cform id 
107  */
108 int
109 cha_get_form_id(char *x, int type)
110 {
111     int i;
112
113     if (x == NULL) {
114         cha_exit_file(1, "null string for form");
115         return 0;
116     }
117
118     if (x[0] == '*' && x[1] == '\0')
119         return 0;
120
121     if (type == 0) {
122         cha_exit_file(1, "Invalid type number for type `%s'", x);
123         return 0;
124     }
125
126     for (i = 1; strcmp(Cha_form[type][i].name, x);) {
127         if (!Cha_form[type][++i].name) {
128             cha_exit_file(1, "type `%s' has no conjugation `%s'",
129                           Cha_type[type].name, x);
130             return 0;
131         }
132     }
133
134     return i;
135 }