public IEnumerable <string> Handle(string input, Match match, IListener listener) { var query = input; if (match.Groups[1].Value == "wolfram") { query = match.Groups[2].Value; } var engine = new WolframAlphaEngine(AppId); var result = engine.GetWolframAlphaQueryResult(engine.GetStringRequest(new WolframAlphaQuery() { Query = query, APIKey = AppId })); if (!result.Success) { yield return(""); } var r = ""; var answerPod = result.Pods.FirstOrDefault(o => o.Title.ToLower().Contains("result")); var interpretationPod = result.Pods.FirstOrDefault(o => o.Title.ToLower().Contains("input interpretation")); if (answerPod == null || interpretationPod == null) { yield return(""); } var interpretation = interpretationPod.SubPods[0].PodText.Replace(" |", "'s").UppercaseFirst(); var answer = answerPod.SubPods[0].PodText.RemoveExtraSpaces().Trim(); yield return(("{0} is {1}".Template(interpretation, answer)).Replace("\n", " ")); }
public Wolfram(string query) { var url = "http://api.wolframalpha.com/v2/query?input={0}&appid=2PWVJ9-9XEHHYT93V".Template(query); var doc = new XmlDocument(); doc.LoadXml(new BrowserClient().DownloadString(url)); Result = "I have no idea."; Images = new List <string>(); foreach (XmlNode node in doc.SelectNodes("//pod/subpod/img")) { Images.Add(node.Attributes["src"].Value); } try { Result = doc.SelectSingleNode("//pod[@title='Result']/subpod/plaintext").InnerText; } catch { } var engine = new WolframAlphaEngine(AppId); var result = engine.GetWolframAlphaQueryResult(engine.GetStringRequest(new WolframAlphaQuery() { Query = query, APIKey = AppId })); }
public Wolfram(string query) { var url = "http://api.wolframalpha.com/v2/query?input={0}&appid=2PWVJ9-9XEHHYT93V".Template(query); var doc = new XmlDocument(); doc.LoadXml(new BrowserClient().DownloadString(url)); Result = "I have no idea."; Images = new List<string>(); foreach (XmlNode node in doc.SelectNodes("//pod/subpod/img")) { Images.Add(node.Attributes["src"].Value); } try { Result = doc.SelectSingleNode("//pod[@title='Result']/subpod/plaintext").InnerText; } catch { } var engine = new WolframAlphaEngine(AppId); var result = engine.GetWolframAlphaQueryResult(engine.GetStringRequest(new WolframAlphaQuery() { Query = query, APIKey = AppId })); }
public void ShowAndCalculate(string query, string appkey) { this.Show(); Properties.Settings.Default.WA_RespSend++; Properties.Settings.Default.Save(); Engine = new WolframAlphaEngine(appkey);//KLQJ9W-5UU8EGQUG3 WolframAlphaQuery WAQ = new WolframAlphaQuery(); WAQ.APIKey = appkey; WAQ.MoreOutput = false; WAQ.Asynchronous = false; WAQ.AllowCaching = false; WAQ.Query = query; WAQ.TimeLimit = 30000; WAQ.Format = WolframAlphaQueryFormat.PlainText + "," + WolframAlphaQueryFormat.Image; pictureLoadAnim.Image = Properties.Resources.anim_0; loadingslide = 0; timerAnim.Start(); del = new Delegate(Engine.LoadResponse); del.BeginInvoke(WAQ, new AsyncCallback(CallBackFunc), null); }
public IEnumerable<string> Handle(string input, Match match, IListener listener) { var query = input; if (match.Groups[1].Value == "wolfram") query = match.Groups[2].Value; var engine = new WolframAlphaEngine(AppId); var result = engine.GetWolframAlphaQueryResult(engine.GetStringRequest(new WolframAlphaQuery() { Query = query, APIKey = AppId })); if (!result.Success) yield return ""; var r = ""; var answerPod = result.Pods.FirstOrDefault(o => o.Title.ToLower().Contains("result")); var interpretationPod = result.Pods.FirstOrDefault(o => o.Title.ToLower().Contains("input interpretation")); if (answerPod == null || interpretationPod == null) yield return ""; var interpretation = interpretationPod.SubPods[0].PodText.Replace(" |", "'s").UppercaseFirst(); var answer = answerPod.SubPods[0].PodText.RemoveExtraSpaces().Trim(); yield return ("{0} is {1}".Template(interpretation, answer)).Replace("\n", " "); }
public void Main(string apiKey, string WolframAlphaSearchTerms) { Engine = new WolframAlphaEngine(); //Try to delete the log file if it already exists. /*try { File.Delete(System.Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\Wolfram Alpha wrapper log.log"); } catch { }*/ //Define what our application ID is. string WolframAlphaApplicationID = "beta824g1"; //Define what we want to search for. //string WolframAlphaSearchTerms = "england"; //Print out what we're about to do in the console. Output("Getting response for the search terms \"" + WolframAlphaSearchTerms , 0, ConsoleColor.White); //Use the engine to get a response, from the application ID specified, and the search terms. //Engine.LoadResponse(WolframAlphaSearchTerms, WolframAlphaApplicationID); var query = new WolframAlphaQuery(); query.APIKey = apiKey; query.Format = "plaintext"; query.Query = WolframAlphaSearchTerms; //"england"; //"what day is today?"; //Engine.LoadResponse(WolframAlphaSearchTerms); Engine.LoadResponse(query); //Print out a message saying that the last task was successful. Output("Response injected.", 0, ConsoleColor.White); //Make 2 empty spaces in the console. Output("", 0, ConsoleColor.White); Output("Response details", 1, ConsoleColor.Blue); "Showing details for Engine: {0}".info(Engine); //Print out how many different pods that were found. Output("Pods found: " + Engine.QueryResult.NumberOfPods, 1, ConsoleColor.White); Output("Query pasing time: " + Engine.QueryResult.ParseTiming + " seconds", 1, ConsoleColor.White); Output("Query execution time: " + Engine.QueryResult.Timing + " seconds", 1, ConsoleColor.White); int PodNumber = 1; foreach (WolframAlphaPod Item in Engine.QueryResult.Pods) { //Make an empty space in the console. Output("", 0, ConsoleColor.White); Output("Pod " + PodNumber, 2, ConsoleColor.Red); Output("Sub pods found: " + Item.NumberOfSubPods, 2, ConsoleColor.White); Output("Title: \"" + Item.Title + "\"", 2, ConsoleColor.White); Output("Position: " + Item.Position, 2, ConsoleColor.White); int SubPodNumber = 1; foreach (WolframAlphaSubPod SubItem in Item.SubPods) { Output("", 0, ConsoleColor.White); Output("Sub pod " + SubPodNumber, 3, ConsoleColor.Magenta); Output("Title: \"" + SubItem.Title + "\"", 3, ConsoleColor.White); Output("Pod text: \"" + SubItem.PodText + "\"", 3, ConsoleColor.White); if (SubItem.PodImage.notNull()) { Output("Pod image title: \"" + SubItem.PodImage.Title + "\"", 3, ConsoleColor.White); Output("Pod image width: " + SubItem.PodImage.Width, 3, ConsoleColor.White); Output("Pod image height: " + SubItem.PodImage.Height, 3, ConsoleColor.White); Output("Pod image location: \"" + SubItem.PodImage.Location.ToString() + "\"", 3, ConsoleColor.White); Output("Pod image description text: \"" + SubItem.PodImage.HoverText + "\"", 3, ConsoleColor.White); } SubPodNumber += 1; } PodNumber += 1; } //Make an empty space in the console. Output("", 0, ConsoleColor.White); //Make the application stay open until there is user interaction. //Output("All content has been saved to " + System.Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\Wolfram Alpha wrapper log.log. Press a key to close the example.", 0, ConsoleColor.Green); //Console.ReadLine(); }
public void Main(string apiKey, string WolframAlphaSearchTerms) { Engine = new WolframAlphaEngine(); //Try to delete the log file if it already exists. /*try { * File.Delete(System.Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\Wolfram Alpha wrapper log.log"); * } catch { * }*/ //Define what our application ID is. string WolframAlphaApplicationID = "beta824g1"; //Define what we want to search for. //string WolframAlphaSearchTerms = "england"; //Print out what we're about to do in the console. Output("Getting response for the search terms \"" + WolframAlphaSearchTerms, 0, ConsoleColor.White); //Use the engine to get a response, from the application ID specified, and the search terms. //Engine.LoadResponse(WolframAlphaSearchTerms, WolframAlphaApplicationID); var query = new WolframAlphaQuery(); query.APIKey = apiKey; query.Format = "plaintext"; query.Query = WolframAlphaSearchTerms; //"england"; //"what day is today?"; //Engine.LoadResponse(WolframAlphaSearchTerms); Engine.LoadResponse(query); //Print out a message saying that the last task was successful. Output("Response injected.", 0, ConsoleColor.White); //Make 2 empty spaces in the console. Output("", 0, ConsoleColor.White); Output("Response details", 1, ConsoleColor.Blue); "Showing details for Engine: {0}".info(Engine); //Print out how many different pods that were found. Output("Pods found: " + Engine.QueryResult.NumberOfPods, 1, ConsoleColor.White); Output("Query pasing time: " + Engine.QueryResult.ParseTiming + " seconds", 1, ConsoleColor.White); Output("Query execution time: " + Engine.QueryResult.Timing + " seconds", 1, ConsoleColor.White); int PodNumber = 1; foreach (WolframAlphaPod Item in Engine.QueryResult.Pods) { //Make an empty space in the console. Output("", 0, ConsoleColor.White); Output("Pod " + PodNumber, 2, ConsoleColor.Red); Output("Sub pods found: " + Item.NumberOfSubPods, 2, ConsoleColor.White); Output("Title: \"" + Item.Title + "\"", 2, ConsoleColor.White); Output("Position: " + Item.Position, 2, ConsoleColor.White); int SubPodNumber = 1; foreach (WolframAlphaSubPod SubItem in Item.SubPods) { Output("", 0, ConsoleColor.White); Output("Sub pod " + SubPodNumber, 3, ConsoleColor.Magenta); Output("Title: \"" + SubItem.Title + "\"", 3, ConsoleColor.White); Output("Pod text: \"" + SubItem.PodText + "\"", 3, ConsoleColor.White); if (SubItem.PodImage.notNull()) { Output("Pod image title: \"" + SubItem.PodImage.Title + "\"", 3, ConsoleColor.White); Output("Pod image width: " + SubItem.PodImage.Width, 3, ConsoleColor.White); Output("Pod image height: " + SubItem.PodImage.Height, 3, ConsoleColor.White); Output("Pod image location: \"" + SubItem.PodImage.Location.ToString() + "\"", 3, ConsoleColor.White); Output("Pod image description text: \"" + SubItem.PodImage.HoverText + "\"", 3, ConsoleColor.White); } SubPodNumber += 1; } PodNumber += 1; } //Make an empty space in the console. Output("", 0, ConsoleColor.White); //Make the application stay open until there is user interaction. //Output("All content has been saved to " + System.Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\Wolfram Alpha wrapper log.log. Press a key to close the example.", 0, ConsoleColor.Green); //Console.ReadLine(); }