func ProcessImage(path string) (int, int, int, int) { loadDictionary("/usr/share/dict/words") text := gosseract.Must(gosseract.Params{Src: path}) totalCharacters := len(text) text = strings.TrimSpace(text) words := strings.Fields(text) util.Log(fmt.Sprintf("Text: %s\n", text)) alpha, nonAlpha := analyzeWords(words) hasMoreAlpha := hasMoreAlphaCharacters(alpha, nonAlpha) if hasMoreAlpha { util.Log("hasMoreAlphaCharacters") } dictionaryWords := 0 for _, word := range words { if hasMoreAlpha { if isInDictionary(word) { dictionaryWords++ util.Log(fmt.Sprintf("isInDictionary: %s\n", word)) } } } return alpha, nonAlpha, totalCharacters, dictionaryWords }
func analyzeWords(words []string) (int, int) { alpha := 0 nonAlpha := 0 for _, word := range words { re := regexp.MustCompile("[a-zA-Z]") for _, c := range word { comp := []byte(string(c)) if re.Match(comp) { alpha++ } else { nonAlpha++ } } } util.Log(fmt.Sprintf("Alpha: %d NonAlpha: %d\n", alpha, nonAlpha)) return alpha, nonAlpha }