Beispiel #1
0
        public static List <ConfidenceScore> RunCmd(string cmd, string args, string workingDir)
        {
            List <ConfidenceScore> res   = new List <ConfidenceScore>();
            ProcessStartInfo       start = new ProcessStartInfo();

            start.FileName               = @"C:\Users\gerhas\AppData\Local\Programs\Python\Python37\python.exe";
            start.Arguments              = string.Format("\"{0}\" \"{1}\"", cmd, args);
            start.UseShellExecute        = false; // Do not use OS shell
            start.WorkingDirectory       = workingDir;
            start.CreateNoWindow         = true;  // We don't need new window
            start.RedirectStandardOutput = true;  // Any output, generated by application will be redirected back
            start.RedirectStandardError  = true;  // Any error in standard output will be redirected back (for example exceptions)
            using (Process process = Process.Start(start))
            {
                using (StreamReader reader = process.StandardOutput)
                {
                    string stderr = process.StandardError.ReadToEnd(); // Here are the exceptions from our Python script
                    while (!reader.EndOfStream)
                    {
                        string          tag        = reader.ReadLine();
                        string          confidence = reader.ReadLine();
                        ConfidenceScore s          = new ConfidenceScore();
                        s.Hashtag    = tag;
                        s.Confidence = float.Parse(confidence);
                        res.Add(s);
                    }
                    return(res);
                }
            }
        }
Beispiel #2
0
        public static List <ConfidenceScore> GetConfidenceFromServer()
        {
            List <ConfidenceScore> res = new List <ConfidenceScore>();

            var    client              = new HttpClient();
            var    definition          = new[] { new { confidence = 0.0, hashtag = "" } };
            string jsonContent         = client.GetStringAsync("http://127.0.0.1:5000/recipes").Result;
            Root   myDeserializedClass = JsonConvert.DeserializeObject <Root>(jsonContent);

            foreach (var x in myDeserializedClass.Table1)
            {
                ConfidenceScore s = new ConfidenceScore();
                s.Confidence = x[0].confidence;
                s.Hashtag    = x[0].hashtag;
                res.Add(s);
            }

            return(res);
        }