public static bool CheckDerivative2(string expression, string derivative) { try { WolframAlpha wolfram = new WolframAlpha(ConfigurationManager.AppSettings["WolframAlphaAppId"]); QueryResult result = wolfram.Query("diff(" + expression + ")"); string answer = result.Pods[0].SubPods[0].Plaintext; string answerDer = answer.Remove(0, answer.IndexOf(" = ") + 3).Trim().Replace(" ", ""); result = wolfram.Query(derivative); var pod = result.GetPrimaryPod(); if (answerDer == pod.SubPods[0].Plaintext.Replace(" ", "")) return true; pod = result.Pods.Where(p => p.ID == "AlternateForm").FirstOrDefault(); return answerDer == pod.SubPods[0].Plaintext.Replace(" ", ""); } catch { return false; } }
private string QueryWolfram(string input) { WolframAlpha wolfram = new WolframAlpha("RQJPTG-976HAP24AX"); QueryResult results = wolfram.Query("cost of living index " + input); return(results != null?results.Pods.ToList().Last().SubPods.ToList().Last().Plaintext : "Data not Available"); }
public JarvisResponse Handle(JarvisIntent intent) { var o = intent.Intent.BestOutcome; var query = o.GetFirstString("wolfram_search_query").Value; var w = new WolframAlpha("8GXWYP-Q8TLWGUH4H"); w.Formats = new List <Format>() { Format.Plaintext }; w.ScanTimeout = 0.1f; var results = w.Query(query); if (results != null) { var result = results.Pods.Find((p) => p.Title == "Result"); if (result != null) { return(new JarvisResponse(ProcessOutput(result.SubPods.First().Plaintext))); } else { var pods = results.RecalculateResults(); var newResult = pods.Find((p) => p.Title == "Result"); if (newResult != null) { return(new JarvisResponse(ProcessOutput(newResult.SubPods.First().Plaintext))); } } } return(JarvisResponse.Unknown); }
public void ValidateQueryTest() { WolframAlpha wolframAlpha = new WolframAlpha(_appId); //We put in a lot of parameters wolframAlpha.EnableTranslate = true; wolframAlpha.MaxWidth = 200; wolframAlpha.OutputUnit = Unit.NonMetric; wolframAlpha.ExcludePodIDs.Add("NonExistingId"); wolframAlpha.PodIndex.AddRange(new[] { 1, 2, 3, 4, 5, 6, 7, 8 }); wolframAlpha.FormatTimeout = 5; wolframAlpha.Formats.Add(Format.MathML); wolframAlpha.Formats.Add(Format.Wav); wolframAlpha.Formats.Add(Format.Plaintext); wolframAlpha.GPSLocation = new GeoCoordinate(40.42, -3.70); wolframAlpha.IgnoreCase = true; wolframAlpha.Magnification = 2.0f; wolframAlpha.Width = 300; wolframAlpha.ParseTimeout = 5; wolframAlpha.ScanTimeout = 1; wolframAlpha.UseAsync = true; wolframAlpha.ReInterpret = true; wolframAlpha.PlotWidth = 200; wolframAlpha.PodTimeout = 5; ValidateQueryResult results; const bool expected = true; bool actual = wolframAlpha.ValidateQuery("PI", out results); Assert.IsNotNull(results); Assert.AreEqual(expected, actual); }
protected override Task <IEnumerable <IReply> > OnInvoke(TelegramMessageEventArgs input) { string expression = input.Message.Text.Substring(1); WolframAlpha wolfram = new WolframAlpha(ApiToken); QueryResult results = wolfram.Query(expression); if (results == null) { return(Task.FromResult(Nothing)); } var sb = new StringBuilder(); foreach (var pod in results.Pods) { sb.AppendLine(pod.Title); if (pod.SubPods == null) { continue; } foreach (var subPod in pod.SubPods) { sb.AppendLine(subPod.Title); sb.AppendLine(subPod.Plaintext); } } return(FromResult(new TextReply(sb.ToString()))); }
static void Main(string[] args) { //Create the Engine. WolframAlpha wolfram = new WolframAlpha(_appId); wolfram.ScanTimeout = 0.1f; //We set ScanTimeout really low to get a quick answer. See RecalculateResults() below. wolfram.UseTLS = true; //Use encryption //We search for something. Notice that we spelled it wrong. QueryResult results = wolfram.Query("Who is Danald Duck?"); //This fetches the pods that did not complete. It is only here to show how to use it. //This returns the pods, but also adds them to the original QueryResults. results.RecalculateResults(); //Here we output the Wolfram|Alpha results. if (results.Error != null) { Console.WriteLine("Woops, where was an error: " + results.Error.Message); } if (results.DidYouMean.HasElements()) { foreach (DidYouMean didYouMean in results.DidYouMean) { Console.WriteLine("Did you mean: " + didYouMean.Value); } } Console.WriteLine(); //Results are split into "pods" that contain information. Those pods can also have subpods. Pod primaryPod = results.GetPrimaryPod(); if (primaryPod != null) { Console.WriteLine(primaryPod.Title); if (primaryPod.SubPods.HasElements()) { foreach (SubPod subPod in primaryPod.SubPods) { Console.WriteLine(subPod.Title); Console.WriteLine(subPod.Plaintext); } } } if (results.Warnings != null) { if (results.Warnings.Translation != null) { Console.WriteLine("Translation: " + results.Warnings.Translation.Text); } if (results.Warnings.SpellCheck != null) { Console.WriteLine("Spellcheck: " + results.Warnings.SpellCheck.Text); } } }
public static bool CheckDerivative2(string expression, string derivative) { try { WolframAlpha wolfram = new WolframAlpha(ConfigurationManager.AppSettings["WolframAlphaAppId"]); QueryResult result = wolfram.Query("diff(" + expression + ")"); string answer = result.Pods[0].SubPods[0].Plaintext; string answerDer = answer.Remove(0, answer.IndexOf(" = ") + 3).Trim().Replace(" ", ""); result = wolfram.Query(derivative); var pod = result.GetPrimaryPod(); if (answerDer == pod.SubPods[0].Plaintext.Replace(" ", "")) { return(true); } pod = result.Pods.Where(p => p.ID == "AlternateForm").FirstOrDefault(); return(answerDer == pod.SubPods[0].Plaintext.Replace(" ", "")); } catch { return(false); } }
public void ValidateQueryTest() { WolframAlpha wolframAlpha = new WolframAlpha(_appId); //We put in a lot of parameters wolframAlpha.EnableTranslate = true; wolframAlpha.MaxWidth = 200; wolframAlpha.OutputUnit = Unit.NonMetric; wolframAlpha.ExcludePodIDs.Add("NonExistingId"); wolframAlpha.PodIndex.AddRange(new[] { 1, 2, 3, 4, 5, 6, 7, 8 }); wolframAlpha.FormatTimeout = 5; wolframAlpha.Formats.Add(Format.MathML); wolframAlpha.Formats.Add(Format.Wav); wolframAlpha.Formats.Add(Format.Plaintext); wolframAlpha.GPSLocation = new GeoCoordinate(40.42, -3.70); wolframAlpha.IgnoreCase = true; wolframAlpha.Magnification = 2.0f; wolframAlpha.Width = 300; wolframAlpha.ParseTimeout = 5; wolframAlpha.ScanTimeout = 1; wolframAlpha.UseAsync = true; wolframAlpha.ReInterpret = true; wolframAlpha.PlotWidth = 200; wolframAlpha.PodTimeout = 5; const bool expected = true; bool actual = wolframAlpha.ValidateQuery("PI", out var results); Assert.NotNull(results); Assert.Equal(expected, actual); }
static void Main(string[] args) { //Create the Engine. WolframAlpha wolfram = new WolframAlpha(_appId); wolfram.ScanTimeout = 0.1f; //We set ScanTimeout really low to get a quick answer. See RecalculateResults() below. wolfram.UseTLS = true; //Use encryption //We search for something. Notice that we spelled it wrong. QueryResult results = wolfram.Query("Who is Danald Duck?"); //This fetches the pods that did not complete. It is only here to show how to use it. //This returns the pods, but also adds them to the original QueryResults. results.RecalculateResults(); //Here we output the Wolfram|Alpha results. if (results.Error != null) Console.WriteLine("Woops, where was an error: " + results.Error.Message); if (results.DidYouMean.HasElements()) { foreach (DidYouMean didYouMean in results.DidYouMean) { Console.WriteLine("Did you mean: " + didYouMean.Value); } } Console.WriteLine(); //Results are split into "pods" that contain information. Those pods can also have subpods. Pod primaryPod = results.GetPrimaryPod(); if (primaryPod != null) { Console.WriteLine(primaryPod.Title); if (primaryPod.SubPods.HasElements()) { foreach (SubPod subPod in primaryPod.SubPods) { Console.WriteLine(subPod.Title); Console.WriteLine(subPod.Plaintext); } } } if (results.Warnings != null) { if (results.Warnings.Translation != null) Console.WriteLine("Translation: " + results.Warnings.Translation.Text); if (results.Warnings.SpellCheck != null) Console.WriteLine("Spellcheck: " + results.Warnings.SpellCheck.Text); } Console.ReadLine(); }
public void WolframAlphaConstructorTest() { WolframAlpha wolfram = new WolframAlpha(_appId); Assert.IsNotNull(wolfram.Assumptions); Assert.IsNotNull(wolfram.ExcludePodIDs); Assert.IsNotNull(wolfram.Formats); Assert.IsNotNull(wolfram.IncludePodIDs); Assert.IsNotNull(wolfram.PodTitles); Assert.IsNotNull(wolfram.PodIndex); Assert.IsNotNull(wolfram.Scanners); }
public Form1() { InitializeComponent(); plotter = new Plotter(); wolfram = new WolframAlpha("HVTG5G-R85WWR978J"); this.Bounds = Screen.PrimaryScreen.Bounds; // fill up the whole screen graphPictureBox.SizeMode = PictureBoxSizeMode.AutoSize; // for being able to scroll the graph window polynomialPoints = new List <DataPoint> (); }
public void WolframAlphaConstructorTest() { WolframAlpha wolfram = new WolframAlpha(_appId); Assert.NotNull(wolfram.Assumptions); Assert.NotNull(wolfram.ExcludePodIDs); Assert.NotNull(wolfram.Formats); Assert.NotNull(wolfram.IncludePodIDs); Assert.NotNull(wolfram.PodTitles); Assert.NotNull(wolfram.PodIndex); Assert.NotNull(wolfram.Scanners); }
public WolframAlphaPlugin( IBotServices services, BotConfig config) : base( services, config) { string configFile = Path.Combine(Environment.CurrentDirectory, "Wolfram.ini"); string appId = LoadConfig(configFile); this.mWolframAlpha = new WolframAlpha(appId); this.mWolframAlpha.ScanTimeout = cScanTimeout; }
public static double GetValue(string expression, params KeyValuePair<string, double>[] values) { StringBuilder request = new StringBuilder(expression + " where "); foreach (var value in values) request.AppendFormat("{0}={1};", value.Key, value.Value.ToString(CultureInfo.InvariantCulture)); if (values.Length > 0) request.Remove(request.Length - 1, 1); WolframAlpha wolfram = new WolframAlpha(ConfigurationManager.AppSettings["WolframAlphaAppId"]); QueryResult response = wolfram.Query(request.ToString()); var pod = response.GetPrimaryPod(); return double.Parse(pod.SubPods[0].Plaintext, CultureInfo.InvariantCulture); }
public void SearchTest() { WolframAlpha wolframAlpha = new WolframAlpha(_appId); const string expectedPIApproximation = "3.1415926535897932384626433832795028841971693993751058..."; QueryResult actual = wolframAlpha.Query("PI"); Assert.IsNotNull(actual); //Get the interesting subpod string actualPIApproximation = QueryResultHelper.GetPrimaryPod(actual).SubPods.First().Plaintext; Assert.AreEqual(expectedPIApproximation, actualPIApproximation); }
public override void Invoke(Object sender, OnUserCommandReceivedArgs e) { var request = String.Join(' ', e.Words); var result = WolframAlpha.Query(request); if (result.Success) { var pod = result.Pods.FirstOrDefault(pod => pod.Title == "Result" || pod.Title == "Wikipedia summary"); if (pod != null && pod.SubPods != null) { StringBuilder messageBuilder = new(); messageBuilder.Append(e.ChatMessage.DisplayName); messageBuilder.Append(' '); if (pod.Title == "Result") { foreach (var subpod in pod.SubPods) { messageBuilder.Append(subpod.Plaintext); } } else { StringBuilder wikipediaEntryBuilder = new(); foreach (var subpod in pod.SubPods) { wikipediaEntryBuilder.Append(subpod.Plaintext); wikipediaEntryBuilder.Append(' '); } var match = FirstSentenceRegex.Match(wikipediaEntryBuilder.ToString()); if (match.Success) { messageBuilder.Append(match.Value); } } TwitchClientManager.SpoolMessage(messageBuilder.ToString()); } } else { TwitchClientManager.SpoolMessage(e.ChatMessage.DisplayName + " Could not query WolframAlpha successfully."); } }
public void SearchTest() { WolframAlpha wolframAlpha = new WolframAlpha(_appId); const string expectedPIApproximation = "3.141592653589793238462643383279502884197169399375105820974..."; QueryResult actual = wolframAlpha.Query("PI"); Assert.NotNull(actual); //Get the interesting subpod string actualPIApproximation = actual.GetPrimaryPod().SubPods.First().Plaintext; Assert.Equal(expectedPIApproximation, actualPIApproximation); }
public QueryResult Query(string text) { var key = this.config.Get("WolframAlphaApiKey"); if (string.IsNullOrWhiteSpace(key)) { throw new InvalidOperationException("No Api Key"); } if (string.IsNullOrWhiteSpace(text)) { return null; } WolframAlpha wolfram = new WolframAlpha(key); wolfram.Formats.Add(Format.Plaintext); return wolfram.Query(text); // string queryResult = string.Empty; // // if (results != null) // { // if (!results.Pods.Any()) // { // queryResult = "No Results"; // } // // foreach (Pod pod in results.Pods) // { // queryResult += pod.Title + Environment.NewLine; // if (pod.SubPods != null) // { // foreach (SubPod subPod in pod.SubPods) // { // queryResult += subPod.Title + Environment.NewLine; // queryResult += subPod.Plaintext + Environment.NewLine; // } // } // queryResult += Environment.NewLine; // } // } // else // { // queryResult = "No Results"; // } // // return queryResult; }
public Wolfram() { StreamReader sr = null; try { sr = new StreamReader(AppDomain.CurrentDomain.BaseDirectory + "wolframapikey.txt"); wolfram = new WolframAlpha(sr.ReadLine()); } catch { throw new Exception("API Key not found or not valid at: " + AppDomain.CurrentDomain.BaseDirectory + "wolframapikey.txt"); } finally { sr.Close(); } }
public void EnableTranslateTest() { //First try without translation WolframAlpha wolframAlpha = new WolframAlpha(_appId); wolframAlpha.EnableTranslate = false; QueryResult negativeResults = wolframAlpha.Query("uno dos tres"); Assert.IsNull(negativeResults.Warnings); //Then try with translation wolframAlpha.EnableTranslate = true; QueryResult positiveResults = wolframAlpha.Query("uno dos tres"); const string expectedOutput = "one two three"; const string expectedLanguage = "Spanish"; Assert.IsNotNull(positiveResults.Warnings.Translation); Assert.AreEqual(expectedOutput, positiveResults.Warnings.Translation.TranslatedText); Assert.AreEqual(expectedLanguage, positiveResults.Warnings.Translation.Language); }
public static bool CheckEquality(string expression1, string expression2) { WolframAlpha wolfram = new WolframAlpha(ConfigurationManager.AppSettings["WolframAlphaAppId"]); string query = "(" + expression1.Replace(" ", "") + ")-(" + expression2.Replace(" ", "") + ")"; QueryResult result = wolfram.Query(query); result.RecalculateResults(); try { double d; return double.TryParse(result.GetPrimaryPod().SubPods[0].Plaintext, out d) && d == 0.0; } catch { return false; } }
public static bool CheckEquality(string expression1, string expression2) { WolframAlpha wolfram = new WolframAlpha(ConfigurationManager.AppSettings["WolframAlphaAppId"]); string query = "(" + expression1.Replace(" ", "") + ")-(" + expression2.Replace(" ", "") + ")"; QueryResult result = wolfram.Query(query); result.RecalculateResults(); try { return(double.TryParse(result.GetPrimaryPod().SubPods[0].Plaintext, out double d) && d == 0.0); } catch { return(false); } }
public static double GetValue(string expression, params KeyValuePair <string, double>[] values) { StringBuilder request = new StringBuilder(expression + " where "); foreach (var value in values) { request.AppendFormat("{0}={1};", value.Key, value.Value.ToString(CultureInfo.InvariantCulture)); } if (values.Length > 0) { request.Remove(request.Length - 1, 1); } WolframAlpha wolfram = new WolframAlpha(ConfigurationManager.AppSettings["WolframAlphaAppId"]); QueryResult response = wolfram.Query(request.ToString()); var pod = response.GetPrimaryPod(); return(double.Parse(pod.SubPods[0].Plaintext, CultureInfo.InvariantCulture)); }
public static bool CheckEquality(string expression1, string expression2) { Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; WolframAlpha wolfram = new WolframAlpha(WolframAlphaAppId); string query = "(" + expression1.Replace(" ", "") + ")-(" + expression2.Replace(" ", "") + ")"; QueryResult result = wolfram.Query(query); result.RecalculateResults(); try { return(double.TryParse(result.GetPrimaryPod().SubPods[0].Plaintext, NumberStyles.Any, CultureInfo.InvariantCulture, out double d) && d == 0.0); } catch { return(false); } }
public void EnableTranslateTest() { //First try without translation WolframAlpha wolframAlpha = new WolframAlpha(_appId); wolframAlpha.EnableTranslate = false; QueryResult negativeResults = wolframAlpha.Query("uno dos tres"); Assert.Null(negativeResults.Warnings); //Then try with translation wolframAlpha.EnableTranslate = true; QueryResult positiveResults = wolframAlpha.Query("uno dos tres"); const string expectedOutput = "one two three"; const string expectedLanguage = "Spanish"; Assert.NotNull(positiveResults.Warnings.Translation); Assert.Equal(expectedOutput, positiveResults.Warnings.Translation.TranslatedText); Assert.Equal(expectedLanguage, positiveResults.Warnings.Translation.Language); }
public WolframAlphaPlugin( IMtgStore store, ICardPriceStore priceStore, ICommandParser commandParser, IHttpClient httpClient, IUrlShortener urlShortener, BotConfig config) : base( store, priceStore, commandParser, httpClient, urlShortener, config) { string configFile = Path.Combine(Environment.CurrentDirectory, "Wolfram.ini"); string appId = LoadConfig(configFile); this.mWolframAlpha = new WolframAlpha(appId); this.mWolframAlpha.ScanTimeout = cScanTimeout; }
public async Task <EventHandledResponse> Handle(EventMetaData data, AppMentionEvent message) { var messageText = message.Text.Replace($"wolf ", ""); var wolfram = new WolframAlpha(_options.Value.WulframAlphaAppId); var results = wolfram.Query(messageText); var text = ""; if (results != null) { foreach (var pod in results.Pods) { if (pod.SubPods != null) { foreach (var subPod in pod.SubPods) { if (!string.IsNullOrEmpty(subPod.Title)) { text += $"•{subPod.Title}\n"; } text += $"{subPod.Plaintext} \n"; text += $"\n"; } } } } if (string.IsNullOrEmpty(text)) { text = "Wulf aner ikke 🐺"; } await _client.ChatPostMessage(message.Channel, text); return(new EventHandledResponse("OK")); }
private string GeneratePrimeNumber() { WolframAlpha wolfram = new WolframAlpha("H6JLXP-RJ7Y7RVPPE"); try { var queryResult = wolfram.Query("nextPrime[2^1022 + RandomInteger(2^1023)]"); if (queryResult == null) { throw new Exception("Нет доступа в интернет"); } if (queryResult.Error != null) { throw new Exception(queryResult.Error.Message); } string result = queryResult?.Pods[1]?.SubPods[0]?.Plaintext; return(result); } catch (Exception) { throw; } }
public Wolfram(ITwitchClientManager client, TextWriter console, WolframAlpha wolfram) : base(client, console) { WolframAlpha = wolfram; FirstSentenceRegex = new Regex(FirstSentencePattern, RegexOptions.Compiled); }