Esempio n. 1
0
        public IndexModule()
        {
            Post["/train/{classification}", true] = async(parameters, ct) =>
            {
                Corpus corpus = this.Bind();
                return(await SaveAndTrain(parameters.classification, corpus));
            };

            Get["/ptrain/{classification}", true] = async(parameters, ct) =>
            {
                var c = new Corpus();
                c.Positives.Add(this.Request.Query["input"]);
                return(await SaveAndTrain(parameters.classification, c));
            };

            Get["/ntrain/{classification}", true] = async(parameters, ct) =>
            {
                var c = new Corpus();
                c.Negatives.Add(this.Request.Query["input"]);
                return(await SaveAndTrain(parameters.classification, c));
            };

            Get["/classify/{classification}", true] = async(parameters, ct) =>
            {
                string            input = this.Request.Query["input"];
                Func <CloudTable> t     = BayesTable;
                var bb = new BinaryBayes(t, parameters.classification);
                return(await bb.Classify(input));
            };

            Get["/health"] = p => "damn right";
        }
Esempio n. 2
0
        public async Task <string> SaveAndTrain(string classification, Corpus c)
        {
            Func <CloudTable> t = BayesTable;
            var bb    = new BinaryBayes(t, classification);
            var corpi = Corpi(classification);
            await corpi.UploadTextAsync(JsonConvert.SerializeObject(c));

            return(JsonConvert.SerializeObject(await bb.Train(c)));
        }