Exemplo n.º 1
0
 public OcrConfig(string text, OCR_DATA_TYPE type, string textSplit = "")
 {
     Type  = type;
     Input = text;
 }
Exemplo n.º 2
0
        string[] ___extract_startWith(string t, string startWith_,
                                      int numberLineOutput = 1, int numberWordOutput = -1, OCR_DATA_TYPE type = OCR_DATA_TYPE.NONE)
        {
            if (string.IsNullOrEmpty(t))
            {
                return new string[] { string.Empty, string.Empty, string.Empty }
            }
            ;

            string v = "", err = "";

            try
            {
                int k = t.ToLower().IndexOf(startWith_);

                if (k != -1)
                {
                    k = k + startWith_.Length;
                    t = t.Substring(k, t.Length - k).Trim();
                    t = ___remove_startWith(t, ".");
                    t = ___remove_startWith(t, ":");

                    v = string.Join(" ", t.Split('\n').Where((x, i) => i < numberLineOutput)).Trim();

                    k = v.Length;
                    t = t.Substring(k, t.Length - k).Trim();
                    t = ___remove_startWith(t, ".");
                    t = ___remove_startWith(t, ":");
                }
            }
            catch (Exception ex)
            {
                err = ex.Message;
            }

            v = ___remove_endWith(v, ".").Trim();
            switch (type)
            {
            case OCR_DATA_TYPE.DATE_TIME_BIRTHDAY:
            case OCR_DATA_TYPE.DATE_TIME_EXPIRY:
                //v = Regex.Replace(v, @"[^\d]", " ").Trim();
                v = Regex.Replace(v, @"[^0-9]", " ").Trim();
                break;
            }

            v = ___remove_endWith(v, ".").Trim();

            if (numberWordOutput > 0)
            {
                v = string.Join(" ", v.Split(' ').Where((x, i) => i < numberWordOutput).ToArray());
            }

            // Replace multi space
            v = Regex.Replace(v, @"\s+", " ").Trim();

            switch (type)
            {
            case OCR_DATA_TYPE.DATE_TIME_BIRTHDAY:
            case OCR_DATA_TYPE.DATE_TIME_EXPIRY:
                v = v.Replace(' ', '-');
                break;
            }

            return(new string[] { v, t, err });
        }