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
| Flag | Description |
|---|---|
-t, --threshold <n> | Minimum score threshold |
-l, --limit <n> | Maximum number of results |
-h, --help | Show help and usage |
-v, --version | Show 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()andkc_lng_detect_top()- perform language detection. Both callkc_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
Beta Notice
This is a beta project tested only on Debian x86_64. It was created out of a personal need for these libraries, but no guarantees are provided regarding its stability or future support. You are free to test it, use it, and modify it as you please.
If you'd like to reach out, you can send an email to [email protected]. Please note that I do not accept pull requests; the goal is to avoid long-term dependency on platforms like GitHub, and I do not maintain fixed infrastructure to guarantee long-term stability for these projects.
Repo
You can download the repository and read the most up-to-date documentation directly from its official source.
GitHub: kaisarcode/lng.c
License
This project is distributed under the GNU General Public License version 3 (GPLv3).
