chaine 3.13.1__cp311-cp311-musllinux_1_2_i686.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of chaine might be problematic. Click here for more details.

Files changed (70) hide show
  1. chaine/__init__.py +2 -0
  2. chaine/_core/crf.cpp +19854 -0
  3. chaine/_core/crf.cpython-311-i386-linux-musl.so +0 -0
  4. chaine/_core/crf.pyx +271 -0
  5. chaine/_core/crfsuite/COPYING +27 -0
  6. chaine/_core/crfsuite/README +183 -0
  7. chaine/_core/crfsuite/include/crfsuite.h +1077 -0
  8. chaine/_core/crfsuite/include/crfsuite.hpp +649 -0
  9. chaine/_core/crfsuite/include/crfsuite_api.hpp +406 -0
  10. chaine/_core/crfsuite/include/os.h +65 -0
  11. chaine/_core/crfsuite/lib/cqdb/COPYING +28 -0
  12. chaine/_core/crfsuite/lib/cqdb/include/cqdb.h +518 -0
  13. chaine/_core/crfsuite/lib/cqdb/src/cqdb.c +639 -0
  14. chaine/_core/crfsuite/lib/cqdb/src/lookup3.c +1271 -0
  15. chaine/_core/crfsuite/lib/cqdb/src/main.c +184 -0
  16. chaine/_core/crfsuite/lib/crf/src/crf1d.h +354 -0
  17. chaine/_core/crfsuite/lib/crf/src/crf1d_context.c +788 -0
  18. chaine/_core/crfsuite/lib/crf/src/crf1d_encode.c +1020 -0
  19. chaine/_core/crfsuite/lib/crf/src/crf1d_feature.c +382 -0
  20. chaine/_core/crfsuite/lib/crf/src/crf1d_model.c +1085 -0
  21. chaine/_core/crfsuite/lib/crf/src/crf1d_tag.c +582 -0
  22. chaine/_core/crfsuite/lib/crf/src/crfsuite.c +500 -0
  23. chaine/_core/crfsuite/lib/crf/src/crfsuite_internal.h +233 -0
  24. chaine/_core/crfsuite/lib/crf/src/crfsuite_train.c +302 -0
  25. chaine/_core/crfsuite/lib/crf/src/dataset.c +115 -0
  26. chaine/_core/crfsuite/lib/crf/src/dictionary.c +127 -0
  27. chaine/_core/crfsuite/lib/crf/src/holdout.c +83 -0
  28. chaine/_core/crfsuite/lib/crf/src/json.c +1497 -0
  29. chaine/_core/crfsuite/lib/crf/src/json.h +120 -0
  30. chaine/_core/crfsuite/lib/crf/src/logging.c +85 -0
  31. chaine/_core/crfsuite/lib/crf/src/logging.h +49 -0
  32. chaine/_core/crfsuite/lib/crf/src/params.c +370 -0
  33. chaine/_core/crfsuite/lib/crf/src/params.h +84 -0
  34. chaine/_core/crfsuite/lib/crf/src/quark.c +180 -0
  35. chaine/_core/crfsuite/lib/crf/src/quark.h +46 -0
  36. chaine/_core/crfsuite/lib/crf/src/rumavl.c +1178 -0
  37. chaine/_core/crfsuite/lib/crf/src/rumavl.h +144 -0
  38. chaine/_core/crfsuite/lib/crf/src/train_arow.c +409 -0
  39. chaine/_core/crfsuite/lib/crf/src/train_averaged_perceptron.c +237 -0
  40. chaine/_core/crfsuite/lib/crf/src/train_l2sgd.c +491 -0
  41. chaine/_core/crfsuite/lib/crf/src/train_lbfgs.c +323 -0
  42. chaine/_core/crfsuite/lib/crf/src/train_passive_aggressive.c +442 -0
  43. chaine/_core/crfsuite/lib/crf/src/vecmath.h +360 -0
  44. chaine/_core/crfsuite/swig/crfsuite.cpp +1 -0
  45. chaine/_core/crfsuite_api.pxd +67 -0
  46. chaine/_core/liblbfgs/COPYING +22 -0
  47. chaine/_core/liblbfgs/README +71 -0
  48. chaine/_core/liblbfgs/include/lbfgs.h +745 -0
  49. chaine/_core/liblbfgs/lib/arithmetic_ansi.h +142 -0
  50. chaine/_core/liblbfgs/lib/arithmetic_sse_double.h +303 -0
  51. chaine/_core/liblbfgs/lib/arithmetic_sse_float.h +312 -0
  52. chaine/_core/liblbfgs/lib/lbfgs.c +1531 -0
  53. chaine/_core/tagger_wrapper.hpp +58 -0
  54. chaine/_core/trainer_wrapper.cpp +32 -0
  55. chaine/_core/trainer_wrapper.hpp +26 -0
  56. chaine/crf.py +505 -0
  57. chaine/logging.py +214 -0
  58. chaine/optimization/__init__.py +10 -0
  59. chaine/optimization/metrics.py +129 -0
  60. chaine/optimization/spaces.py +394 -0
  61. chaine/optimization/trial.py +103 -0
  62. chaine/optimization/utils.py +119 -0
  63. chaine/training.py +184 -0
  64. chaine/typing.py +18 -0
  65. chaine/validation.py +43 -0
  66. chaine-3.13.1.dist-info/METADATA +348 -0
  67. chaine-3.13.1.dist-info/RECORD +70 -0
  68. chaine-3.13.1.dist-info/WHEEL +4 -0
  69. chaine.libs/libgcc_s-1257a076.so.1 +0 -0
  70. chaine.libs/libstdc++-0530927c.so.6.0.32 +0 -0
@@ -0,0 +1,184 @@
1
+ /*
2
+ * Test program for Constant Quark Database (CQDB).
3
+ *
4
+ * Copyright (c) 2007, Naoaki Okazaki
5
+ * All rights reserved.
6
+ *
7
+ * Redistribution and use in source and binary forms, with or without
8
+ * modification, are permitted provided that the following conditions are met:
9
+ * * Redistributions of source code must retain the above copyright
10
+ * notice, this list of conditions and the following disclaimer.
11
+ * * 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
+ * * Neither the name of the Northwestern University, University of Tokyo,
15
+ * nor the names of its contributors may be used to endorse or promote
16
+ * products derived from this software without specific prior written
17
+ * permission.
18
+ *
19
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
23
+ * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
+ */
31
+
32
+ /* $Id$ */
33
+
34
+ #include <stdio.h>
35
+ #include <stdlib.h>
36
+ #include <string.h>
37
+ #include "cqdb.h"
38
+
39
+ //#define TEST_WRITE 1
40
+ #define CHECK_VALIDITY
41
+
42
+ #define DBNAME "test.cqdb"
43
+ #define NUMELEMS 1000000
44
+
45
+ #ifdef TEST_WRITE
46
+
47
+ int main(int argc, char *argv[])
48
+ {
49
+ int i, ret;
50
+ char str[10];
51
+ FILE *fp = NULL;
52
+ cqdb_writer_t *dbw = NULL;
53
+
54
+ // Open a file for writing.
55
+ fp = fopen(DBNAME, "wb");
56
+ if (fp == NULL)
57
+ {
58
+ fprintf(stderr, "ERROR: failed to open the file.\n");
59
+ return 1;
60
+ }
61
+
62
+ // Create a CQDB on the file stream.
63
+ dbw = cqdb_writer(fp, 0);
64
+ if (dbw == NULL)
65
+ {
66
+ fprintf(stderr, "ERROR: failed to create a CQDB on the file.\n");
67
+ goto error_exit;
68
+ }
69
+
70
+ // Put string/integer associations, "00000001"/1, ..., "01000000"/1000000.
71
+ for (i = 0; i < NUMELEMS; ++i)
72
+ {
73
+ sprintf(str, "%08d", i);
74
+ if (ret = cqdb_writer_put(dbw, str, i))
75
+ {
76
+ fprintf(stderr, "ERROR: failed to put a pair '%s'/%d.\n", str, i);
77
+ goto error_exit;
78
+ }
79
+ }
80
+
81
+ // Close the CQDB.
82
+ if (ret = cqdb_writer_close(dbw))
83
+ {
84
+ fprintf(stderr, "ERROR: failed to close the CQDB.\n");
85
+ goto error_exit;
86
+ }
87
+
88
+ // Close the file.
89
+ fclose(fp);
90
+ return 0;
91
+
92
+ error_exit:
93
+ if (dbw != NULL)
94
+ cqdb_writer_close(dbw);
95
+ if (fp != NULL)
96
+ fclose(fp);
97
+ return 1;
98
+ }
99
+
100
+ #else /*TEST_WRITE*/
101
+
102
+ int main(int argc, char *argv[])
103
+ {
104
+ int i, j, ret;
105
+ long size = 0;
106
+ const char *value = NULL;
107
+ char str[10], *buffer = NULL;
108
+ FILE *fp = NULL;
109
+ cqdb_t *db = NULL;
110
+
111
+ // Open the database.
112
+ fp = fopen(DBNAME, "rb");
113
+ if (fp == NULL)
114
+ {
115
+ fprintf(stderr, "ERROR: failed to open the file\n");
116
+ return 1;
117
+ }
118
+
119
+ // Obtain the file size at one time.
120
+ fseek(fp, 0, SEEK_END);
121
+ size = ftell(fp);
122
+ fseek(fp, 0, SEEK_SET);
123
+
124
+ // Read the content of the file.
125
+ buffer = (char *)malloc(size);
126
+ if (buffer == NULL)
127
+ {
128
+ fprintf(stderr, "ERROR: out of memory.\n");
129
+ goto error_exit;
130
+ }
131
+ fread(buffer, 1, size, fp);
132
+ fclose(fp);
133
+ fp = NULL;
134
+
135
+ // Open the database on the memory.
136
+ db = cqdb_reader(buffer, size);
137
+ if (db == NULL)
138
+ {
139
+ fprintf(stderr, "ERROR: failed to open a CQDB on the file.\n");
140
+ goto error_exit;
141
+ }
142
+
143
+ // Forward lookups: strings to integer identifiers.
144
+ for (i = 0; i < NUMELEMS; ++i)
145
+ {
146
+ sprintf(str, "%08d", i);
147
+ j = cqdb_to_id(db, str);
148
+ #ifdef CHECK_VALIDITY
149
+ if (i != j)
150
+ {
151
+ fprintf(stderr, "ERROR: inconsistency error '%s'/%d.\n", str, i);
152
+ goto error_exit;
153
+ }
154
+ #endif /*CHECK_VALIDITY*/
155
+ }
156
+
157
+ // Backward lookups: integer identifiers to strings.
158
+ for (i = 0; i < NUMELEMS; ++i)
159
+ {
160
+ sprintf(str, "%08d", i);
161
+ value = cqdb_to_string(db, i);
162
+ #ifdef CHECK_VALIDITY
163
+ if (strcmp(str, value) != 0)
164
+ {
165
+ fprintf(stderr, "ERROR: inconsistency error '%s'/%d.\n", str, i);
166
+ goto error_exit;
167
+ }
168
+ #endif /*CHECK_VALIDITY*/
169
+ }
170
+
171
+ cqdb_delete(db);
172
+ free(buffer);
173
+
174
+ return 0;
175
+
176
+ error_exit:
177
+ if (fp != NULL)
178
+ fclose(fp);
179
+ if (buffer != NULL)
180
+ free(buffer);
181
+ return 1;
182
+ }
183
+
184
+ #endif /*TEST_WRITE*/
@@ -0,0 +1,354 @@
1
+ /*
2
+ * The 1st-order linear-chain CRF with dyad features (CRF1d).
3
+ *
4
+ * Copyright (c) 2007-2010, Naoaki Okazaki
5
+ * All rights reserved.
6
+ *
7
+ * Redistribution and use in source and binary forms, with or without
8
+ * modification, are permitted provided that the following conditions are met:
9
+ * * Redistributions of source code must retain the above copyright
10
+ * notice, this list of conditions and the following disclaimer.
11
+ * * 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
+ * * Neither the names of the authors nor the names of its contributors
15
+ * may be used to endorse or promote products derived from this
16
+ * software without specific prior written permission.
17
+ *
18
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
22
+ * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24
+ * 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
+
31
+ /* $Id$ */
32
+
33
+ #ifndef __CRF1D_H__
34
+ #define __CRF1D_H__
35
+
36
+ #include <crfsuite.h>
37
+ #include "crfsuite_internal.h"
38
+
39
+ /**
40
+ * \defgroup crf1d_context.c
41
+ */
42
+ /** @{ */
43
+
44
+ /**
45
+ * Functionality flags for contexts.
46
+ * @see crf1dc_new().
47
+ */
48
+ enum
49
+ {
50
+ CTXF_BASE = 0x01,
51
+ CTXF_VITERBI = 0x01,
52
+ CTXF_MARGINALS = 0x02,
53
+ CTXF_ALL = 0xFF,
54
+ };
55
+
56
+ /**
57
+ * Reset flags.
58
+ * @see crf1dc_reset().
59
+ */
60
+ enum
61
+ {
62
+ RF_STATE = 0x01, /**< Reset state scores. */
63
+ RF_TRANS = 0x02, /**< Reset transition scores. */
64
+ RF_ALL = 0xFF, /**< Reset all. */
65
+ };
66
+
67
+ /**
68
+ * Context structure.
69
+ * This structure maintains internal data for an instance.
70
+ */
71
+ typedef struct
72
+ {
73
+ /**
74
+ * Flag specifying the functionality.
75
+ */
76
+ int flag;
77
+
78
+ /**
79
+ * The total number of distinct labels (L).
80
+ */
81
+ int num_labels;
82
+
83
+ /**
84
+ * The number of items (T) in the instance.
85
+ */
86
+ int num_items;
87
+
88
+ /**
89
+ * The maximum number of labels.
90
+ */
91
+ int cap_items;
92
+
93
+ /**
94
+ * Logarithm of the normalization factor for the instance.
95
+ * This is equivalent to the total scores of all paths in the lattice.
96
+ */
97
+ floatval_t log_norm;
98
+
99
+ /**
100
+ * State scores.
101
+ * This is a [T][L] matrix whose element [t][l] presents total score
102
+ * of state features associating label #l at #t.
103
+ */
104
+ floatval_t *state;
105
+
106
+ /**
107
+ * Transition scores.
108
+ * This is a [L][L] matrix whose element [i][j] represents the total
109
+ * score of transition features associating labels #i and #j.
110
+ */
111
+ floatval_t *trans;
112
+
113
+ /**
114
+ * Alpha score matrix.
115
+ * This is a [T][L] matrix whose element [t][l] presents the total
116
+ * score of paths starting at BOS and arraiving at (t, l).
117
+ */
118
+ floatval_t *alpha_score;
119
+
120
+ /**
121
+ * Beta score matrix.
122
+ * This is a [T][L] matrix whose element [t][l] presents the total
123
+ * score of paths starting at (t, l) and arraiving at EOS.
124
+ */
125
+ floatval_t *beta_score;
126
+
127
+ /**
128
+ * Scale factor vector.
129
+ * This is a [T] vector whose element [t] presents the scaling
130
+ * coefficient for the alpha_score and beta_score.
131
+ */
132
+ floatval_t *scale_factor;
133
+
134
+ /**
135
+ * Row vector (work space).
136
+ * This is a [T] vector used internally for a work space.
137
+ */
138
+ floatval_t *row;
139
+
140
+ /**
141
+ * Backward edges.
142
+ * This is a [T][L] matrix whose element [t][j] represents the label #i
143
+ * that yields the maximum score to arrive at (t, j).
144
+ * This member is available only with CTXF_VITERBI flag enabled.
145
+ */
146
+ int *backward_edge;
147
+
148
+ /**
149
+ * Exponents of state scores.
150
+ * This is a [T][L] matrix whose element [t][l] presents the exponent
151
+ * of the total score of state features associating label #l at #t.
152
+ * This member is available only with CTXF_MARGINALS flag.
153
+ */
154
+ floatval_t *exp_state;
155
+
156
+ /**
157
+ * Exponents of transition scores.
158
+ * This is a [L][L] matrix whose element [i][j] represents the exponent
159
+ * of the total score of transition features associating labels #i and #j.
160
+ * This member is available only with CTXF_MARGINALS flag.
161
+ */
162
+ floatval_t *exp_trans;
163
+
164
+ /**
165
+ * Model expectations of states.
166
+ * This is a [T][L] matrix whose element [t][l] presents the model
167
+ * expectation (marginal probability) of the state (t,l)
168
+ * This member is available only with CTXF_MARGINALS flag.
169
+ */
170
+ floatval_t *mexp_state;
171
+
172
+ /**
173
+ * Model expectations of transitions.
174
+ * This is a [L][L] matrix whose element [i][j] presents the model
175
+ * expectation of the transition (i--j).
176
+ * This member is available only with CTXF_MARGINALS flag.
177
+ */
178
+ floatval_t *mexp_trans;
179
+
180
+ } crf1d_context_t;
181
+
182
+ #define MATRIX(p, xl, x, y) ((p)[(xl) * (y) + (x)])
183
+
184
+ #define ALPHA_SCORE(ctx, t) \
185
+ (&MATRIX(ctx->alpha_score, ctx->num_labels, 0, t))
186
+ #define BETA_SCORE(ctx, t) \
187
+ (&MATRIX(ctx->beta_score, ctx->num_labels, 0, t))
188
+ #define STATE_SCORE(ctx, i) \
189
+ (&MATRIX(ctx->state, ctx->num_labels, 0, i))
190
+ #define TRANS_SCORE(ctx, i) \
191
+ (&MATRIX(ctx->trans, ctx->num_labels, 0, i))
192
+ #define EXP_STATE_SCORE(ctx, i) \
193
+ (&MATRIX(ctx->exp_state, ctx->num_labels, 0, i))
194
+ #define EXP_TRANS_SCORE(ctx, i) \
195
+ (&MATRIX(ctx->exp_trans, ctx->num_labels, 0, i))
196
+ #define STATE_MEXP(ctx, i) \
197
+ (&MATRIX(ctx->mexp_state, ctx->num_labels, 0, i))
198
+ #define TRANS_MEXP(ctx, i) \
199
+ (&MATRIX(ctx->mexp_trans, ctx->num_labels, 0, i))
200
+ #define BACKWARD_EDGE_AT(ctx, t) \
201
+ (&MATRIX(ctx->backward_edge, ctx->num_labels, 0, t))
202
+
203
+ crf1d_context_t *crf1dc_new(int flag, int L, int T);
204
+ int crf1dc_set_num_items(crf1d_context_t *ctx, int T);
205
+ void crf1dc_delete(crf1d_context_t *ctx);
206
+ void crf1dc_reset(crf1d_context_t *ctx, int flag);
207
+ void crf1dc_exp_state(crf1d_context_t *ctx);
208
+ void crf1dc_exp_transition(crf1d_context_t *ctx);
209
+ void crf1dc_alpha_score(crf1d_context_t *ctx);
210
+ void crf1dc_beta_score(crf1d_context_t *ctx);
211
+ void crf1dc_marginals(crf1d_context_t *ctx);
212
+ floatval_t crf1dc_marginal_point(crf1d_context_t *ctx, int l, int t);
213
+ floatval_t crf1dc_marginal_path(crf1d_context_t *ctx, const int *path, int begin, int end);
214
+ floatval_t crf1dc_score(crf1d_context_t *ctx, const int *labels);
215
+ floatval_t crf1dc_lognorm(crf1d_context_t *ctx);
216
+ floatval_t crf1dc_viterbi(crf1d_context_t *ctx, int *labels);
217
+ void crf1dc_debug_context(FILE *fp);
218
+
219
+ /** @} */
220
+
221
+ /**
222
+ * \defgroup crf1d_feature.c
223
+ */
224
+ /** @{ */
225
+
226
+ /**
227
+ * Feature type.
228
+ */
229
+ enum
230
+ {
231
+ FT_STATE = 0, /**< State features. */
232
+ FT_TRANS, /**< Transition features. */
233
+ };
234
+
235
+ /**
236
+ * A feature (for either state or transition).
237
+ */
238
+ typedef struct
239
+ {
240
+ /**
241
+ * Feature type.
242
+ * Possible values are:
243
+ * - FT_STATE (0) for state features.
244
+ * - FT_TRANS (1) for transition features.
245
+ */
246
+ int type;
247
+
248
+ /**
249
+ * Source id.
250
+ * The semantic of this field depends on the feature type:
251
+ * - attribute id for state features (type == 0).
252
+ * - output label id for transition features (type != 0).
253
+ */
254
+ int src;
255
+
256
+ /**
257
+ * Destination id.
258
+ * Label id emitted by this feature.
259
+ */
260
+ int dst;
261
+
262
+ /**
263
+ * Frequency (observation expectation).
264
+ */
265
+ floatval_t freq;
266
+ } crf1df_feature_t;
267
+
268
+ /**
269
+ * Feature references.
270
+ * This is a collection of feature ids used for faster accesses.
271
+ */
272
+ typedef struct
273
+ {
274
+ int num_features; /**< Number of features referred */
275
+ int *fids; /**< Array of feature ids */
276
+ } feature_refs_t;
277
+
278
+ crf1df_feature_t *crf1df_generate(
279
+ int *ptr_num_features,
280
+ dataset_t *ds,
281
+ int num_labels,
282
+ int num_attributes,
283
+ int connect_all_attrs,
284
+ int connect_all_edges,
285
+ floatval_t minfreq,
286
+ crfsuite_logging_callback func,
287
+ void *instance);
288
+
289
+ int crf1df_init_references(
290
+ feature_refs_t **ptr_attributes,
291
+ feature_refs_t **ptr_trans,
292
+ const crf1df_feature_t *features,
293
+ const int K,
294
+ const int A,
295
+ const int L);
296
+
297
+ /** @} */
298
+
299
+ /**
300
+ * \defgroup crf1d_model.c
301
+ */
302
+ /** @{ */
303
+
304
+ struct tag_crf1dm;
305
+ typedef struct tag_crf1dm crf1dm_t;
306
+
307
+ struct tag_crf1dmw;
308
+ typedef struct tag_crf1dmw crf1dmw_t;
309
+
310
+ typedef struct
311
+ {
312
+ int type;
313
+ int src;
314
+ int dst;
315
+ floatval_t weight;
316
+ } crf1dm_feature_t;
317
+
318
+ crf1dmw_t *crf1mmw(const char *filename);
319
+ int crf1dmw_close(crf1dmw_t *writer);
320
+ int crf1dmw_open_labels(crf1dmw_t *writer, int num_labels);
321
+ int crf1dmw_close_labels(crf1dmw_t *writer);
322
+ int crf1dmw_put_label(crf1dmw_t *writer, int lid, const char *value);
323
+ int crf1dmw_open_attrs(crf1dmw_t *writer, int num_attributes);
324
+ int crf1dmw_close_attrs(crf1dmw_t *writer);
325
+ int crf1dmw_put_attr(crf1dmw_t *writer, int aid, const char *value);
326
+ int crf1dmw_open_labelrefs(crf1dmw_t *writer, int num_labels);
327
+ int crf1dmw_close_labelrefs(crf1dmw_t *writer);
328
+ int crf1dmw_put_labelref(crf1dmw_t *writer, int lid, const feature_refs_t *ref, int *map);
329
+ int crf1dmw_open_attrrefs(crf1dmw_t *writer, int num_attrs);
330
+ int crf1dmw_close_attrrefs(crf1dmw_t *writer);
331
+ int crf1dmw_put_attrref(crf1dmw_t *writer, int aid, const feature_refs_t *ref, int *map);
332
+ int crf1dmw_open_features(crf1dmw_t *writer);
333
+ int crf1dmw_close_features(crf1dmw_t *writer);
334
+ int crf1dmw_put_feature(crf1dmw_t *writer, int fid, const crf1dm_feature_t *f);
335
+
336
+ crf1dm_t *crf1dm_new(const char *filename);
337
+ crf1dm_t *crf1dm_new_from_memory(const void *data, size_t size);
338
+ void crf1dm_close(crf1dm_t *model);
339
+ int crf1dm_get_num_attrs(crf1dm_t *model);
340
+ int crf1dm_get_num_labels(crf1dm_t *model);
341
+ const char *crf1dm_to_label(crf1dm_t *model, int lid);
342
+ int crf1dm_to_lid(crf1dm_t *model, const char *value);
343
+ int crf1dm_to_aid(crf1dm_t *model, const char *value);
344
+ const char *crf1dm_to_attr(crf1dm_t *model, int aid);
345
+ int crf1dm_get_labelref(crf1dm_t *model, int lid, feature_refs_t *ref);
346
+ int crf1dm_get_attrref(crf1dm_t *model, int aid, feature_refs_t *ref);
347
+ int crf1dm_get_featureid(feature_refs_t *ref, int i);
348
+ int crf1dm_get_feature(crf1dm_t *model, int fid, crf1dm_feature_t *f);
349
+ void crf1dm_dump_states(crf1dm_t *model, FILE *fp);
350
+ void crf1dm_dump_transitions(crf1dm_t *model, FILE *fp);
351
+
352
+ /** @} */
353
+
354
+ #endif /*__CRF1D_H__*/