/* scorpiox-scorpioplayer-ntextcat-ngram-language-identify — pure C99 * character-ngram language identifier + trainer API. * See SPEC.md. Zero network. Profile is a file, never a string literal. */ #ifndef SPLID_H #define SPLID_H #ifdef __cplusplus extern "C" { #endif #include enum { SPLID_OK = 0, SPLID_TOO_SHORT = 1, SPLID_AMBIGUOUS = 2, SPLID_NO_PROFILE = 3, SPLID_BAD_PROFILE = 4, SPLID_BAD_UTF8 = 5, SPLID_INVALID_ARG = 6, SPLID_OOM = 7 }; #ifndef SPLID_EXPORT # if defined(__GNUC__) || defined(__clang__) # define SPLID_EXPORT __attribute__((visibility("default"))) # else # define SPLID_EXPORT # endif #endif /* ---- profile lifecycle: load once, identify many ---- */ SPLID_EXPORT int splid_load_profile(const char *path); SPLID_EXPORT int splid_load_profile_memory(const void *data, size_t len); SPLID_EXPORT void splid_free_profile(void); SPLID_EXPORT int splid_profile_language_count(void); SPLID_EXPORT const char *splid_profile_language_code(int i); /* ISO 639-2T */ SPLID_EXPORT const char *splid_profile_meta(const char *key); /* ---- identify ---- */ SPLID_EXPORT int splid_identify(const char *utf8_text); SPLID_EXPORT int splid_result_count(void); SPLID_EXPORT const char *splid_result_code(int i); /* ranked best-first */ SPLID_EXPORT double splid_result_distance(int i); SPLID_EXPORT double splid_result_confidence(int i); /* from top-2 margin */ SPLID_EXPORT const char *splid_best_code(void); /* NULL if refused */ /* honesty knobs (C# has no equivalent) */ SPLID_EXPORT void splid_set_min_ngrams(int n); /* default 40 */ SPLID_EXPORT void splid_set_min_margin(double pct);/* default 2.0 */ SPLID_EXPORT void splid_set_size_penalty(int on); /* default 0 */ /* tuning */ SPLID_EXPORT void splid_set_max_ngram_length(int n); /* default 5 */ SPLID_EXPORT void splid_set_max_distribution(int n); /* default 4000 */ SPLID_EXPORT void splid_set_occurance_threshold(int n); /* default 0 */ /* introspection */ SPLID_EXPORT int splid_extract_ngrams(const char *utf8_text); SPLID_EXPORT int splid_ngram_count(void); SPLID_EXPORT const char *splid_ngram(int i); SPLID_EXPORT int splid_ngram_rank(int i); SPLID_EXPORT const char *splid_explain(int lang_index); /* JSON via yyjson */ SPLID_EXPORT const char *splid_last_error(void); SPLID_EXPORT const char *splid_result_json(void); SPLID_EXPORT const char *splid_version(void); SPLID_EXPORT const char *splid_profile_id(void); /* ---- trainer (also in lib for tests; primary consumer is splid-train) ---- */ SPLID_EXPORT int splid_train_begin(const char *iso_code); SPLID_EXPORT int splid_train_feed(const char *utf8_text); SPLID_EXPORT int splid_train_end_language(void); SPLID_EXPORT int splid_train_write_profile(const char *path); SPLID_EXPORT int splid_train_set_meta(const char *key, const char *value); SPLID_EXPORT void splid_train_reset(void); /* letter predicate — named + testable (SPEC §2 D4) */ SPLID_EXPORT int splid_is_letter(unsigned int codepoint); #ifdef __cplusplus } #endif #endif /* SPLID_H */