C API reference · Kjarni 0.2.8

classifier

kjarni_classifier_config_default

struct KjarniClassifierConfig kjarni_classifier_config_default(void);

Get default classifier configuration.

kjarni_classifier_new

enum KjarniErrorCode kjarni_classifier_new(const struct KjarniClassifierConfig *config, struct KjarniClassifier **out);

Create a new Classifier.

Safety

  • config must be valid or NULL
  • out must be a valid pointer
  • The returned handle must be freed with kjarni_classifier_free

kjarni_classifier_free

void kjarni_classifier_free(struct KjarniClassifier *classifier);

Free a Classifier.

Safety

  • classifier must be null, or a handle returned by kjarni_classifier_new that has not already been passed to this function. It is invalid to use afterwards.

kjarni_classifier_classify

enum KjarniErrorCode kjarni_classifier_classify(struct KjarniClassifier *classifier, const char *text, struct KjarniClassResults *out);

Classify a single text.

Safety

  • classifier must be null, or a live handle returned by kjarni_classifier_new that has not been freed.
  • text must be null, or a valid pointer to a nul-terminated C string.
  • out must be a valid, writable pointer to a KjarniClassResults. On KJARNI_OK it receives a value the caller owns and must release with the matching *_free; on failure it is either cleared or left unmodified, and must not be read.

kjarni_classifier_classify_batch

enum KjarniErrorCode kjarni_classifier_classify_batch(struct KjarniClassifier *classifier, const char *const *texts, uintptr_t num_texts, struct KjarniClassBatch *out);

Classify several texts in one call.

The texts go through the model together, grouped by length, which on a CPU is several times faster than classifying them one at a time. Each result is the same as kjarni_classifier_classify gives for that text alone.

Safety

  • classifier must be null, or a live handle returned by kjarni_classifier_new.
  • texts must point to num_texts valid, nul-terminated C strings, or be null when num_texts is 0.
  • out must be a valid, writable pointer. On KJARNI_OK it receives a value the caller owns and must release with kjarni_class_batch_free.

kjarni_classifier_labels

enum KjarniErrorCode kjarni_classifier_labels(const struct KjarniClassifier *classifier, struct KjarniStringArray *out);

Get the classifier's labels.

Safety

  • classifier must be null, or a live handle returned by kjarni_classifier_new that has not been freed.
  • out must be a valid, writable pointer to a KjarniStringArray. On KJARNI_OK it receives a value the caller owns and must release with the matching *_free; on failure it is either cleared or left unmodified, and must not be read.

kjarni_classifier_num_labels

uintptr_t kjarni_classifier_num_labels(const struct KjarniClassifier *classifier);

Get number of labels.

Safety

  • classifier must be null, or a live handle returned by kjarni_classifier_new that has not been freed.

Kjarni runs the same engine on every platform: