public ActionResult ProcessText([FromBody] string text)
        {
            // Arabizi to arabic script
            // either direct call to perl script
            var textConverter = new TextConverter();
            // or via a php api
            // var textConverter = new ApiTextConverter();

            // SA & Entity
            var textSentimentAnalyzer = new TextSentimentAnalyzer();
            var textEntityExtraction  = new TextEntityExtraction();
            // Arabizi to arabic from perl script
            var arabicText = textConverter.Convert(text);

            // Sentiment analysis from watson https://gateway.watsonplatform.net/";
            var sentiment = textSentimentAnalyzer.GetSentiment(arabicText);

            // Entity extraction from rosette (https://api.rosette.com/rest/v1/)
            var entities = textEntityExtraction.GetEntities(arabicText);

            var result = new TextAnalyze
            {
                ArabicText = arabicText,
                Entities   = entities.ToList(),
                Sentiment  = sentiment
            };

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Example #2
0
        void GetImageUrlsComplete(string sourceHtml, string baseUrl)
        {
            string        regexString = RegexStringLib.GetFileUrlRegexString("jpg|jpeg|png|ico|bmp|gif");
            List <string> imageUrls   = TextAnalyze.GetUrlList(sourceHtml, regexString, baseUrl);

            if (imageUrls.Count > 0)
            {
                this.downloadUrlList = new List <string>();
                foreach (string url in imageUrls)
                {
                    string fullUrl = Utils.CompleteRelativeUrl(baseUrl, url);
                    this.downloadUrlList.Add(fullUrl);

                    tbxMessage.Text += string.Format("{1}{0}", Environment.NewLine, fullUrl);
                }
                MessageBox.Show(string.Format("{0} images got!", imageUrls.Count));
            }
            else
            {
                tbxMessage.Text = "no regexed";
            }
        }
Example #3
0
    private void OnLoadTextCallback(string path, byte[] bytes)
    {
        if (!mLoadHandles.ContainsKey(path))
        {
            //出现严重错误
            return;
        }
        string text = "";

        LoadHandler handle = mLoadHandles[path] as LoadHandler;

        if (handle.isXML)
        {
            text = System.Text.Encoding.UTF8.GetString(bytes);
        }
        else
        {
            text = System.Text.Encoding.Unicode.GetString(bytes);
        }

        if (string.IsNullOrEmpty(text))
        {
            return;
        }

        //Hashtable tb = new Hashtable(new CustomEqualityComparer());

        DataTable tb = new DataTable();

        if (!handle.isXML)
        {
            WDBData dbData = null;
            try
            {
                dbData = TextAnalyze.Analyze(text);
            }
            catch (Exception analyzeException)
            {
                throw new Exception("加载" + path + "失败: " + analyzeException.Message);
            }

            for (int i = 0; i < dbData.GetRecordCount(); ++i)
            {
                WDBSheetLine line = dbData.GetDataByNumber(i);

                if (line != null)
                {
                    object item = System.Activator.CreateInstance(handle.type);
                    try
                    {
                        tb.Add(loadLine(line, item, handle.keyIdx), item);
                    }
                    catch (Exception exp)
                    {
                        throw new Exception("解析" + path + "失败: " + exp.Message);
                    }
                }
            }
        }
        else
        {
            XmlDocument xDoc = new XmlDocument();
            xDoc.LoadXml(text);
            XmlNode node = xDoc.FirstChild;
            node = node.NextSibling;
            XmlNodeList nodeList = node.ChildNodes;
            for (int i = 0; i < nodeList.Count; ++i)
            {
                XmlNode childNode = nodeList[i];

                if (!string.IsNullOrEmpty(childNode.Name) &&
                    childNode.LocalName == "#comment")
                {
                    continue;
                }
                object item = System.Activator.CreateInstance(handle.type);

                Type itemType = item.GetType();
                System.Reflection.FieldInfo[] fields = itemType.GetFields();

                foreach (System.Reflection.FieldInfo f in fields)
                {
                    XmlNode nd = childNode.Attributes.GetNamedItem(f.Name);
                    if (nd != null)
                    {
                        if (f.FieldType.Name == "Int32")
                        {
                            f.SetValue(item, System.Convert.ToInt32(nd.Value));
                        }
                        if (f.FieldType.Name == "Single")
                        {
                            f.SetValue(item, System.Convert.ToSingle(nd.Value));
                        }
                        if (f.FieldType.Name == "String")
                        {
                            f.SetValue(item, nd.Value);
                        }
                    }
                }

                tb.Add(fields[0].GetValue(item), item);
            }
        }

        mLoadHandles.Remove(path);
        mTableList.Add((int)handle.dataType, tb);


        if (mLoadHandles.Count <= 0)
        {
            OnAllLoad();
        }
    }