Example #1
0
        public override object TransformData(IFreeDocument datas)
        {
            var text = datas[Column];
            if (text == null)
                return null;
            var pattern = "all";
            var format = "plain";
            switch (ResultType)
            {
                case ContentType.Json:
                    format = "json";
                    break;
                case ContentType.Text:
                    format = "plain";
                    break;
                case ContentType.XML:
                    format = "xml";
                    break;
                case ContentType.Byte:
                    format = "conll";
                    break;
            }
            switch (Pattern)
            {
                case Pattern.分词:
                    pattern = "ws";
                    break;
                case Pattern.词性标注:
                    pattern = "pos";
                    break;
                case Pattern.依存句法分析:
                    pattern = "dp";
                    break;
                case Pattern.语义依存分析:
                    pattern = "sdp";
                    break;
                case Pattern.语义角色标注:
                    pattern = "srl";
                    break;
                case Pattern.命名实体识别:
                    pattern = "ner";
                    break;
            }

            var param = ("api_key=" + apiKey +

                         "&pattern=" + pattern +
                         "&format=" + format+
                             "&text=" + HttpUtility.UrlEncode(text.ToString())
                         );
            var docs = buffHelper.Get(param);
            if (docs == null)
            {
                var item = new HttpItem();
                item.URL = uriBase+'?'+ param;
                item.Method = MethodType.GET;
                item.Encoding = EncodingType.UTF8;
                var helper = new HttpHelper();
                HttpStatusCode code;
                var result = helper.GetHtml(item,out code);
                if(code==HttpStatusCode.OK)
                    buffHelper.Set(param, result);
                return result;

            }
            return docs;
        }
Example #2
0
 public static HtmlDocument GetHtmlDocument(string url)
 {
     var httpitem = new HttpItem {URL = url};
     var helper = new HttpHelper();
     HttpStatusCode statusCode;
     var doc2 = helper.GetHtml(httpitem, out statusCode);
     if (statusCode != HttpStatusCode.OK)
         return null;
     var htmldoc = new HtmlDocument();
     htmldoc.LoadHtml(doc2);
     return htmldoc;
 }
Example #3
0
        public static IEnumerable<List<FreeDocument>> GetMultiDataFromURL(string url)
        {
            var httpitem = new HttpItem {URL = url};
            var helper = new HttpHelper();
            HttpStatusCode statusCode;
            var doc2 = helper.GetHtml(httpitem, out statusCode);
            if (statusCode != HttpStatusCode.OK)
                yield break;

            if (doc2 == null)
                yield return new List<FreeDocument>();
            var htmldoc = new HtmlDocument();
            htmldoc.LoadHtml(doc2);

            foreach (var item in htmldoc.GetDataFromHtml())
            {
                yield return item;
            }
        }
Example #4
0
        public static HtmlDocument GetDocumentFromURL(string url, EncodingType encoding = EncodingType.Unknown)
        {
            var httpitem = new HttpItem();
            httpitem.URL = url;

            httpitem.Encoding = encoding;
            var helper = new HttpHelper();
            HttpStatusCode code;

            var doc = new HtmlDocument();
            var result = helper.GetHtml(httpitem, out code);
            if (!HttpHelper.IsSuccess(code))
                return doc;
            doc.LoadHtml(result);
            return doc;
        }