chaine 3.13.1__cp313-cp313-musllinux_1_2_x86_64.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-313-x86_64-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-a0b57c20.so.1 +0 -0
  70. chaine.libs/libstdc++-0d31ccbe.so.6.0.32 +0 -0
@@ -0,0 +1,1077 @@
1
+ /*
2
+ * CRFsuite library.
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 __CRFSUITE_H__
34
+ #define __CRFSUITE_H__
35
+
36
+ #ifdef __cplusplus
37
+ extern "C"
38
+ {
39
+ #endif /*__cplusplus*/
40
+
41
+ #include <limits.h>
42
+ #include <stdio.h>
43
+ #include <stdarg.h>
44
+
45
+ /**
46
+ * \addtogroup crfsuite_api CRFSuite C API
47
+ * @{
48
+ *
49
+ * The CRFSuite C API provides a low-level library for manupulating
50
+ * CRFSuite in C language.
51
+ */
52
+
53
+ /**
54
+ * \addtogroup crfsuite_misc Miscellaneous definitions and functions
55
+ * @{
56
+ */
57
+
58
+ /** Version number of CRFSuite library. */
59
+ #define CRFSUITE_VERSION "0.12.2"
60
+
61
+ /** Copyright string of CRFSuite library. */
62
+ #define CRFSUITE_COPYRIGHT "Copyright (c) 2007-2013 Naoaki Okazaki"
63
+
64
+ /** Type of a float value. */
65
+ typedef double floatval_t;
66
+
67
+ /** Maximum value of a float value. */
68
+ #define FLOAT_MAX DBL_MAX
69
+
70
+ /**
71
+ * Status codes.
72
+ */
73
+ enum
74
+ {
75
+ /** Success. */
76
+ CRFSUITE_SUCCESS = 0,
77
+ /** Unknown error occurred. */
78
+ CRFSUITEERR_UNKNOWN = INT_MIN,
79
+ /** Insufficient memory. */
80
+ CRFSUITEERR_OUTOFMEMORY,
81
+ /** Unsupported operation. */
82
+ CRFSUITEERR_NOTSUPPORTED,
83
+ /** Incompatible data. */
84
+ CRFSUITEERR_INCOMPATIBLE,
85
+ /** Internal error. */
86
+ CRFSUITEERR_INTERNAL_LOGIC,
87
+ /** Overflow. */
88
+ CRFSUITEERR_OVERFLOW,
89
+ /** Not implemented. */
90
+ CRFSUITEERR_NOTIMPLEMENTED,
91
+ };
92
+
93
+ /**@}*/
94
+
95
+ /**
96
+ * \addtogroup crfsuite_object Object interfaces and utilities.
97
+ * @{
98
+ */
99
+
100
+ struct tag_crfsuite_model;
101
+ /** CRFSuite model interface. */
102
+ typedef struct tag_crfsuite_model crfsuite_model_t;
103
+
104
+ struct tag_crfsuite_trainer;
105
+ /** CRFSuite trainer interface. */
106
+ typedef struct tag_crfsuite_trainer crfsuite_trainer_t;
107
+
108
+ struct tag_crfsuite_tagger;
109
+ /** CRFSuite tagger interface. */
110
+ typedef struct tag_crfsuite_tagger crfsuite_tagger_t;
111
+
112
+ struct tag_crfsuite_dictionary;
113
+ /** CRFSuite dictionary interface. */
114
+ typedef struct tag_crfsuite_dictionary crfsuite_dictionary_t;
115
+
116
+ struct tag_crfsuite_params;
117
+ /** CRFSuite parameter interface. */
118
+ typedef struct tag_crfsuite_params crfsuite_params_t;
119
+
120
+ /**@}*/
121
+
122
+ /**
123
+ * \addtogroup crfsuite_data Dataset (attribute, item, instance, dataset)
124
+ * @{
125
+ */
126
+
127
+ /**
128
+ * An attribute.
129
+ * An attribute consists of an attribute id with its value.
130
+ */
131
+ typedef struct
132
+ {
133
+ int aid; /**< Attribute id. */
134
+ floatval_t value; /**< Value of the attribute. */
135
+ } crfsuite_attribute_t;
136
+
137
+ /**
138
+ * An item.
139
+ * An item consists of an array of attributes.
140
+ */
141
+ typedef struct
142
+ {
143
+ /** Number of contents associated with the item. */
144
+ int num_contents;
145
+ /** Maximum number of contents (internal use). */
146
+ int cap_contents;
147
+ /** Array of the attributes. */
148
+ crfsuite_attribute_t *contents;
149
+ } crfsuite_item_t;
150
+
151
+ /**
152
+ * An instance (sequence of items and labels).
153
+ * An instance consists of a sequence of items and labels.
154
+ */
155
+ typedef struct
156
+ {
157
+ /** Number of items/labels in the sequence. */
158
+ int num_items;
159
+ /** Maximum number of items/labels (internal use). */
160
+ int cap_items;
161
+ /** Array of the item sequence. */
162
+ crfsuite_item_t *items;
163
+ /** Array of the label sequence. */
164
+ int *labels;
165
+ /** Instance weight. */
166
+ floatval_t weight;
167
+ /** Group ID of the instance. */
168
+ int group;
169
+ } crfsuite_instance_t;
170
+
171
+ /**
172
+ * A data set.
173
+ * A data set consists of an array of instances and dictionary objects
174
+ * for attributes and labels.
175
+ */
176
+ typedef struct
177
+ {
178
+ /** Number of instances. */
179
+ int num_instances;
180
+ /** Maximum number of instances (internal use). */
181
+ int cap_instances;
182
+ /** Array of instances. */
183
+ crfsuite_instance_t *instances;
184
+
185
+ /** Dictionary object for attributes. */
186
+ crfsuite_dictionary_t *attrs;
187
+ /** Dictionary object for labels. */
188
+ crfsuite_dictionary_t *labels;
189
+ } crfsuite_data_t;
190
+
191
+ /**@}*/
192
+
193
+ /**
194
+ * \addtogroup crfsuite_evaluation Evaluation utility
195
+ * @{
196
+ */
197
+
198
+ /**
199
+ * Label-wise performance values.
200
+ */
201
+ typedef struct
202
+ {
203
+ /** Number of correct predictions. */
204
+ int num_correct;
205
+ /** Number of occurrences of the label in the gold-standard data. */
206
+ int num_observation;
207
+ /** Number of predictions. */
208
+ int num_model;
209
+ /** Precision. */
210
+ floatval_t precision;
211
+ /** Recall. */
212
+ floatval_t recall;
213
+ /** F1 score. */
214
+ floatval_t fmeasure;
215
+ } crfsuite_label_evaluation_t;
216
+
217
+ /**
218
+ * An overall performance values.
219
+ */
220
+ typedef struct
221
+ {
222
+ /** Number of labels. */
223
+ int num_labels;
224
+ /** Array of label-wise evaluations. */
225
+ crfsuite_label_evaluation_t *tbl;
226
+
227
+ /** Number of correctly predicted items. */
228
+ int item_total_correct;
229
+ /** Total number of items. */
230
+ int item_total_num;
231
+ /** Total number of occurrences of labels in the gold-standard data. */
232
+ int item_total_observation;
233
+ /** Total number of predictions. */
234
+ int item_total_model;
235
+ /** Item-level accuracy. */
236
+ floatval_t item_accuracy;
237
+
238
+ /** Number of correctly predicted instances. */
239
+ int inst_total_correct;
240
+ /** Total number of instances. */
241
+ int inst_total_num;
242
+ /** Instance-level accuracy. */
243
+ floatval_t inst_accuracy;
244
+
245
+ /** Macro-averaged precision. */
246
+ floatval_t macro_precision;
247
+ /** Macro-averaged recall. */
248
+ floatval_t macro_recall;
249
+ /** Macro-averaged F1 score. */
250
+ floatval_t macro_fmeasure;
251
+ } crfsuite_evaluation_t;
252
+
253
+ /**@}*/
254
+
255
+ /**
256
+ * \addtogroup crfsuite_object
257
+ * @{
258
+ */
259
+
260
+ /**
261
+ * Type of callback function for logging.
262
+ * @param user Pointer to the user-defined data.
263
+ * @param format Format string (compatible with prinf()).
264
+ * @param args Optional arguments for the format string.
265
+ * @return int \c 0 to continue; non-zero to cancel the training.
266
+ */
267
+ typedef int (*crfsuite_logging_callback)(void *user, const char *format, va_list args);
268
+
269
+ /**
270
+ * CRFSuite model interface.
271
+ */
272
+ struct tag_crfsuite_model
273
+ {
274
+ /**
275
+ * Pointer to the internal data (internal use only).
276
+ */
277
+ void *internal;
278
+
279
+ /**
280
+ * Reference counter (internal use only).
281
+ */
282
+ int nref;
283
+
284
+ /**
285
+ * Increment the reference counter.
286
+ * @param model The pointer to this model instance.
287
+ * @return int The reference count after this increment.
288
+ */
289
+ int (*addref)(crfsuite_model_t *model);
290
+
291
+ /**
292
+ * Decrement the reference counter.
293
+ * @param model The pointer to this model instance.
294
+ * @return int The reference count after this operation.
295
+ */
296
+ int (*release)(crfsuite_model_t *model);
297
+
298
+ /**
299
+ * Obtain the pointer to crfsuite_tagger_t interface.
300
+ * @param model The pointer to this model instance.
301
+ * @param ptr_tagger The pointer that receives a crfsuite_tagger_t
302
+ * pointer.
303
+ * @return int The status code.
304
+ */
305
+ int (*get_tagger)(crfsuite_model_t *model, crfsuite_tagger_t **ptr_tagger);
306
+
307
+ /**
308
+ * Obtain the pointer to crfsuite_dictionary_t interface for labels.
309
+ * @param model The pointer to this model instance.
310
+ * @param ptr_labels The pointer that receives a crfsuite_dictionary_t
311
+ * pointer.
312
+ * @return int The status code.
313
+ */
314
+ int (*get_labels)(crfsuite_model_t *model, crfsuite_dictionary_t **ptr_labels);
315
+
316
+ /**
317
+ * Obtain the pointer to crfsuite_dictionary_t interface for attributes.
318
+ * @param model The pointer to this model instance.
319
+ * @param ptr_attrs The pointer that receives a crfsuite_dictionary_t
320
+ * pointer.
321
+ * @return int The status code.
322
+ */
323
+ int (*get_attrs)(crfsuite_model_t *model, crfsuite_dictionary_t **ptr_attrs);
324
+
325
+ /**
326
+ * Print the learned transitions as JSON.
327
+ * @param model The pointer to this model instance.
328
+ * @param fpo The FILE* pointer.
329
+ * @return int The status code.
330
+ */
331
+ int (*dump_transitions)(crfsuite_model_t *model, FILE *fpo);
332
+
333
+ /**
334
+ * Print the learned states as JSON.
335
+ * @param model The pointer to this model instance.
336
+ * @param fpo The FILE* pointer.
337
+ * @return int The status code.
338
+ */
339
+ int (*dump_states)(crfsuite_model_t *model, FILE *fpo);
340
+ };
341
+
342
+ /**
343
+ * CRFSuite trainer interface.
344
+ */
345
+ struct tag_crfsuite_trainer
346
+ {
347
+ /**
348
+ * Pointer to the internal data (internal use only).
349
+ */
350
+ void *internal;
351
+
352
+ /**
353
+ * Reference counter (internal use only).
354
+ */
355
+ int nref;
356
+
357
+ /**
358
+ * Increment the reference counter.
359
+ * @param trainer The pointer to this trainer instance.
360
+ * @return int The reference count after this increment.
361
+ */
362
+ int (*addref)(crfsuite_trainer_t *trainer);
363
+
364
+ /**
365
+ * Decrement the reference counter.
366
+ * @param trainer The pointer to this trainer instance.
367
+ * @return int The reference count after this operation.
368
+ */
369
+ int (*release)(crfsuite_trainer_t *trainer);
370
+
371
+ /**
372
+ * Obtain the pointer to crfsuite_params_t interface.
373
+ * @param trainer The pointer to this trainer instance.
374
+ * @return crfsuite_params_t* The pointer to crfsuite_params_t.
375
+ */
376
+ crfsuite_params_t *(*params)(crfsuite_trainer_t *trainer);
377
+
378
+ /**
379
+ * Set the callback function and user-defined data.
380
+ * @param trainer The pointer to this trainer instance.
381
+ * @param user The pointer to the user-defined data.
382
+ * @param cbm The pointer to the callback function.
383
+ */
384
+ void (*set_message_callback)(crfsuite_trainer_t *trainer, void *user, crfsuite_logging_callback cbm);
385
+
386
+ /**
387
+ * Start a training process.
388
+ * @param trainer The pointer to this trainer instance.
389
+ * @param data The poiinter to the data set.
390
+ * @param filename The filename to which the trainer stores the model.
391
+ * If an empty string is specified, this function
392
+ * does not sture the model to a file.
393
+ * @param holdout The holdout group.
394
+ * @return int The status code.
395
+ */
396
+ int (*train)(crfsuite_trainer_t *trainer, const crfsuite_data_t *data, const char *filename, int holdout);
397
+ };
398
+
399
+ /**
400
+ * CRFSuite tagger interface.
401
+ */
402
+ struct tag_crfsuite_tagger
403
+ {
404
+ /**
405
+ * Pointer to the internal data (internal use only).
406
+ */
407
+ void *internal;
408
+
409
+ /**
410
+ * Reference counter (internal use only).
411
+ */
412
+ int nref;
413
+
414
+ /**
415
+ * Increment the reference counter.
416
+ * @param tagger The pointer to this tagger instance.
417
+ * @return int The reference count after this increment.
418
+ */
419
+ int (*addref)(crfsuite_tagger_t *tagger);
420
+
421
+ /**
422
+ * Decrement the reference counter.
423
+ * @param tagger The pointer to this tagger instance.
424
+ * @return int The reference count after this operation.
425
+ */
426
+ int (*release)(crfsuite_tagger_t *tagger);
427
+
428
+ /**
429
+ * Set an instance to the tagger.
430
+ * @param tagger The pointer to this tagger instance.
431
+ * @param inst The item sequence to be tagged.
432
+ * @return int The status code.
433
+ */
434
+ int (*set)(crfsuite_tagger_t *tagger, crfsuite_instance_t *inst);
435
+
436
+ /**
437
+ * Obtain the number of items in the current instance.
438
+ * @param tagger The pointer to this tagger instance.
439
+ * @return int The number of items of the instance set by
440
+ * set() function.
441
+ * @return int The status code.
442
+ */
443
+ int (*length)(crfsuite_tagger_t *tagger);
444
+
445
+ /**
446
+ * Find the Viterbi label sequence.
447
+ * @param tagger The pointer to this tagger instance.
448
+ * @param labels The label array that receives the Viterbi label
449
+ * sequence. The number of elements in the array must
450
+ * be no smaller than the number of item.
451
+ * @param ptr_score The pointer to a float variable that receives the
452
+ * score of the Viterbi label sequence.
453
+ * @return int The status code.
454
+ */
455
+ int (*viterbi)(crfsuite_tagger_t *tagger, int *labels, floatval_t *ptr_score);
456
+
457
+ /**
458
+ * Compute the score of a label sequence.
459
+ * @param tagger The pointer to this tagger instance.
460
+ * @param path The label sequence.
461
+ * @param ptr_score The pointer to a float variable that receives the
462
+ * score of the label sequence.
463
+ * @return int The status code.
464
+ */
465
+ int (*score)(crfsuite_tagger_t *tagger, int *path, floatval_t *ptr_score);
466
+
467
+ /**
468
+ * Compute the log of the partition factor (normalization constant).
469
+ * @param tagger The pointer to this tagger instance.
470
+ * @param ptr_score The pointer to a float variable that receives the
471
+ * logarithm of the partition factor.
472
+ * @return int The status code.
473
+ */
474
+ int (*lognorm)(crfsuite_tagger_t *tagger, floatval_t *ptr_norm);
475
+
476
+ /**
477
+ * Compute the marginal probability of a label at a position.
478
+ * This function computes P(y_t = l | x), the probability when
479
+ * y_t is the label (l).
480
+ * @param tagger The pointer to this tagger instance.
481
+ * @param l The label.
482
+ * @param t The position.
483
+ * @param ptr_prob The pointer to a float variable that receives the
484
+ * marginal probability.
485
+ * @return int The status code.
486
+ */
487
+ int (*marginal_point)(crfsuite_tagger_t *tagger, int l, int t, floatval_t *ptr_prob);
488
+
489
+ /**
490
+ * Compute the marginal probability of a partial label sequence.
491
+ * @param tagger The pointer to this tagger instance.
492
+ * @param path The partial label sequence.
493
+ * @param begin The start position of the partial label sequence.
494
+ * @param end The last+1 position of the partial label sequence.
495
+ * @param ptr_prob The pointer to a float variable that receives the
496
+ * marginal probability.
497
+ * @return int The status code.
498
+ */
499
+ int (*marginal_path)(crfsuite_tagger_t *tagger, const int *path, int begin, int end, floatval_t *ptr_prob);
500
+ };
501
+
502
+ /**
503
+ * CRFSuite dictionary interface.
504
+ */
505
+ struct tag_crfsuite_dictionary
506
+ {
507
+ /**
508
+ * Pointer to the internal data (internal use only).
509
+ */
510
+ void *internal;
511
+
512
+ /**
513
+ * Reference counter (internal use only).
514
+ */
515
+ int nref;
516
+
517
+ /**
518
+ * Increment the reference counter.
519
+ * @param dic The pointer to this dictionary instance.
520
+ * @return int The reference count after this increment.
521
+ */
522
+ int (*addref)(crfsuite_dictionary_t *dic);
523
+
524
+ /**
525
+ * Decrement the reference counter.
526
+ * @param dic The pointer to this dictionary instance.
527
+ * @return int The reference count after this operation.
528
+ */
529
+ int (*release)(crfsuite_dictionary_t *dic);
530
+
531
+ /**
532
+ * Assign and obtain the integer ID for the string.
533
+ * @param dic The pointer to this dictionary instance.
534
+ * @param str The string.
535
+ * @return int The ID associated with the string if any,
536
+ * the new ID otherwise.
537
+ */
538
+ int (*get)(crfsuite_dictionary_t *dic, const char *str);
539
+
540
+ /**
541
+ * Obtain the integer ID for the string.
542
+ * @param dic The pointer to this dictionary instance.
543
+ * @param str The string.
544
+ * @return int The ID associated with the string if any,
545
+ * \c -1 otherwise.
546
+ */
547
+ int (*to_id)(crfsuite_dictionary_t *dic, const char *str);
548
+
549
+ /**
550
+ * Obtain the string for the ID.
551
+ * @param dic The pointer to this dictionary instance.
552
+ * @param id the string ID.
553
+ * @param pstr \c *pstr points to the string associated with
554
+ * the ID if any, \c NULL otherwise.
555
+ * @return int \c 0 if the string ID is associated with a string,
556
+ * \c 1 otherwise.
557
+ */
558
+ int (*to_string)(crfsuite_dictionary_t *dic, int id, char const **pstr);
559
+
560
+ /**
561
+ * Obtain the number of strings in the dictionary.
562
+ * @param dic The pointer to this dictionary instance.
563
+ * @return int The number of strings stored in the dictionary.
564
+ */
565
+ int (*num)(crfsuite_dictionary_t *dic);
566
+
567
+ /**
568
+ * Free the memory block allocated by to_string() function.
569
+ * @param dic The pointer to this dictionary instance.
570
+ * @param str The pointer to the string whose memory block is
571
+ * freed.
572
+ */
573
+ void (*free)(crfsuite_dictionary_t *dic, const char *str);
574
+ };
575
+
576
+ /**
577
+ * CRFSuite parameter interface.
578
+ */
579
+ struct tag_crfsuite_params
580
+ {
581
+ /**
582
+ * Pointer to the instance data (internal use only).
583
+ */
584
+ void *internal;
585
+
586
+ /**
587
+ * Reference counter (internal use only).
588
+ */
589
+ int nref;
590
+
591
+ /**
592
+ * Increment the reference counter.
593
+ * @param params The pointer to this parameter instance.
594
+ * @return int The reference count after this increment.
595
+ */
596
+ int (*addref)(crfsuite_params_t *params);
597
+
598
+ /**
599
+ * Decrement the reference counter.
600
+ * @param params The pointer to this parameter instance.
601
+ * @return int The reference count after this operation.
602
+ */
603
+ int (*release)(crfsuite_params_t *params);
604
+
605
+ /**
606
+ * Obtain the number of available parameters.
607
+ * @param params The pointer to this parameter instance.
608
+ * @return int The number of parameters maintained by this object.
609
+ */
610
+ int (*num)(crfsuite_params_t *params);
611
+
612
+ /**
613
+ * Obtain the name of a parameter.
614
+ * @param params The pointer to this parameter instance.
615
+ * @param i The parameter index.
616
+ * @param ptr_name *ptr_name points to the parameter name.
617
+ * @return int \c 0 always.
618
+ */
619
+ int (*name)(crfsuite_params_t *params, int i, char **ptr_name);
620
+
621
+ /**
622
+ * Set a parameter value.
623
+ * @param params The pointer to this parameter instance.
624
+ * @param name The parameter name.
625
+ * @param value The parameter value in string format.
626
+ * @return int \c 0 if the parameter is found, \c -1 otherwise.
627
+ */
628
+ int (*set)(crfsuite_params_t *params, const char *name, const char *value);
629
+
630
+ /**
631
+ * Get a parameter value.
632
+ * @param params The pointer to this parameter instance.
633
+ * @param name The parameter name.
634
+ * @param ptr_value *ptr_value presents the parameter value in string
635
+ * format.
636
+ * @return int \c 0 if the parameter is found, \c -1 otherwise.
637
+ */
638
+ int (*get)(crfsuite_params_t *params, const char *name, char **ptr_value);
639
+
640
+ /**
641
+ * Set an integer value of a parameter.
642
+ * @param params The pointer to this parameter instance.
643
+ * @param name The parameter name.
644
+ * @param value The parameter value.
645
+ * @return int \c 0 if the parameter value is set successfully,
646
+ * \c -1 otherwise (unknown parameter or incompatible
647
+ * type).
648
+ */
649
+ int (*set_int)(crfsuite_params_t *params, const char *name, int value);
650
+
651
+ /**
652
+ * Set a float value of a parameter.
653
+ * @param params The pointer to this parameter instance.
654
+ * @param name The parameter name.
655
+ * @param value The parameter value.
656
+ * @return int \c 0 if the parameter value is set successfully,
657
+ * \c -1 otherwise (unknown parameter or incompatible
658
+ * type).
659
+ */
660
+ int (*set_float)(crfsuite_params_t *params, const char *name, floatval_t value);
661
+
662
+ /**
663
+ * Set a string value of a parameter.
664
+ * @param params The pointer to this parameter instance.
665
+ * @param name The parameter name.
666
+ * @param value The parameter value.
667
+ * @return int \c 0 if the parameter value is set successfully,
668
+ * \c -1 otherwise (unknown parameter or incompatible
669
+ * type).
670
+ */
671
+ int (*set_string)(crfsuite_params_t *params, const char *name, const char *value);
672
+
673
+ /**
674
+ * Get an integer value of a parameter.
675
+ * @param params The pointer to this parameter instance.
676
+ * @param name The parameter name.
677
+ * @param ptr_value The pointer to a variable that receives the
678
+ * integer value.
679
+ * @return int \c 0 if the parameter value is obtained
680
+ * successfully, \c -1 otherwise (unknown parameter
681
+ * or incompatible type).
682
+ */
683
+ int (*get_int)(crfsuite_params_t *params, const char *name, int *ptr_value);
684
+
685
+ /**
686
+ * Get a float value of a parameter.
687
+ * @param params The pointer to this parameter instance.
688
+ * @param name The parameter name.
689
+ * @param ptr_value The pointer to a variable that receives the
690
+ * float value.
691
+ * @return int \c 0 if the parameter value is obtained
692
+ * successfully, \c -1 otherwise (unknown parameter
693
+ * or incompatible type).
694
+ */
695
+ int (*get_float)(crfsuite_params_t *params, const char *name, floatval_t *ptr_value);
696
+
697
+ /**
698
+ * Get a string value of a parameter.
699
+ * @param params The pointer to this parameter instance.
700
+ * @param name The parameter name.
701
+ * @param ptr_value *ptr_value presents the parameter value.
702
+ * @return int \c 0 if the parameter value is obtained
703
+ * successfully, \c -1 otherwise (unknown parameter
704
+ * or incompatible type).
705
+ */
706
+ int (*get_string)(crfsuite_params_t *params, const char *name, char **ptr_value);
707
+
708
+ /**
709
+ * Get the help message of a parameter.
710
+ * @param params The pointer to this parameter instance.
711
+ * @param name The parameter name.
712
+ * @param ptr_type The pointer to \c char* to which this function
713
+ * store the type of the parameter.
714
+ * @param ptr_help The pointer to \c char* to which this function
715
+ * store the help message of the parameter.
716
+ * @return int \c 0 if the parameter is found, \c -1 otherwise.
717
+ */
718
+ int (*help)(crfsuite_params_t *params, const char *name, char **ptr_type, char **ptr_help);
719
+
720
+ /**
721
+ * Free the memory block of a string allocated by this object.
722
+ * @param params The pointer to this parameter instance.
723
+ * @param str The pointer to the string.
724
+ */
725
+ void (*free)(crfsuite_params_t *params, const char *str);
726
+ };
727
+
728
+ /**@}*/
729
+
730
+ /**
731
+ * \addtogroup crfsuite_object
732
+ * @{
733
+ */
734
+
735
+ /**
736
+ * Create an instance of an object by an interface identifier.
737
+ * @param iid The interface identifier.
738
+ * @param ptr The pointer to \c void* that points to the
739
+ * instance of the object if successful,
740
+ * *ptr points to \c NULL otherwise.
741
+ * @return int \c 1 if this function creates an object successfully,
742
+ * \c 0 otherwise. Note that this is inconsistent with the
743
+ * other CRFsuite API calls.
744
+ */
745
+ int crfsuite_create_instance(const char *iid, void **ptr);
746
+
747
+ /**
748
+ * Create an instance of a model object from a model file.
749
+ * @param filename The filename of the model.
750
+ * @param ptr The pointer to \c void* that points to the
751
+ * instance of the model object if successful,
752
+ * *ptr points to \c NULL otherwise.
753
+ * @return int \c 0 if this function creates an object successfully,
754
+ * \c 1 otherwise.
755
+ */
756
+ int crfsuite_create_instance_from_file(const char *filename, void **ptr);
757
+
758
+ /**
759
+ * Create an instance of a model object from a model in memory.
760
+ * @param data A pointer to the model data.
761
+ * Must be 16-byte aligned.
762
+ * @param size A size (in bytes) of the model data.
763
+ * @param ptr The pointer to \c void* that points to the
764
+ * instance of the model object if successful,
765
+ * *ptr points to \c NULL otherwise.
766
+ * @return int \c 0 if this function creates an object successfully,
767
+ * \c 1 otherwise
768
+ */
769
+ int crfsuite_create_instance_from_memory(const void *data, size_t size, void **ptr);
770
+
771
+ /**
772
+ * Create instances of tagging object from a model file.
773
+ * @param filename The filename of the model.
774
+ * @param ptr_tagger The pointer to \c void* that points to the
775
+ * instance of the tagger object if successful,
776
+ * *ptr points to \c NULL otherwise.
777
+ * @param ptr_attrs The pointer to \c void* that points to the
778
+ * instance of the dictionary object for attributes
779
+ * if successful, *ptr points to \c NULL otherwise.
780
+ * @param ptr_labels The pointer to \c void* that points to the
781
+ * instance of the dictionary object for labels
782
+ * if successful, *ptr points to \c NULL otherwise.
783
+ * @return int \c 0 if this function creates an object successfully,
784
+ * \c 1 otherwise.
785
+ */
786
+ int crfsuite_create_tagger(
787
+ const char *filename,
788
+ crfsuite_tagger_t **ptr_tagger,
789
+ crfsuite_dictionary_t **ptr_attrs,
790
+ crfsuite_dictionary_t **ptr_labels);
791
+
792
+ /**@}*/
793
+
794
+ /**
795
+ * \addtogroup crfsuite_data
796
+ * @{
797
+ */
798
+
799
+ /**
800
+ * Initialize an attribute structure.
801
+ * @param attr The pointer to crfsuite_attribute_t.
802
+ */
803
+ void crfsuite_attribute_init(crfsuite_attribute_t *attr);
804
+
805
+ /**
806
+ * Set an attribute and its value.
807
+ * @param attr The pointer to crfsuite_attribute_t.
808
+ * @param aid The attribute identifier.
809
+ * @param value The attribute value.
810
+ */
811
+ void crfsuite_attribute_set(crfsuite_attribute_t *attr, int aid, floatval_t value);
812
+
813
+ /**
814
+ * Copy the content of an attribute structure.
815
+ * @param dst The pointer to the destination.
816
+ * @param src The pointer to the source.
817
+ */
818
+ void crfsuite_attribute_copy(crfsuite_attribute_t *dst, const crfsuite_attribute_t *src);
819
+
820
+ /**
821
+ * Swap the contents of two attribute structures.
822
+ * @param x The pointer to an attribute structure.
823
+ * @param y The pointer to another attribute structure.
824
+ */
825
+ void crfsuite_attribute_swap(crfsuite_attribute_t *x, crfsuite_attribute_t *y);
826
+
827
+ /**
828
+ * Initialize an item structure.
829
+ * @param item The pointer to crfsuite_item_t.
830
+ */
831
+ void crfsuite_item_init(crfsuite_item_t *item);
832
+
833
+ /**
834
+ * Initialize an item structure with the number of attributes.
835
+ * @param item The pointer to crfsuite_item_t.
836
+ * @param num_attributes The number of attributes.
837
+ */
838
+ void crfsuite_item_init_n(crfsuite_item_t *item, int num_attributes);
839
+
840
+ /**
841
+ * Uninitialize an item structure.
842
+ * @param item The pointer to crfsuite_item_t.
843
+ */
844
+ void crfsuite_item_finish(crfsuite_item_t *item);
845
+
846
+ /**
847
+ * Copy the content of an item structure.
848
+ * @param dst The pointer to the destination.
849
+ * @param src The pointer to the source.
850
+ */
851
+ void crfsuite_item_copy(crfsuite_item_t *dst, const crfsuite_item_t *src);
852
+
853
+ /**
854
+ * Swap the contents of two item structures.
855
+ * @param x The pointer to an item structure.
856
+ * @param y The pointer to another item structure.
857
+ */
858
+ void crfsuite_item_swap(crfsuite_item_t *x, crfsuite_item_t *y);
859
+
860
+ /**
861
+ * Append an attribute to the item structure.
862
+ * @param item The pointer to crfsuite_item_t.
863
+ * @param attr The attribute to be added to the item.
864
+ * @return int \c 0 if successful, \c -1 otherwise.
865
+ */
866
+ int crfsuite_item_append_attribute(crfsuite_item_t *item, const crfsuite_attribute_t *attr);
867
+
868
+ /**
869
+ * Check whether the item has no attribute.
870
+ * @param item The pointer to crfsuite_item_t.
871
+ * @return int \c 1 if the item has no attribute, \c 0 otherwise.
872
+ */
873
+ int crfsuite_item_empty(crfsuite_item_t *item);
874
+
875
+ /**
876
+ * Initialize an instance structure.
877
+ * @param seq The pointer to crfsuite_instance_t.
878
+ */
879
+ void crfsuite_instance_init(crfsuite_instance_t *seq);
880
+
881
+ /**
882
+ * Initialize an instance structure with the number of items.
883
+ * @param seq The pointer to crfsuite_instance_t.
884
+ * @param num_items The number of items.
885
+ */
886
+ void crfsuite_instance_init_n(crfsuite_instance_t *seq, int num_items);
887
+
888
+ /**
889
+ * Uninitialize an instance structure.
890
+ * @param seq The pointer to crfsuite_instance_t.
891
+ */
892
+ void crfsuite_instance_finish(crfsuite_instance_t *seq);
893
+
894
+ /**
895
+ * Copy the content of an instance structure.
896
+ * @param dst The pointer to the destination.
897
+ * @param src The pointer to the source.
898
+ */
899
+ void crfsuite_instance_copy(crfsuite_instance_t *dst, const crfsuite_instance_t *src);
900
+
901
+ /**
902
+ * Swap the contents of two instance structures.
903
+ * @param x The pointer to an instance structure.
904
+ * @param y The pointer to another instance structure.
905
+ */
906
+ void crfsuite_instance_swap(crfsuite_instance_t *x, crfsuite_instance_t *y);
907
+
908
+ /**
909
+ * Append a pair of item and label to the instance structure.
910
+ * @param seq The pointer to crfsuite_instance_t.
911
+ * @param item The item to be added to the instance.
912
+ * @param label The label to be added to the instance.
913
+ * @return int \c 0 if successful, \c -1 otherwise.
914
+ */
915
+ int crfsuite_instance_append(crfsuite_instance_t *seq, const crfsuite_item_t *item, int label);
916
+
917
+ /**
918
+ * Check whether the instance has no item.
919
+ * @param seq The pointer to crfsuite_instance_t.
920
+ * @return int \c 1 if the instance has no attribute, \c 0 otherwise.
921
+ */
922
+ int crfsuite_instance_empty(crfsuite_instance_t *seq);
923
+
924
+ /**
925
+ * Initialize a dataset structure.
926
+ * @param data The pointer to crfsuite_data_t.
927
+ */
928
+ void crfsuite_data_init(crfsuite_data_t *data);
929
+
930
+ /**
931
+ * Initialize a dataset structure with the number of instances.
932
+ * @param data The pointer to crfsuite_data_t.
933
+ * @param n The number of instances.
934
+ */
935
+ void crfsuite_data_init_n(crfsuite_data_t *data, int n);
936
+
937
+ /**
938
+ * Uninitialize a dataset structure.
939
+ * @param data The pointer to crfsuite_data_t.
940
+ */
941
+ void crfsuite_data_finish(crfsuite_data_t *data);
942
+
943
+ /**
944
+ * Copy the content of a dataset structure.
945
+ * @param dst The pointer to the destination.
946
+ * @param src The pointer to the source.
947
+ */
948
+ void crfsuite_data_copy(crfsuite_data_t *dst, const crfsuite_data_t *src);
949
+
950
+ /**
951
+ * Swap the contents of two dataset structures.
952
+ * @param x The pointer to a dataset structure.
953
+ * @param y The pointer to another dataset structure.
954
+ */
955
+ void crfsuite_data_swap(crfsuite_data_t *x, crfsuite_data_t *y);
956
+
957
+ /**
958
+ * Append an instance to the dataset structure.
959
+ * @param data The pointer to crfsuite_data_t.
960
+ * @param inst The instance to be added to the dataset.
961
+ * @return int \c 0 if successful, \c -1 otherwise.
962
+ */
963
+ int crfsuite_data_append(crfsuite_data_t *data, const crfsuite_instance_t *inst);
964
+
965
+ /**
966
+ * Obtain the maximum length of the instances in the dataset.
967
+ * @param data The pointer to crfsuite_data_t.
968
+ * @return int The maximum number of items of the instances in the
969
+ * dataset.
970
+ */
971
+ int crfsuite_data_maxlength(crfsuite_data_t *data);
972
+
973
+ /**
974
+ * Obtain the total number of items in the dataset.
975
+ * @param data The pointer to crfsuite_data_t.
976
+ * @return int The total number of items in the dataset.
977
+ */
978
+ int crfsuite_data_totalitems(crfsuite_data_t *data);
979
+
980
+ /**@}*/
981
+
982
+ /**
983
+ * \addtogroup crfsuite_evaluation
984
+ */
985
+ /**@{*/
986
+
987
+ /**
988
+ * Initialize an evaluation structure.
989
+ * @param eval The pointer to crfsuite_evaluation_t.
990
+ * @param n The number of labels in the dataset.
991
+ */
992
+ void crfsuite_evaluation_init(crfsuite_evaluation_t *eval, int n);
993
+
994
+ /**
995
+ * Uninitialize an evaluation structure.
996
+ * @param eval The pointer to crfsuite_evaluation_t.
997
+ */
998
+ void crfsuite_evaluation_finish(crfsuite_evaluation_t *eval);
999
+
1000
+ /**
1001
+ * Reset an evaluation structure.
1002
+ * @param eval The pointer to crfsuite_evaluation_t.
1003
+ */
1004
+ void crfsuite_evaluation_clear(crfsuite_evaluation_t *eval);
1005
+
1006
+ /**
1007
+ * Accmulate the correctness of the predicted label sequence.
1008
+ * @param eval The pointer to crfsuite_evaluation_t.
1009
+ * @param reference The reference label sequence.
1010
+ * @param prediction The predicted label sequence.
1011
+ * @param T The length of the label sequence.
1012
+ * @return int \c 0 if succeeded, \c 1 otherwise.
1013
+ */
1014
+ int crfsuite_evaluation_accmulate(crfsuite_evaluation_t *eval, const int *reference, const int *prediction, int T);
1015
+
1016
+ /**
1017
+ * Finalize the evaluation result.
1018
+ * @param eval The pointer to crfsuite_evaluation_t.
1019
+ */
1020
+ void crfsuite_evaluation_finalize(crfsuite_evaluation_t *eval);
1021
+
1022
+ /**
1023
+ * Print the evaluation result.
1024
+ * @param eval The pointer to crfsuite_evaluation_t.
1025
+ * @param labels The pointer to the label dictionary.
1026
+ * @param cbm The callback function to receive the evaluation result.
1027
+ * @param user The pointer to the user data that is forwarded to the
1028
+ * callback function.
1029
+ */
1030
+ void crfsuite_evaluation_output(crfsuite_evaluation_t *eval, crfsuite_dictionary_t *labels, crfsuite_logging_callback cbm, void *user);
1031
+
1032
+ /**@}*/
1033
+
1034
+ /**
1035
+ * \addtogroup crfsuite_misc Miscellaneous definitions and functions
1036
+ * @{
1037
+ */
1038
+
1039
+ /**
1040
+ * Increments the value of the integer variable as an atomic operation.
1041
+ * @param count The pointer to the integer variable.
1042
+ * @return The value after this increment.
1043
+ */
1044
+ int crfsuite_interlocked_increment(int *count);
1045
+
1046
+ /**
1047
+ * Decrements the value of the integer variable as an atomic operation.
1048
+ * @param count The pointer to the integer variable.
1049
+ * @return The value after this decrement.
1050
+ */
1051
+ int crfsuite_interlocked_decrement(int *count);
1052
+
1053
+ /**@}*/
1054
+
1055
+ /**@}*/
1056
+
1057
+ /**
1058
+ @mainpage CRFsuite: a fast implementation of Conditional Random Fields (CRFs)
1059
+
1060
+ @section intro Introduction
1061
+
1062
+ This document describes information for using
1063
+ <a href="http://www.chokkan.org/software/crfsuite">CRFsuite</a> from external
1064
+ programs. CRFsuite provides two APIs:
1065
+ - @link crfsuite_api C API @endlink: low-level and complete interface, which
1066
+ is used by the official frontend program.
1067
+ - @link crfsuite_hpp_api C++/SWIG API @endlink: high-level and easy-to-use
1068
+ interface for a number of programming languages (e.g, C++ and Python),
1069
+ which is a wrapper for the C API.
1070
+
1071
+ */
1072
+
1073
+ #ifdef __cplusplus
1074
+ }
1075
+ #endif /*__cplusplus*/
1076
+
1077
+ #endif /*__CRFSUITE_H__*/