Пример #1
0
func GuessLang(epub *epubgo.Epub, orig_langs []string) []string {
	spine, err := epub.Spine()
	if err != nil {
		return orig_langs
	}

	var err_spine error
	err_spine = nil
	langs := []string{}
	for err_spine == nil {
		html, err := spine.Open()
		err_spine = spine.Next()
		if err != nil {
			continue
		}
		defer html.Close()

		buff, err := ioutil.ReadAll(html)
		if err != nil {
			continue
		}
		langs = append(langs, cld2.Detect(string(buff)))
	}

	lang := commonLang(langs)
	if lang != "un" && differentLang(lang, orig_langs) {
		return []string{lang}
	}
	return orig_langs
}
Пример #2
0
// DetectLang3 returns the best guess 3-letter language code for a given text.
func DetectLang3(text string) (string, error) {
	c := cld2.Detect(text)
	b, err := language.ParseBase(c)
	if err != nil {
		return "", err
	}
	return b.ISO3(), nil
}