fixes phrase_index.h
[platform/upstream/libpinyin.git] / src / storage / tag_utility.h
1 /* 
2  *  libpinyin
3  *  Library to deal with pinyin.
4  *  
5  *  Copyright (C) 2010 Peng Wu
6  *  
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation; either version 2 of the License, or
10  *  (at your option) any later version.
11  * 
12  *  This program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  *  GNU General Public License for more details.
16  *  
17  *  You should have received a copy of the GNU General Public License
18  *  along with this program; if not, write to the Free Software
19  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20  */
21
22 #ifndef TAG_UTILITY_H
23 #define TAG_UTILITY_H
24
25 #include "novel_types.h"
26
27 /* Note: the optional tag has been removed from the first implementation.
28  * Maybe the optional tag will be added back later.
29  */
30
31 namespace pinyin{
32
33 /**
34  * taglib_init:
35  * @returns: whether the initialize operation is successful.
36  *
37  * Initialize the n-gram tag parse library.
38  *
39  */
40 bool taglib_init();
41
42 /**
43  * taglib_add_tag:
44  * @line_type: the line type.
45  * @line_tag: the line tag.
46  * @num_of_values: the number of values following the line tag.
47  * @required_tags: the required tags of the line.
48  * @ignored_tags: the ignored tags of the line.
49  * @returns: whether the add operation is successful.
50  *
51  * Add one line tag to the tag parse library.
52  *
53  * Note: the required and ignored tags are separated by ',' or ':' .
54  *
55  */
56 bool taglib_add_tag(int line_type, const char * line_tag, int num_of_values, const char * required_tags, const char * ignored_tags);
57
58 /**
59  * taglib_read:
60  * @input_line: one input line.
61  * @line_type: the line type.
62  * @values: the values following the line tag.
63  * @required: the required tags of the line type.
64  * @returns: whether the line is parsed ok.
65  *
66  * Parse one input line into line_type, values and required tags.
67  *
68  * Note: most parameters are hash table of string (const char *).
69  *
70  */
71 bool taglib_read(const char * input_line, int & line_type,
72                  GPtrArray * values, GHashTable * required);
73
74 /**
75  * taglib_remove_tag:
76  * @line_type: the type of the line tag.
77  * @returns: whether the remove operation is successful.
78  *
79  * Remove one line tag.
80  *
81  */
82 bool taglib_remove_tag(int line_type);
83
84 /**
85  * taglib_push_state:
86  * @returns: whether the push operation is successful.
87  *
88  * Push the current state onto the stack.
89  *
90  * Note: the taglib_push/pop_state functions are used to save
91  * the current known tag list in stack.
92  * Used when the parsing context is changed.
93  */
94 bool taglib_push_state();
95
96 /**
97  * taglib_pop_state:
98  * @returns: whether the pop operation is successful.
99  *
100  * Pop the current state off the stack.
101  *
102  */
103 bool taglib_pop_state();
104
105 /**
106  * taglib_fini:
107  * @returns: whether the finish operation is successful.
108  *
109  * Finish the n-gram tag parse library.
110  *
111  */
112 bool taglib_fini();
113
114 class PhraseLargeTable2;
115 class FacadePhraseIndex;
116
117
118 /**
119  * taglib_string_to_token:
120  * @phrase_table: the phrase table for token lookup.
121  * @phrase_index: the phrase index to prepare PhraseTokens.
122  * @string: the string of the phrase.
123  * @returns: the phrase token found in phrase table.
124  *
125  * Translate one phrase into the token.
126  *
127  */
128 phrase_token_t taglib_string_to_token(PhraseLargeTable2 * phrase_table,
129                                       FacadePhraseIndex * phrase_index,
130                                       const char * string);
131
132 /**
133  * taglib_token_to_string:
134  * @phrase_index: the phrase index for phrase string lookup.
135  * @token: the phrase token.
136  * @returns: the phrase string found in phrase index.
137  *
138  * Translate one token into the phrase string.
139  *
140  */
141 char * taglib_token_to_string(FacadePhraseIndex * phrase_index,
142                               phrase_token_t token);
143
144 /* Note: the following function is only available when the optional tag exists.
145  * bool taglib_report_status(int line_type);
146  */
147
148 /* Note: taglib_write is omited, as printf is more suitable for this. */
149
150 };
151
152 #endif