MCPcopy Index your code
hub / github.com/abadojack/whatlanggo

github.com/abadojack/whatlanggo @v1.0.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.0.1 ↗ · + Follow
60 symbols 128 edges 15 files 21 documented · 35% 3 cross-repo links
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Whatlanggo

Build Status Go Report Card GoDoc Coverage Status

Natural language detection for Go.

Features

  • Supports 84 languages
  • 100% written in Go
  • No external dependencies
  • Fast
  • Recognizes not only a language, but also a script (Latin, Cyrillic, etc)

Getting started

Installation:

    go get -u github.com/abadojack/whatlanggo

Simple usage example:

package main

import (
    "fmt"

    "github.com/abadojack/whatlanggo"
)

func main() {
    info := whatlanggo.Detect("Foje funkcias kaj foje ne funkcias")
    fmt.Println("Language:", info.Lang.String(), " Script:", whatlanggo.Scripts[info.Script], " Confidence: ", info.Confidence)
}

Blacklisting and whitelisting

package main

import (
    "fmt"

    "github.com/abadojack/whatlanggo"
)

func main() {
    //Blacklist
    options := whatlanggo.Options{
        Blacklist: map[whatlanggo.Lang]bool{
            whatlanggo.Ydd: true,
        },
    }

    info := whatlanggo.DetectWithOptions("האקדמיה ללשון העברית", options)

    fmt.Println("Language:", info.Lang.String(), "Script:", whatlanggo.Scripts[info.Script])

    //Whitelist
    options1 := whatlanggo.Options{
        Whitelist: map[whatlanggo.Lang]bool{
            whatlanggo.Epo: true,
            whatlanggo.Ukr: true,
        },
    }

    info = whatlanggo.DetectWithOptions("Mi ne scias", options1)
    fmt.Println("Language:", info.Lang.String(), " Script:", whatlanggo.Scripts[info.Script])
}

For more details, please check the documentation.

Requirements

Go 1.8 or higher

How does it work?

How does the language recognition work?

The algorithm is based on the trigram language models, which is a particular case of n-grams. To understand the idea, please check the original whitepaper Cavnar and Trenkle '94: N-Gram-Based Text Categorization'.

How IsReliable calculated?

It is based on the following factors: * How many unique trigrams are in the given text * How big is the difference between the first and the second(not returned) detected languages? This metric is called rate in the code base.

Therefore, it can be presented as 2d space with threshold functions, that splits it into "Reliable" and "Not reliable" areas. This function is a hyperbola and it looks like the following one:

Language recognition whatlang rust

For more details, please check a blog article Introduction to Rust Whatlang Library and Natural Language Identification Algorithms.

License

MIT

Derivation

whatlanggo is a derivative of Franc (JavaScript, MIT) by Titus Wormer.

Acknowledgements

Thanks to greyblake (Potapov Sergey) for creating whatlang-rs from where I got the idea and algorithms.

Core symbols most depended-on inside this repo

LangToString
called by 15
lang.go
DetectWithOptions
called by 7
detect.go
detectLangInProfiles
called by 6
detect.go
Detect
called by 3
detect.go
isStopChar
called by 3
utils.go
DetectLangWithOptions
called by 2
detect.go
detectLangBaseOnScript
called by 2
detect.go
toTrigramChar
called by 2
trigrams.go

Shape

Function 49
Struct 5
Method 4
TypeAlias 2

Languages

Go100%

Modules by API surface

script_test.go15 symbols
detect_test.go9 symbols
detect.go9 symbols
lang.go8 symbols
trigrams.go4 symbols
trigrams_test.go3 symbols
lang_test.go3 symbols
utils_test.go2 symbols
utils.go2 symbols
script.go2 symbols
info.go2 symbols
options.go1 symbols

For agents

$ claude mcp add whatlanggo \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact