// Languages returns the given and guessed languages // found in abstract and fulltext. Note: This is slow. // Skip detection on too short strings. func (article *Article) Languages() []string { set := container.NewStringSet() if article.Front.Article.Abstract.Lang != "" { base, err := language.ParseBase(article.Front.Article.Abstract.Lang) if err == nil { set.Add(base.ISO3()) } } vals := []string{ article.Front.Article.Abstract.Value, article.Front.Article.TranslatedAbstract.Title.Value, article.Body.Section.Value, } for _, s := range vals { if len(s) < 20 { continue } lang, err := span.DetectLang3(s) if err != nil || lang == "und" { continue } if !acceptedLanguages.Contains(lang) { continue } set.Add(lang) } return set.Values() }
// Languages returns the given and guessed languages found in abstract and // fulltext. Note: This is slow. Skip detection on too short strings. func (doc Document) Languages() []string { set := container.NewStringSet() vals := []string{doc.Title, doc.Text} for _, s := range vals { if len(s) < 20 { continue } lang, err := span.DetectLang3(s) if err != nil { continue } if !acceptedLanguages.Contains(lang) { continue } if lang == "und" { continue } set.Add(lang) } return set.Values() }