Exemple #1
0
        //public static string ClassifyXML(string text, string classifierName="Cuisines")
        //{
        //    var bytes = Encoding.UTF8.GetBytes(text);
        //    var base64 = Convert.ToBase64String(bytes);
        //    var ns = XNamespace.Get("http://api.uclassify.com/1/RequestSchema");
        //    XDocument miXML = new XDocument(
        //        new XDeclaration("1.0", "utf-8", null),
        //        new XElement(ns + "uclassify",
        //            new XAttribute("version", "1.01"),
        //                new XElement(ns + "texts",
        //                    new XElement(ns + "textBase64",
        //                        new XAttribute("id", "TextId"),
        //                        base64
        //                    )
        //                ),
        //                new XElement(ns + "readCalls",
        //                    new XAttribute("readApiKey", readApiKey),
        //                    new XElement(ns + "classify",
        //                            new XAttribute("id", "Classify"),
        //                            new XAttribute("classifierName", classifierName),
        //                            new XAttribute("textId", "TextId")
        //                    )
        //                )
        //        )
        //    );
        //    return miXML.ToString();
        //}
        public static string BuildClassifyXML(string text, string classifierName = "Cuisines")
        {
            var request = new Models.Request.uclassify();
            request.version = decimal.Parse("1,01");
            var readCallList = new Models.Request.ReadCallList();
            readCallList.readApiKey = readApiKey;

            request.texts = new Models.Request.TextList();
            Models.Request.TextBase64 textBase64 = new Models.Request.TextBase64();
            textBase64.id = "APIText";
            var bytes = Encoding.UTF8.GetBytes(text);
            textBase64.Value = Convert.ToBase64String(bytes);
            request.texts = new Models.Request.TextList();
            request.texts.textBase64 = new Models.Request.TextBase64[1];
            request.texts.textBase64[0] = textBase64;

            var classify = new Models.Request.Classify();
            classify.classifierName = classifierName;
            classify.id = "Classify";
            classify.textId = "APIText";
            readCallList.classify = new Models.Request.Classify[1];
            readCallList.classify[0] = classify;

            request.Item = readCallList;

            var ser = new XmlSerializer(typeof(Models.Request.uclassify));
            StringWriter textWriter = new StringWriter();
            ser.Serialize(textWriter, request);

            string requestStr = textWriter.ToString();

            return requestStr;
        }
Exemple #2
0
        public static string BuildUntrainXML(string text, string className, string classifierName = "Cuisines")
        {
            var request = new Models.Request.uclassify();
            request.version = decimal.Parse("1,01");
            var writeCallList = new Models.Request.WriteCallList();
            writeCallList.writeApiKey = writeApiKey;
            writeCallList.classifierName = classifierName;

            request.texts = new Models.Request.TextList();
            Models.Request.TextBase64 textBase64 = new Models.Request.TextBase64();
            textBase64.id = "APIText";
            var bytes = Encoding.UTF8.GetBytes(text);
            textBase64.Value = Convert.ToBase64String(bytes);
            request.texts = new Models.Request.TextList();
            request.texts.textBase64 = new Models.Request.TextBase64[1];
            request.texts.textBase64[0] = textBase64;

            var untrain = new Models.Request.Untrain();
            untrain.className = className;
            untrain.id = "Untrain";
            untrain.textId = "APIText";
            writeCallList.untrain = new Models.Request.Untrain[1];
            writeCallList.untrain[0] = untrain;

            request.Item = writeCallList;

            var ser = new XmlSerializer(typeof(Models.Request.uclassify));
            StringWriter textWriter = new StringWriter();
            ser.Serialize(textWriter, request);

            string requestStr = textWriter.ToString();

            return requestStr;
        }