Ejemplo n.º 1
0
        protected override void Execute(CodeActivityContext context)
        {
            var text = Text.Get(context);

            string basepath = Interfaces.Extensions.DataDirectory;
            string path     = System.IO.Path.Combine(basepath, "tessdata");

            // 百度OCR
            var _ocr = new Baidu.Aip.Nlp.Nlp("SYxNNxCZXW6TaarZS2a9oeiH", "MP8OclERWqaKfSrT77majSD9QQkOhN5z");

            _ocr.Timeout = 60000;//设置超时时间
            //_ocr.Init(path, lang.ToString(), Emgu.CV.OCR.OcrEngineMode.TesseractLstmCombined);
            //_ocr.PageSegMode = Emgu.CV.OCR.PageSegMode.SparseText;

            // OpenRPA.Interfaces.Image.Util.SaveImageStamped(ele.element, "OCR");
            Bitmap sourceimg = null;


            var result = _ocr.Ecnet(text);

            context.SetValue(CorrectText, result["item"]["correct_query"].ToString());
            context.SetValue(Score, Convert.ToDouble(result["item"]["score"]));

            //IEnumerator<ImageElement> _enum = result.ToList().GetEnumerator();
            //context.SetValue(_elements, _enum);
            //bool more = _enum.MoveNext();
            //if (more)
            //{
            //    context.ScheduleAction(Body, _enum.Current, OnBodyComplete);
            //}
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 文本纠查
        /// </summary>
        /// <param name="oldstr">需要进行纠查的文本内容</param>
        /// <returns></returns>
        public static string TextCorrection(string oldstr)
        {
            string newstr = "";
            // 设置APPID/AK/SK
            var API_KEY    = "f9lW5F1dvZYnUyY0giikjG0x";
            var SECRET_KEY = "VpiaIYO9vnDq3IBuaI16fz3tGrCZpOFI";

            try
            {
                var client = new Baidu.Aip.Nlp.Nlp(API_KEY, SECRET_KEY);
                client.Timeout = 60000;            // 修改超时时间
                var result = client.Ecnet(oldstr); // 调用文本纠错,可能会抛出网络等异常,请使用try/catch捕获
                newstr = result["item"]["correct_query"].ToString();
                return(newstr);
            }
            catch (Exception e)
            {
                return("");
            }
        }
Ejemplo n.º 3
0
        protected override void Execute(CodeActivityContext context)
        {
            string text   = Text.Get(context);
            string apiKey = APIKey.Get(context);
            string seKey  = SecretKey.Get(context);

            try
            {
                var client = new Baidu.Aip.Nlp.Nlp(apiKey, seKey);
                //修改超时时间
                client.Timeout = 60000;
                //调用文本纠错
                string result = client.Ecnet(text).ToString();
                Result.Set(context, result);
            }
            catch (Exception e)
            {
                SharedObject.Instance.Output(SharedObject.enOutputType.Error, Localize.LocalizedResources.GetString("msgErrorOccurred"), e.Message);
            }
        }