2
Copyright (c) 1993-2008, Cognitive Technologies
5
����������� ��������� ��������������� � ������������� ��� � ���� ��������� ����,
6
��� � � �������� �����, � ����������� ��� ���, ��� ���������� ��������� �������:
8
* ��� ��������� ��������������� ��������� ���� ������ ���������� ���������
9
���� ����������� �� ��������� �����, ���� ������ ������� � �����������
11
* ��� ��������� ��������������� ��������� ���� � ������������ �/��� �
12
������ ����������, ������������ ��� ���������������, ������ �����������
13
��������� ���� ���������� �� ��������� �����, ���� ������ ������� �
14
����������� ����� �� ��������.
15
* �� �������� Cognitive Technologies, �� ����� �� ����������� �� �����
16
���� ������������ � �������� �������� ��������� �/��� �����������
17
���������, ���������� �� ���� ��, ��� ���������������� �����������
20
��� ��������� ������������� ����������� ��������� ���� �/��� ������� ������ "���
21
��� ����" ��� ������-���� ���� ��������, ���������� ���� ��� ���������������,
22
������� �������� ������������ �������� � ����������� ��� ���������� ����, �� ��
23
������������� ���. �� �������� ��������� ���� � �� ���� ������ ����, �������
24
����� �������� �/��� �������� �������������� ���������, �� � ���� ������ ��
25
��Ѩ� ���������������, ������� ����� �����, ���������, ����������� ���
26
������������� ������, ��������� � �������������� ��� ���������� ����������
27
������������� ������������� ��������� (������� ������ ������, ��� ������,
28
������� ���������, ��� ������ �/��� ������ �������, ���������� ��-�� ��������
29
������� ��� �/��� ������ ��������� �������� ��������� � ������� �����������,
30
�� �� ������������� ����� ��������), �� �� ������������� ���, ���� ���� �����
31
�������� ��� ������ ���� ���� �������� � ����������� ����� ������� � ������.
33
Redistribution and use in source and binary forms, with or without modification,
34
are permitted provided that the following conditions are met:
36
* Redistributions of source code must retain the above copyright notice,
37
this list of conditions and the following disclaimer.
38
* Redistributions in binary form must reproduce the above copyright notice,
39
this list of conditions and the following disclaimer in the documentation
40
and/or other materials provided with the distribution.
41
* Neither the name of the Cognitive Technologies nor the names of its
42
contributors may be used to endorse or promote products derived from this
43
software without specific prior written permission.
45
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
46
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
47
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
48
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
49
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
50
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
51
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
52
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
53
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
54
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2
Copyright (c) 1993-2008, Cognitive Technologies
5
Разрешается повторное распространение и использование как в виде исходного кода,
6
так и в двоичной форме, с изменениями или без, при соблюдении следующих условий:
8
* При повторном распространении исходного кода должны оставаться указанное
9
выше уведомление об авторском праве, этот список условий и последующий
11
* При повторном распространении двоичного кода в документации и/или в
12
других материалах, поставляемых при распространении, должны сохраняться
13
указанная выше информация об авторском праве, этот список условий и
14
последующий отказ от гарантий.
15
* Ни название Cognitive Technologies, ни имена ее сотрудников не могут
16
быть использованы в качестве средства поддержки и/или продвижения
17
продуктов, основанных на этом ПО, без предварительного письменного
20
ЭТА ПРОГРАММА ПРЕДОСТАВЛЕНА ВЛАДЕЛЬЦАМИ АВТОРСКИХ ПРАВ И/ИЛИ ДРУГИМИ ЛИЦАМИ "КАК
21
ОНА ЕСТЬ" БЕЗ КАКОГО-ЛИБО ВИДА ГАРАНТИЙ, ВЫРАЖЕННЫХ ЯВНО ИЛИ ПОДРАЗУМЕВАЕМЫХ,
22
ВКЛЮЧАЯ ГАРАНТИИ КОММЕРЧЕСКОЙ ЦЕННОСТИ И ПРИГОДНОСТИ ДЛЯ КОНКРЕТНОЙ ЦЕЛИ, НО НЕ
23
ОГРАНИЧИВАЯСЬ ИМИ. НИ ВЛАДЕЛЕЦ АВТОРСКИХ ПРАВ И НИ ОДНО ДРУГОЕ ЛИЦО, КОТОРОЕ
24
МОЖЕТ ИЗМЕНЯТЬ И/ИЛИ ПОВТОРНО РАСПРОСТРАНЯТЬ ПРОГРАММУ, НИ В КОЕМ СЛУЧАЕ НЕ
25
НЕСЁТ ОТВЕТСТВЕННОСТИ, ВКЛЮЧАЯ ЛЮБЫЕ ОБЩИЕ, СЛУЧАЙНЫЕ, СПЕЦИАЛЬНЫЕ ИЛИ
26
ПОСЛЕДОВАВШИЕ УБЫТКИ, СВЯЗАННЫЕ С ИСПОЛЬЗОВАНИЕМ ИЛИ ПОНЕСЕННЫЕ ВСЛЕДСТВИЕ
27
НЕВОЗМОЖНОСТИ ИСПОЛЬЗОВАНИЯ ПРОГРАММЫ (ВКЛЮЧАЯ ПОТЕРИ ДАННЫХ, ИЛИ ДАННЫЕ,
28
СТАВШИЕ НЕГОДНЫМИ, ИЛИ УБЫТКИ И/ИЛИ ПОТЕРИ ДОХОДОВ, ПОНЕСЕННЫЕ ИЗ-ЗА ДЕЙСТВИЙ
29
ТРЕТЬИХ ЛИЦ И/ИЛИ ОТКАЗА ПРОГРАММЫ РАБОТАТЬ СОВМЕСТНО С ДРУГИМИ ПРОГРАММАМИ,
30
НО НЕ ОГРАНИЧИВАЯСЬ ЭТИМИ СЛУЧАЯМИ), НО НЕ ОГРАНИЧИВАЯСЬ ИМИ, ДАЖЕ ЕСЛИ ТАКОЙ
31
ВЛАДЕЛЕЦ ИЛИ ДРУГОЕ ЛИЦО БЫЛИ ИЗВЕЩЕНЫ О ВОЗМОЖНОСТИ ТАКИХ УБЫТКОВ И ПОТЕРЬ.
33
Redistribution and use in source and binary forms, with or without modification,
34
are permitted provided that the following conditions are met:
36
* Redistributions of source code must retain the above copyright notice,
37
this list of conditions and the following disclaimer.
38
* Redistributions in binary form must reproduce the above copyright notice,
39
this list of conditions and the following disclaimer in the documentation
40
and/or other materials provided with the distribution.
41
* Neither the name of the Cognitive Technologies nor the names of its
42
contributors may be used to endorse or promote products derived from this
43
software without specific prior written permission.
45
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
46
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
47
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
48
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
49
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
50
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
51
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
52
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
53
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
54
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
58
57
#include <stdlib.h>
60
59
#include <string.h>
62
60
#include "struct.h"
104
97
#define AFTERAPOSTROPHE 0x20
105
98
#define COMPLEX 0x40
106
99
#define AFTERDOTCOM 0x80
108
100
#define BAD_SYM 1
109
101
#define ALPHANUM 2
110
102
#define SPEC_SYM 4
111
103
#define DOT_SPACE 8
112
104
#define SPEC_SYM_SLASH 0x10
114
105
#define NOT_EXPECT_DELIM 0x80
115
106
#define DELIM_WORD_IS_POSSIBLE 0x01
116
107
#define DELIM_DIG_IS_POSSIBLE 0x02
117
108
#define DELIM_REGULAR 0x04
118
109
#define REAL_WORD_DELIM 0x10
119
110
#define REAL_DIG_DELIM 0x20
121
111
#define BONUS 16 // bonus for probability
122
112
#define MONUS 50 // antibonus for probability
123
113
#define MONUS1I 20 // antibonus for 1-i-l case
124
114
#define BONUS01 6 // bonus for 0 and 1 for neigboring digits
125
115
#define BONUS_SLASH 30 // bonus or monus for SLASH being between
128
117
#define MAX_VERS 8 // maximal number of alternatives
129
118
#define MAX_PROB 254 // maximal probability of letter
130
119
#define MIN_PROB 2 // minimal probability of letter
131
120
#define MAX_SYMB 80 // maximal admissible number of
133
122
#define MAX_NUM_WORDS (MAX_SYMB/2) // maximum admissible number of
136
124
#undef COMPLEX_PROT /* Complex_word Protocol Flag */
138
125
#define COMP_NVAR 3 // Number of variants in Complex_word
140
126
/***** Complex_word --> Types of conserning symbols: *****/
142
128
#define L_SMALL 1
144
130
#define L_UNDEF 3
145
131
#define L_EMPTY 4
147
132
/******* Complex_word --> Penalties types: ************/
148
133
#define JMP 35 // Jump penalty (was 25)
149
134
#define JMP_SN 8 // Additional jump penalty
150
// from small to numeric
135
// from small to numeric
151
136
#define ADD_JMP_SN 12 // One more additional jump penalty from small
152
// to numeric, if small is single version
137
// to numeric, if small is single version
153
138
#define NUM_INC 5 // Increase numeric power (was 10)
154
139
#define SMALL_INC 3 // Increase small power
156
140
/****** Context Penalties: **********/
157
141
#define REFUSE_BOUND 66 // Refuse boundary for version selection
159
142
#define ADM_PROB 120
160
143
#define CONS_VOWEL_JMP 50 // penalty for conson. letter after 'l' and
161
// for vowel letter after 'I'
144
// for vowel letter after 'I'
162
145
#define TITLE_JMP 25 // after dot small letter penalty
164
146
#define BON_DIG_CHAR 50
166
147
#define FRANCH_ART_BONUS 30
167
148
#define GER_DOUBLE_S_MONUS 40
168
149
#define SWED_LJU_BONUS 50
172
153
#define LOWER_A 'a'
173
154
#define LOWER_C 'c'
174
155
#define AFTER_C 1
176
156
/****** Numeral object Processing Variants *********/
177
157
#define VAR_1st 1
178
158
#define VAR_2nd 2
179
159
#define VAR_3rd 4
180
160
#define VAR_09th 8
182
161
#define CONTINUE_ACTION 0
183
162
#define NO_ACTION 1
185
163
/***** Common variables and functions **********/
186
CONT_EXTERN BYTE word_flag;
187
CONT_EXTERN INT n_ltr; // number of letters in word
188
CONT_EXTERN INT total_words;
189
CONT_EXTERN INT roman_sym_num;
190
CONT_EXTERN BYTE swed_lju_flag;
191
CONT_EXTERN BYTE fl_beg_irish_name;
164
CONT_EXTERN uchar word_flag;
165
CONT_EXTERN int16_t n_ltr; // number of letters in word
166
CONT_EXTERN int16_t total_words;
167
CONT_EXTERN int16_t roman_sym_num;
168
CONT_EXTERN uchar swed_lju_flag;
169
CONT_EXTERN uchar fl_beg_irish_name;
193
void vers_to_first_place ( cell *A, INT nver);
194
INT get_nvers ( cell *A, INT Let );
195
INT check_numb_2_9 (BYTE);
196
INT check_numb_0_9 (BYTE);
197
INT check_upper (BYTE);
198
INT check_lower (BYTE);
199
INT check_alphanum (BYTE);
200
INT check_lowerconson(BYTE);
171
void vers_to_first_place(cell *A, int16_t nver);
172
int16_t get_nvers(cell *A, int16_t Let);
173
int16_t check_numb_2_9(uchar);
174
int16_t check_numb_0_9(uchar);
175
int16_t check_upper(uchar);
176
int16_t check_lower(uchar);
177
int16_t check_alphanum(uchar);
178
int16_t check_lowerconson(uchar);
201
179
void test_O_and_slash();
202
INT english_context_process ( cell* C );
203
INT franch_context_process ( cell* C );
204
INT german_context_process ( cell* C );
205
INT swedish_context_process ( cell* C );
206
INT spanish_context_process ( cell* C );
207
void test_roma_num_sym ( cell *C );
208
void test_irish_name_cur_sym ( INT Let );
180
int16_t english_context_process(cell* C);
181
int16_t franch_context_process(cell* C);
182
int16_t german_context_process(cell* C);
183
int16_t swedish_context_process(cell* C);
184
int16_t spanish_context_process(cell* C);
185
void test_roma_num_sym(cell *C);
186
void test_irish_name_cur_sym(int16_t Let);
209
187
/*========================================================*/
211
189
#ifdef MAIN_CONTEXT_MODULE
212
static INT find_dig_chr_var ();
213
static void make_dig_chr_chain ();
214
static void up_substr ( PCHAR substr );
215
static void up_rest_str ();
216
static INT get_est_substr_in_word ( PCHAR );
217
static INT est_rest_dig ( dv *);
218
static INT test_var ( PCHAR );
190
static int16_t find_dig_chr_var ();
191
static void make_dig_chr_chain ();
192
static void up_substr ( pchar substr );
193
static void up_rest_str ();
194
static int16_t get_est_substr_in_word ( pchar );
195
static int16_t est_rest_dig ( dv *);
196
static int16_t test_var ( pchar );
219
197
/*****************/
220
198
static dv * cdv, *last_dv, *last_dig_dv, *beg_dv;
221
static INT best_l, num_v, admvar = 0, maxest;
222
INT delim_flag, possible_delim_flag;
199
static int16_t best_l, num_v, admvar = 0, maxest;
200
int16_t delim_flag, possible_delim_flag;
223
201
/***********************************************************************/
225
cell *WB; // first cell in word
226
cell *EB; // last cell in word
227
BYTE after_word_flag;
228
BYTE fl_cap_first; // first letter has capital version flag
229
INT num_dig, num_upper, num_lower, num_bad, num_let;
203
cell *WB; // first cell in word
204
cell *EB; // last cell in word
205
uchar after_word_flag;
206
uchar fl_cap_first; // first letter has capital version flag
207
int16_t num_dig, num_upper, num_lower, num_bad, num_let;
208
uchar irish_name_pos;
231
209
static pCell use_word_flags[MAX_NUM_WORDS];
232
210
static pCell pDotComCell;
235
static INT find_and_class_word (cell *);
236
static BYTE classify (cell *);
237
static BOOL find_delim ( INT );
238
static void set_after_word_flag ( INT );
239
static void set_word_flag ( INT );
240
static void check_vers (cell *);
241
static void set_word_type ();
242
static BOOL real_delim ();
243
static void Livers (cell *);
244
static BOOL Lbs_word ();
245
static void cut_lower_ver (cell *);
246
static BOOL roma_num (void);
247
static BOOL is_roma_num (void);
248
static void make_roma_num (void);
249
static INT best_estimation (void);
250
static void estimate_chain (INT);
251
static void estimate_letter (cell *, INT);
252
static INT class_of_letter (CHAR);
253
static void setup_complex (void);
254
static INT make_best_choice (INT);
212
static int16_t find_and_class_word (cell *);
213
static uchar classify (cell *);
214
static Bool find_delim ( int16_t );
215
static void set_after_word_flag ( int16_t );
216
static void set_word_flag ( int16_t );
217
static void check_vers (cell *);
218
static void set_word_type ();
219
static Bool real_delim ();
220
static void Livers (cell *);
221
static Bool Lbs_word ();
222
static void cut_lower_ver (cell *);
223
static Bool roma_num (void);
224
static Bool is_roma_num (void);
225
static void make_roma_num (void);
226
static int16_t best_estimation (void);
227
static void estimate_chain (int16_t);
228
static void estimate_letter (cell *, int16_t);
229
static int16_t class_of_letter (char);
230
static void setup_complex (void);
231
static int16_t make_best_choice (int16_t);
255
232
/*******************
256
static INT is_cons_jmp ( dv *prv, dv *crn );
257
static INT is_vowel_jmp ( dv *prv, dv *crn );
258
********************/
233
static int16_t is_cons_jmp ( dv *prv, dv *crn );
234
static int16_t is_vowel_jmp ( dv *prv, dv *crn );
235
********************/