OSDN Git Service

Initial commit of senna-1.1.2-fast.
[ludiafuncs/senna-1.1.2-fast.git] / lib / snip.h
1 /* Copyright(C) 2004-2005 Brazil
2
3 This library is free software; you can redistribute it and/or
4 modify it under the terms of the GNU Lesser General Public
5 License as published by the Free Software Foundation; either
6 version 2.1 of the License, or (at your option) any later version.
7
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 Lesser General Public License for more details.
12
13 You should have received a copy of the GNU Lesser General Public
14 License along with this library; if not, write to the Free Software
15 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16 */
17 #ifndef SEN_SNIP_H
18 #define SEN_SNIP_H
19
20 #ifndef SENNA_H
21 #include "senna_in.h"
22 #endif /* SENNA_H */
23
24 #ifndef SEN_STR_H
25 #include "str.h"
26 #endif /* SEN_STR_H */
27
28 #define ASIZE                   256U
29 #define MAX_SNIP_TAG_COUNT      512U
30 #define MAX_SNIP_COND_COUNT     32U
31 #define MAX_SNIP_RESULT_COUNT   16U
32
33 #ifdef  __cplusplus
34 extern "C"
35 {
36 #endif
37
38 #define SNIPCOND_NONSTOP 0
39 #define SNIPCOND_STOP    1
40 #define SNIPCOND_ACROSS  2
41
42 #define SEN_QUERY_SCAN_ALLOCCONDS 0x0002
43
44 typedef struct _snip_cond
45 {
46   /* initial parameters */
47   const char *opentag;
48   const char *closetag;
49   size_t opentag_len;
50   size_t closetag_len;
51   sen_nstr *keyword;
52
53   /* Tuned BM pre */
54   size_t bmBc[ASIZE];
55   size_t shift;
56
57   /* Tuned BM temporal result */
58   size_t found;
59   size_t last_found;
60   size_t start_offset;
61   size_t end_offset;
62   size_t found_alpha_head;
63
64   /* search result */
65   int count;
66
67   /* stop flag */
68   int_least8_t stopflag;
69 } snip_cond;
70
71 typedef struct
72 {
73   size_t start_offset;
74   size_t end_offset;
75   snip_cond *cond;
76 } _snip_tag_result;
77
78 typedef struct
79 {
80   size_t start_offset;
81   size_t end_offset;
82   unsigned int first_tag_result_idx;
83   unsigned int last_tag_result_idx;
84   unsigned int tag_count;
85 } _snip_result;
86
87 struct _sen_snip
88 {
89   sen_encoding encoding;
90   int flags;
91   size_t width;
92   unsigned int max_results;
93   const char *defaultopentag;
94   const char *defaultclosetag;
95   size_t defaultopentag_len;
96   size_t defaultclosetag_len;
97
98   sen_snip_mapping *mapping;
99
100   snip_cond cond[MAX_SNIP_COND_COUNT];
101   unsigned int cond_len;
102
103   unsigned int tag_count;
104   unsigned int snip_count;
105
106   const char *string;
107   sen_nstr *nstr;
108
109   _snip_result snip_result[MAX_SNIP_RESULT_COUNT];
110   _snip_tag_result tag_result[MAX_SNIP_TAG_COUNT];
111
112   size_t max_tagged_len;
113 };
114
115 sen_rc sen_snip_cond_init(snip_cond *sc, const char *keyword, unsigned int keyword_len,
116                        sen_encoding enc, int flags);
117 void sen_snip_cond_reinit(snip_cond *cond);
118 sen_rc sen_snip_cond_close(snip_cond *cond);
119 void sen_bm_tunedbm(snip_cond *cond, sen_nstr *object, int flags);
120
121 #ifdef __cplusplus
122 }
123 #endif
124
125 #endif /* SEN_SNIP_H */