Exemple #1
0
        public static BigInteger RandomPrime(int bitLength)
        {
            BigInteger prime            = BigInteger.Zero;
            BigInteger randomBigInteger = BigInteger.Abs(new BigInteger(RandomByteArray(bitLength)));
            string     query            = String.Format(MathHelper.WolframAlphaPrimeQuery, randomBigInteger);

            WolframAlphaService service = new WolframAlphaService(ConfigurationManager.AppSettings.Get(MathHelper.WolframAlphaAppKey));
            WolframAlphaRequest request = new WolframAlphaRequest(query);
            WolframAlphaResult  result;

            request.Formats = new List <string>()
            {
                "plaintext"
            };

            result = service.Compute(request).GetAwaiter().GetResult();

            for (int i = 0; result.QueryResult.Success && i < result.QueryResult.Pods.Count; i++)
            {
                Pod pod = result.QueryResult.Pods[i];

                if (pod.SubPods != null && pod.Title == MathHelper.WolframAlphaResultTitle)
                {
                    for (int j = 0; j < pod.SubPods.Count; j++)
                    {
                        SubPod subPod = pod.SubPods[j];

                        prime = BigInteger.Parse(subPod.Plaintext);
                    }
                }
            }

            return(prime);
        }
        public static string AskWolfram(WolframAlphaService wolfram, string input)
        {
            string alphaMessage = "";

            try
            {
                WolframAlphaRequest request = new WolframAlphaRequest(input);
                request.Formats = new List <string> {
                    Format.Plaintext
                };
                request.IncludePodIds = new List <string> {
                    "Result"
                };
                request.IgnoreCase  = true;
                request.Translation = false;
                request.Scanners    = new List <string> {
                    "Numeric", "Data", "Word"
                };
                request.GeoCoordinate = new GeoCoordinate(53.211004, 5.729472);
                request.FormatTimeout = 5;
                request.PodTimeout    = 5;
                request.Reinterpret   = true;
                request.Unit          = Unit.Metric;
                request.Async         = false;
                request.Width         = 1000;

                WolframAlphaResult result = wolfram.Compute(request).Result;

                if (result != null)
                {
                    if (result.QueryResult.Pods != null)
                    {
                        foreach (Pod pod in result.QueryResult.Pods)
                        {
                            if (pod.SubPods != null && pod.SubPods.Count > 0)
                            {
                                foreach (SubPod sub in pod.SubPods)
                                {
                                    if (!string.IsNullOrWhiteSpace(sub.Plaintext))
                                    {
                                        alphaMessage += sub.Plaintext + ", ";
                                    }
                                }
                                alphaMessage = alphaMessage.Remove(alphaMessage.Length - 2, 2);
                            }
                        }
                    }
                }
            } catch (Exception e)
            {
                Console.WriteLine(e.Message);
                alphaMessage = "";
            }

            return(alphaMessage);
        }
        private static async System.Threading.Tasks.Task WolframTestAsync()
        {
            WolframAlphaService wolfram = new WolframAlphaService(WolframAlphaHelper.API_KEY);
            WolframAlphaRequest request = new WolframAlphaRequest("integrate(2x + x ^ 2 / 12 + (x ^ 2)) dx from 0 to x")
            {
                Formats = new List <string>
                {
                    Format.Plaintext,
                    Format.MathematicaOutput,
                    Format.MathML,
                    Format.MathematicaCell
                }
            };
            WolframAlphaResult result = await wolfram.Compute(request);



            string res = "";

            if (result != null)
            {
                foreach (var pod in result.QueryResult.Pods)
                {
                    if (pod.SubPods != null)
                    {
                        Console.WriteLine(pod.Title + "----");
                        foreach (var subpod in pod.SubPods)
                        {
                            Console.WriteLine(subpod.Plaintext);
                            Console.WriteLine(subpod.Minput);
                            Console.WriteLine(subpod.Title);
                        }
                    }
                    else
                    {
                        res = "SUBPODS ERROR";
                    }
                }
            }
            else
            {
                res = "UNKNOWN ERROR";
            }

            Console.WriteLine(res);
            Console.ReadLine();
        }
Exemple #4
0
        public async void Ask()
        {
            WolframAlphaService service = new WolframAlphaService("5YAGW3-LXEQ4H8YQJ");
            WolframAlphaRequest request = new WolframAlphaRequest("Integrate e^(-x^2)2|x^3| from 2 to 5");
            WolframAlphaResult  result  = await service.Compute(request);

            StringBuilder strb = new StringBuilder();

            if (result.QueryResult.Pods != null)
            {
                var WolframImage = result.QueryResult.Pods
                                   .Where(x => x.Title == "Visual representation of the integral").First()
                                   .SubPods.First()
                                   .Image;
                BitmapImage bitmap = new BitmapImage();
                bitmap.BeginInit();
                bitmap.UriSource = new Uri(WolframImage.Src, UriKind.Absolute);
                bitmap.EndInit();

                VisualRepresentation.Width  = WolframImage.Width;
                VisualRepresentation.Source = bitmap;
            }
        }
Exemple #5
0
        public async Task AnswerQuery([Remainder] string query)
        {
            WolframAlphaService service = new WolframAlphaService("");
            WolframAlphaRequest request = new WolframAlphaRequest(query);
            WolframAlphaResult  result  = await service.Compute(request);

            string final = "";

            if (result.QueryResult.Pods != null)
            {
                final = result.QueryResult.Pods[1].SubPods[0].Plaintext.Replace("Wolfram|Alpha", "wang");
            }
            else
            {
                final = "idk";
            }

            if (final != null || final != "")
            {
                await ReplyAsync(final);
            }
            else
            {
                await ReplyAsync("idk");
            }
            //foreach (var pod in result.QueryResult.Pods)
            //{
            //    if (pod.SubPods != null)
            //    {
            //        await ReplyAsync(pod.Title);
            //        foreach (var subpod in pod.SubPods)
            //        {
            //            await ReplyAsync("    " + subpod.Plaintext);
            //        }
            //    }
            //}
        }
 public WolframAlphaHelper()
 {
     wolfram = new WolframAlphaService(API_KEY);
 }