Text

Language detection

Which of 69 languages a text is in, its script and how sure: route tickets, tag posts, pick a spell-checker.

Version 1.0.0 · 2 functions · 1 crate

#i18n#language#text#support

Functions

What use lang.qwer gives a program, with the types Quillo sees. To take only some, or under other names: use detect_language, detect_script from lang (Quillo 0.6).

detect_language(text: str) → any?

{ code, name, script, confidence, reliable } for text (code is ISO 639-3: "eng", "fra", "jpn"), or null when it cannot tell.

detect_script(text: str) → str?

Only the script text is written in ("Latin", "Cyrillic", "Arabic", "Han", ...), or null.

Get it

$ quillo install lang               # lang.qwer into this folder$ quillo install lang --example     # and its example, lang.qwe

Or with curl:

$ curl -O https://quillolang.org/plugins/files/lang.qwer$ curl -O https://quillolang.org/plugins/files/lang.qwe

Then, in your program, all of it or only what you call:

main.qwe
use lang.qweruse detect_language, detect_script from lang      // Quillo 0.6: only these

It uses this crate, which cargo fetches the first time the plugin is built:

[dependencies]
whatlang = "0.16"

Example

lang.qwe
// Tells the language of each message.////   quillo run lang.qwe      then open http://localhost:8080/detect?text=Bonjour+tout+le+mondeuse "lang.qwer"route GET /detect ? { text: str } = detect_language(text)route GET /many = ["Where is my order?", "¿Dónde está mi pedido?", "Wo ist meine Bestellung?", "私の注文はどこですか"]    | map((t) => { text: t, lang: detect_language(t)?.code })
$ quillo run lang.qwe$ curl 'localhost:8080/detect?text=Bonjour+tout+le+monde%2C+comment+allez-vous'$ curl 'localhost:8080/many'

Source

lang.qwer
//! Which language a text is in, of 69, with its script and how sure: route support tickets, pick a spell-checker, tag posts.//! version: 1.0.0//!//! [dependencies]//! whatlang = "0.16"use serde_json::{json, Value};/// `{ code, name, script, confidence, reliable }` for `text` (`code` is ISO 639-3: "eng", "fra", "jpn"), or null when it cannot tell.pub fn detect_language(text: &str) -> Option<Value> {    whatlang::detect(text).map(|i| json!({        "code": i.lang().code(),        "name": i.lang().eng_name(),        "script": i.script().name(),        "confidence": (i.confidence() * 100.0).round() / 100.0,        "reliable": i.is_reliable(),    }))}/// Only the script `text` is written in ("Latin", "Cyrillic", "Arabic", "Han", ...), or null.pub fn detect_script(text: &str) -> Option<String> {    whatlang::detect_script(text).map(|s| s.name().to_string())}
Thread
66Useful? Like it, or add to its thread below.

Thread 0 posts

On Language detection: questions, tips, corrections, and code that uses it.

No posts yet. The first one opens the thread.