KaisarCode

lng.c

lng.c - Language Detection Library

lng.c is a minimalist C library and CLI for detecting the language of the given text using internal language profiles. It is designed as a composable native primitive for the KaisarCode ecosystem.


CLI

Detect the language of text provided as an argument or via standard input.

Examples

Single language detection:

./bin/x86_64/linux/lng "Hello world"

Ranked detection with threshold and limit:

./bin/x86_64/linux/lng "Hello world" -l 3 -t 0.1

Standard input processing:

printf 'hola mundo' | ./bin/x86_64/linux/lng

Parameters

FlagDescription
-t, --threshold <n>Minimum score threshold
-l, --limit <n>Maximum number of results
-h, --helpShow help and usage
-v, --versionShow version

Output

Results are printed as the language code (for single match) or code and score (for ranked results):

en
en: 0.9500
es: 0.0400

Public API

#include "lng.h"

kc_lng_init();

const char *code = kc_lng_detect("Hello world");

kc_lng_result_t results[3];
int count = kc_lng_detect_top("Hello world", results, 3, 0.1);

Lifecycle

  • kc_lng_init() - initializes internal language profiles. This call is idempotent and thread-safe.
  • kc_lng_detect() and kc_lng_detect_top() - perform language detection. Both call kc_lng_init() internally if not yet initialized. Once initialized, all state is read-only and safe for concurrent access.

Build

Compiled artifacts are generated under bin/{arch}/{platform}/ for the host architecture running the build.

make clean && make

Multiarch Builds

The project is prepared to build artifacts for multiple architectures under bin/{arch}/{platform}/. A plain make builds only the current host architecture, while the targets below build the full matrix or a specific target.

make all
make x86_64/linux
make x86_64/windows
make i686/linux
make i686/windows
make aarch64/linux
make aarch64/android
make armv7/linux
make armv7/android
make armv7hf/linux
make riscv64/linux
make powerpc64le/linux
make mips/linux
make mipsel/linux
make mips64el/linux
make s390x/linux
make loongarch64/linux

License

GPLv3

This project is distributed under the GNU General Public License version 3 (GPLv3).


Repo

GitHub: kaisarcode/lng.c