Documentation ¶
Overview ¶
Package getlang provides fast natural language detection for various languages
getlang compares input text to a characteristic profile of each supported language and returns the language that best matches the input text
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Info ¶
type Info struct {
// contains filtered or unexported fields
}
Info is the language detection result
func FromReader ¶
FromReader detects the language from an io.Reader
This function will read all bytes until an EOF is reached
func FromString ¶
FromString detects the language from the given string
func (Info) Confidence ¶
Confidence returns a measure of reliability for the language classification
The output value is in the range [0, 1.0] inclusive
Example ¶
package main import ( "fmt" "github.com/rylans/getlang" ) func main() { short := getlang.FromString("short text") long := getlang.FromString("this sentence is a bit longer") fmt.Println(long.Confidence() > short.Confidence()) }
Output: true
func (Info) LanguageCode ¶
LanguageCode returns the ISO 639-1 code for the detected language
Example ¶
package main import ( "fmt" "github.com/rylans/getlang" ) func main() { fmt.Println(getlang.FromString("статей на русском").LanguageCode()) }
Output: ru
func (Info) LanguageName ¶
LanguageName returns the English name of the detected language
Example ¶
package main import ( "fmt" "github.com/rylans/getlang" ) func main() { fmt.Println(getlang.FromString("何ですか?").LanguageName()) }
Output: Japanese