This is a go wrapper around langid.c. The repo include all the necessary c code and the default trained model to be able to use as is.
Depends on protobuf-c library, in ubuntu this can be installed using
sudo apt-get install libprotobuf-c-dev
Install the go library
go get github.com/cliqz-oss/langid_go
package main
import (
"fmt"
"github.com/cliqz-oss/langid_go"
)
func main() {
li := langid_go.NewIdfr()
// de-allocates the language model from memory.
defer li.Destroy()
fmt.Println(li.DetectLanguage("hello world"))
}
All C files except langid_go.{c,h}
are copied from langid.c
repo, including
model.c
which contains a generated model. To update these files remove them
from repo, and pass LDFLAG: -lliblangid
to cgo (here:
https://github.com/cliqz-oss/langid_go/blob/master/langid_go.go#L3
)
- Loading your own model is not supported.
- No interface to get the probability values out.
tags: golang, go, langid.go