ze-filter  (ze-filter-0.8.0-develop-180218)
ze-lr-funcs.h
Go to the documentation of this file.
1 /*
2  *
3  * ze-filter - Mail Server Filter for sendmail
4  *
5  * Copyright (c) 2001-2018 - Jose-Marcio Martins da Cruz
6  *
7  * Auteur : Jose Marcio Martins da Cruz
8  * jose.marcio.mc@gmail.org
9  *
10  * Historique :
11  * Creation : Thu May 28 17:51:54 CEST 2009
12  *
13  * This program is free software, but with restricted license :
14  *
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19  *
20  * More details about ze-filter license can be found at ze-filter
21  * web site : http://foss.jose-marcio.org
22  */
23 
24 
25 #ifndef __ZE_LR_FUNCS_H
26 
32 #define LR_CLASS_UNKNOWN -1
33 #define LR_CLASS_HAM 0
34 #define LR_CLASS_SPAM 1
35 
36 #define LR_CMD_CLASS 0
37 #define LR_CMD_LEARN 1
38 #define LR_CMD_LEARN_RESAMPLE 2
39 #define LR_CMD_LEARN_FEEDBACK 3
40 #define LR_CMD_EXTRACT 4
41 
42 
43 #define LR_TASK_CLASSIFY 1
44 #define LR_TASK_LEARN 2
45 #define LR_TASK_EXTRACT 4
46 
47 typedef struct
48 {
49  /* learn only */
50  double lrate;
51 
52  /* resample */
53  bool resample;
54 
55  /* learn or classify */
56  bool useRawMsg;
57  size_t rawLength;
58 
59  size_t bodyLength;
60  bool useBody;
61  bool useHeaders;
62 
65 
66  int tok_type; /* token type */
67  int tok_len; /* token len */
68 
69  /* active learning */
71  double active_margin;
72 } lr_opts_T;
73 
74 #define LR_OPTS_INITIALIZER \
75  { \
76  0.004, FALSE, \
77  FALSE, 2500, 256, TRUE, TRUE, TRUE, TRUE, \
78  0, 4, \
79  FALSE, 0.25 \
80  }
81 
82 typedef struct
83 {
84  char *args;
85 
86  int nmsg;
87  int nbml; /* # of messages learnt */
88  int nbmc; /* # of messages classified */
89 
90  /* number of messages learnt per class */
91  long nSpam;
92  long nHam;
93 
94  /* number of features */
95  long nFeatures;
96 
97 #if 1
98  /* miss probability */
99  double pmiss; /* feedback missing probability */
100 #endif
101 } lr_cargs_T;
102 
103 typedef struct
104 {
105  int cmd;
106  char *args;
107  int class;
108  /* */
109  bool resample;
110  /* */
111  bool learnt; /* this message was learnt */
112  bool query; /* this message was queried */
113 #if 1
114  bool miss; /* feedback missed */
115 #endif
116  test_score_T score; /* message score record */
117 } lr_margs_T;
118 
119 
120 #if 0
121 typedef struct
122 {
123  uint32_t signature;
124  char *fname;
125  bool ok;
126 } lrh_T;
127 
128 #define LRH_INITIALIZER {SIGNATURE, NULL, FALSE}
129 #endif
130 
131 bool lr_data_open(char *fname);
132 bool lr_data_reopen();
133 bool lr_data_close();
134 bool lr_data_dump(char *fname);
135 
136 
137 bool lr_classify(char *id, char *fname,
138  lr_cargs_T * cargs, lr_margs_T * margs,
139  test_score_T * score);
140 
141 bool lr_learn(char *id, char *fname,
142  lr_cargs_T * cargs, lr_margs_T * margs,
143  test_score_T * score, bool spam);
144 
145 bool lr_extract(char *id, char *fname,
146  lr_cargs_T * cargs, lr_margs_T * margs);
147 
148 bool lr_learn_options(bool active, double threshold);
149 
150 bool lr_set_options(lr_opts_T * opts);
151 bool lr_get_options(lr_opts_T * opts);
152 void lr_print_options(lr_opts_T * opts);
153 
154 
155 typedef double (*lr_callback_F) (int, lr_cargs_T *, lr_margs_T *);
157 
160 # define __ZE_LR_FUNCS_H 1
161 #endif /* __ZE_LR_FUNCS_H */
double(* lr_callback_F)(int, lr_cargs_T *, lr_margs_T *)
Definition: ze-lr-funcs.h:155
long nFeatures
Definition: ze-lr-funcs.h:95
bool lr_data_open(char *fname)
Definition: ze-lr-funcs.c:247
bool lr_data_dump(char *fname)
Definition: ze-lr-funcs.c:435
double pmiss
Definition: ze-lr-funcs.h:99
bool lr_data_close()
Definition: ze-lr-funcs.c:350
bool lr_set_learn_callback(lr_callback_F)
Definition: ze-lr-funcs.c:1074
bool cleanUpHeaders
Definition: ze-lr-funcs.h:63
bool ok
Definition: ze-connopen.c:59
bool lr_learn_options(bool active, double threshold)
Definition: ze-lr-funcs.c:997
bool lr_get_options(lr_opts_T *opts)
Definition: ze-lr-funcs.c:1027
bool lr_classify(char *id, char *fname, lr_cargs_T *cargs, lr_margs_T *margs, test_score_T *score)
Definition: ze-lr-funcs.c:965
bool lr_set_options(lr_opts_T *opts)
Definition: ze-lr-funcs.c:1012
size_t rawLength
Definition: ze-lr-funcs.h:57
char * args
Definition: ze-lr-funcs.h:84
int tok_type
Definition: ze-lr-funcs.h:66
bool useHeaders
Definition: ze-lr-funcs.h:61
void lr_print_options(lr_opts_T *opts)
Definition: ze-lr-funcs.c:1042
bool useRawMsg
Definition: ze-lr-funcs.h:56
bool lr_learn(char *id, char *fname, lr_cargs_T *cargs, lr_margs_T *margs, test_score_T *score, bool spam)
Definition: ze-lr-funcs.c:980
char * args
Definition: ze-lr-funcs.h:106
size_t bodyLength
Definition: ze-lr-funcs.h:59
int tok_len
Definition: ze-lr-funcs.h:67
bool useBody
Definition: ze-lr-funcs.h:60
bool lr_data_reopen()
test_score_T score
Definition: ze-lr-funcs.h:116
long nSpam
Definition: ze-lr-funcs.h:91
double lrate
Definition: ze-lr-funcs.h:50
double active_margin
Definition: ze-lr-funcs.h:71
bool cleanUpDates
Definition: ze-lr-funcs.h:64
bool lr_extract(char *id, char *fname, lr_cargs_T *cargs, lr_margs_T *margs)
Definition: ze-lr-funcs.c:951
bool active_learning
Definition: ze-lr-funcs.h:70
long uint32_t
Definition: ze-sys.h:489
bool resample
Definition: ze-lr-funcs.h:109
bool resample
Definition: ze-lr-funcs.h:53