Exemplo n.º 1
0
        public async Task IncludeExcludePodTest()
        {
            FullResultRequest req = new FullResultRequest("pi");

            FullResultResponse res = await Client.FullResultAsync(req).ConfigureAwait(false);

            Assert.NotEmpty(res.Pods);

            int orgPodCount = res.Pods.Count;

            Pod decApprox = res.Pods.Single(x => x.Title == "Decimal approximation");

            req.IncludePodIds.Add(decApprox.Id);

            res = await Client.FullResultAsync(req).ConfigureAwait(false);

            Assert.Single(res.Pods);

            req.IncludePodIds.Clear();
            req.ExcludePodIds.Add(decApprox.Id);

            res = await Client.FullResultAsync(req).ConfigureAwait(false);

            Assert.Equal(orgPodCount - 1, res.Pods.Count);
        }
Exemplo n.º 2
0
        public async Task FutureTopicTest()
        {
            FullResultResponse res = await Client.FullResultAsync("Microsoft Windows").ConfigureAwait(false);

            Assert.Equal("Operating Systems", res.FutureTopic.Topic);
            Assert.Equal("Development of this topic is under investigation...", res.FutureTopic.Message);
        }
Exemplo n.º 3
0
        public async Task DidYouMeanTest()
        {
            FullResultResponse resp = await Client.FullResultAsync("This is a confusing query it in french").ConfigureAwait(false);

            Assert.False(resp.IsSuccess);
            Assert.False(resp.IsError);

            Assert.Equal(4, resp.DidYouMeans.Count);

            HashSet <Level> levels = new HashSet <Level>();

            levels.Add(Level.Low);
            levels.Add(Level.Medium);
            levels.Add(Level.High);

            Assert.NotEqual(0, resp.DidYouMeans[0].Score);
            Assert.Contains(resp.DidYouMeans[0].Level, levels);
            Assert.NotEmpty(resp.DidYouMeans[0].Value);

            Assert.NotEqual(0, resp.DidYouMeans[1].Score);
            Assert.Contains(resp.DidYouMeans[1].Level, levels);
            Assert.NotEmpty(resp.DidYouMeans[1].Value);

            Assert.NotEqual(0, resp.DidYouMeans[2].Score);
            Assert.Contains(resp.DidYouMeans[2].Level, levels);
            Assert.NotEmpty(resp.DidYouMeans[2].Value);

            Assert.NotEqual(0, resp.DidYouMeans[3].Score);
            Assert.Contains(resp.DidYouMeans[3].Level, levels);
            Assert.NotEmpty(resp.DidYouMeans[3].Value);
        }
Exemplo n.º 4
0
        public async Task DelimitersTest()
        {
            FullResultResponse res = await Client.FullResultAsync("sin(x").ConfigureAwait(false);

            Warning warning = Assert.Single(res.Warnings);

            Assert.Equal("An attempt was made to fix mismatched parentheses, brackets, or braces.", warning.Delimiters.Text);
        }
Exemplo n.º 5
0
        public async Task ExamplePageTest()
        {
            FullResultRequest req = new FullResultRequest("electromagnetic wave");

            FullResultResponse res = await Client.FullResultAsync(req).ConfigureAwait(false);

            Assert.Equal("ElectricityAndMagnetism", res.ExamplePage.Category);
            Assert.NotNull(res.ExamplePage.Url);
        }
Exemplo n.º 6
0
        /// <summary>Gets the primary pod</summary>
        public static Pod GetPrimaryPod(this FullResultResponse response)
        {
            if (response.Pods.HasElements())
            {
                return(response.Pods.FirstOrDefault(pod => pod.IsPrimary));
            }

            return(null);
        }
Exemplo n.º 7
0
        public async Task GeneralizationsTest()
        {
            FullResultRequest req = new FullResultRequest("price of copernicium");

            FullResultResponse res = await Client.FullResultAsync(req).ConfigureAwait(false);

            Assert.Equal("copernicium", res.Generalization.Topic);
            Assert.Equal("General results for:", res.Generalization.Description);
            Assert.NotNull(res.Generalization.Url);
        }
Exemplo n.º 8
0
        public async Task LanguageMessageTest()
        {
            FullResultResponse res = await Client.FullResultAsync("wo noch nie").ConfigureAwait(false);

            Assert.Equal("Wolfram|Alpha does not yet support German.", res.LanguageMessage.English);
            Assert.Equal("Wolfram|Alpha versteht noch kein Deutsch.", res.LanguageMessage.Other);

            Tip tip = Assert.Single(res.Tips);

            Assert.Equal("Try spelling out abbreviations", tip.Text);
        }
Exemplo n.º 9
0
        public async Task ScannerFilterTest()
        {
            FullResultRequest req = new FullResultRequest("pi");

            req.Scanners.Add("Numeric");

            FullResultResponse res = await Client.FullResultAsync(req).ConfigureAwait(false);

            //There are 2 scanners with numeric.
            Assert.Equal(2, res.Pods.Count);
        }
Exemplo n.º 10
0
        public async Task ErrorTest()
        {
            Config.AppId = "AAAAAA-AAAAAAAAAA";

            FullResultResponse res = await Client.FullResultAsync("does not matter").ConfigureAwait(false);

            Assert.False(res.IsSuccess);
            Assert.True(res.IsError);

            Assert.Equal(1, res.ErrorDetails.Code);
            Assert.Equal("Invalid appid", res.ErrorDetails.Message);
        }
Exemplo n.º 11
0
        public async Task SpellCheckTest()
        {
            FullResultResponse res = await Client.FullResultAsync("wolframalpa").ConfigureAwait(false);

            Assert.True(res.IsSuccess);
            Assert.False(res.IsError);

            Warning warning = Assert.Single(res.Warnings);

            Assert.Equal("wolframalpa", warning.SpellCheck.Word);
            Assert.Equal("wolframalpha", warning.SpellCheck.Suggestion);
            Assert.Equal("Interpreting \"wolframalpa\" as \"wolframalpha\"", warning.SpellCheck.Text);
        }
Exemplo n.º 12
0
        public async Task PodIndexTest()
        {
            FullResultRequest req = new FullResultRequest("pi");

            req.PodIndex.Add(1);
            req.PodIndex.Add(2);

            FullResultResponse res = await Client.FullResultAsync(req).ConfigureAwait(false);

            Assert.NotEmpty(res.Pods);

            //There is usually 8, we only asked for 2.
            Assert.Equal(2, res.Pods.Count);
        }
Exemplo n.º 13
0
        public async Task AssumptionsTest()
        {
            FullResultRequest req = new FullResultRequest("Pi");

            req.Assumptions.Add("*C.Pi-_*Movie-");

            FullResultResponse res = await Client.FullResultAsync(req).ConfigureAwait(false);

            Assert.True(res.IsSuccess);

            Pod resultPod = res.Pods.Single(x => x.Title == "Input interpretation");

            Assert.Equal("Pi (movie)", resultPod.SubPods[0].Plaintext);
        }
        public async Task SoundFormatTest()
        {
            FullResultRequest req = new FullResultRequest("Doppler shift 300Hz, 75mph");

            req.Formats = Format.Plaintext | Format.Image | Format.Sound;

            FullResultResponse resp = await Client.FullResultAsync(req).ConfigureAwait(false);

            Pod audibleFreq = resp.Pods.Single(x => x.Title == "Audible frequencies");

            Sound sound = Assert.Single(audibleFreq.Sounds);

            Assert.NotNull(sound.Url);
            Assert.NotEmpty(sound.Type);
        }
        public async Task HtmlFormatTest()
        {
            FullResultRequest req = new FullResultRequest("bill gates");

            req.Formats = Format.Html;

            FullResultResponse res = await Client.FullResultAsync(req).ConfigureAwait(false);

            Assert.NotEmpty(res.Scripts);
            Assert.NotEmpty(res.Css);

            foreach (Pod pod in res.Pods)
            {
                Assert.NotEmpty(pod.Markup);
            }
        }
        public async Task MInputFormatTest()
        {
            FullResultRequest req = new FullResultRequest("pi");

            req.Formats = Format.Minput | Format.Moutput;

            FullResultResponse res = await Client.FullResultAsync(req).ConfigureAwait(false);

            Assert.True(res.IsSuccess);

            Pod    propertyPod = res.Pods.Single(x => x.Title == "Property");
            SubPod subPod      = Assert.Single(propertyPod.SubPods);

            Assert.Equal("Element[Pi, Algebraics]", subPod.MInput);
            Assert.Equal("False", subPod.MOutput);
        }
Exemplo n.º 17
0
        public async Task Wolfram([Remainder] string text)
        {
            string             wolframToken = _config["tokens:wolframalpha"];
            WolframAlphaClient client       = new WolframAlphaClient(wolframToken);


            FullResultRequest request = new FullResultRequest(text);

            request.ScanTimeout = 8;

            FullResultResponse results = await client.FullResultAsync(request).ConfigureAwait(false);

            if (results.IsError)
            {
                await ReplyAsync($"Error: {results.ErrorDetails.Message}");
            }


            //Results are split into "pods" that contain information. Those pods can have SubPods.
            foreach (Pod pod in results.Pods)
            {
                foreach (SubPod subPod in pod.SubPods)
                {
                    var builder = new EmbedBuilder()
                    {
                        Color = new Color(114, 137, 218),
                    };

                    string value = (subPod.Image.Height <= 21) ? subPod.Image.Alt : "Shown below";
                    string name  = string.IsNullOrEmpty(subPod.Title) ? pod.Title : subPod.Title;

                    if (!string.IsNullOrEmpty(subPod.Image.Src.ToString()) && subPod.Image.Height > 21)
                    {
                        builder.ImageUrl = subPod.Image.Src.ToString();
                    }


                    builder.AddField(x => {
                        x.Name     = name;
                        x.IsInline = false;
                        x.Value    = value;
                    });

                    await ReplyAsync("", false, builder.Build());
                }
            }
        }
Exemplo n.º 18
0
        public async Task AsyncTest()
        {
            FullResultRequest req = new FullResultRequest("weather in Copenhagen");

            req.UseAsync   = true;
            req.PodTimeout = 1;

            FullResultResponse res = await Client.FullResultAsync(req).ConfigureAwait(false);

            Assert.True(res.IsSuccess);

            Assert.Contains(res.Pods, x => x.AsyncUrl != null);

            await Client.GetAsyncPodsAsync(res).ConfigureAwait(false);

            Assert.True(res.Pods.All(x => x.AsyncUrl == null));
        }
Exemplo n.º 19
0
        public async Task UnitsTest()
        {
            FullResultRequest req = new FullResultRequest("distance from New York to Tokyo");

            req.OutputUnit = Unit.Metric;

            FullResultResponse res = await Client.FullResultAsync(req).ConfigureAwait(false);

            Assert.True(res.IsSuccess);

            Pod resultPod = res.Pods.Single(x => x.Title == "Result");

            Assert.Equal("10879 km (kilometers)", resultPod.SubPods[0].Plaintext);

            req.OutputUnit = Unit.Imperial;
            res            = await Client.FullResultAsync(req).ConfigureAwait(false);

            resultPod = res.Pods.Single(x => x.Title == "Result");
            Assert.Equal("6760 miles", resultPod.SubPods[0].Plaintext);
        }
Exemplo n.º 20
0
        public async Task TimeoutTest()
        {
            FullResultRequest req = new FullResultRequest("pi");

            req.ScanTimeout   = 1;
            req.TotalTimeout  = 5;
            req.ParseTimeout  = 7;
            req.PodTimeout    = 8;
            req.FormatTimeout = 9;

            FullResultResponse res = await Client.FullResultAsync(req).ConfigureAwait(false);

            Assert.True(res.IsSuccess);

            //Because ScanTimeout is 1, we should get a recalculate url
            Assert.NotNull(res.RecalculateUrl);

            await Client.RecalculateQueryAsync(res).ConfigureAwait(false);

            Assert.Null(res.RecalculateUrl);
        }
Exemplo n.º 21
0
        public async Task PodStatesTest()
        {
            FullResultRequest req = new FullResultRequest("pi");

            FullResultResponse res = await Client.FullResultAsync(req).ConfigureAwait(false);

            Assert.NotEmpty(res.Pods);

            //Get the Decimal approximation pod
            Pod decApprox = res.Pods.Single(x => x.Title == "Decimal approximation");
            int length    = decApprox.SubPods[0].Plaintext.Length;

            req.PodStates.Add(decApprox.States[0].Input);

            res = await Client.FullResultAsync(req).ConfigureAwait(false);

            decApprox = res.Pods.Single(x => x.Title == "Decimal approximation");
            int length2 = decApprox.SubPods[0].Plaintext.Length;

            Assert.True(length2 > length);
        }
Exemplo n.º 22
0
        private static async Task Main(string[] args)
        {
            //Create the client.
            WolframAlphaClient client = new WolframAlphaClient(_appId);

            FullResultRequest request = new FullResultRequest("100 digits of pi");

            request.Formats = Format.Plaintext;

            //We start a new query.
            FullResultResponse results = await client.FullResultAsync(request).ConfigureAwait(false);

            //Here we output the Wolfram|Alpha results.
            if (results.IsError)
            {
                Console.WriteLine("Woops, where was an error: " + results.ErrorDetails.Message);
            }

            Console.WriteLine();

            //Results are split into "pods" that contain information. Those pods can have SubPods.
            foreach (Pod pod in results.Pods)
            {
                Console.WriteLine(pod.Title + ":");

                foreach (SubPod subPod in pod.SubPods)
                {
                    if (string.IsNullOrEmpty(subPod.Plaintext))
                    {
                        Console.WriteLine("<Cannot output in console>");
                    }
                    else
                    {
                        Console.WriteLine(subPod.Plaintext);
                    }
                }

                Console.WriteLine();
            }
        }
Exemplo n.º 23
0
        public async Task TranslationTest()
        {
            FullResultRequest req = new FullResultRequest("Bonjour Monde");

            req.Translation = true;

            FullResultResponse res = await Client.FullResultAsync(req).ConfigureAwait(false);

            Assert.True(res.IsSuccess);
            Assert.False(res.IsError);

            Assumption assumption = Assert.Single(res.Assumptions);

            Assert.Equal(AssumptionType.Clash, assumption.Type);
            Assert.Equal("hello world", assumption.Word);
            Assert.Equal("Assuming \"${word}\" is ${desc1}. Use as ${desc2} instead", assumption.Template);

            Assert.Equal(3, assumption.Values.Count);

            Assert.Equal("Miscellaneous", assumption.Values[0].Name);
            Assert.Equal("a phrase", assumption.Values[0].Description);
            Assert.Equal("*C.hello+world-_*Miscellaneous-", assumption.Values[0].Input);

            Assert.Equal("Movie", assumption.Values[1].Name);
            Assert.Equal("a movie", assumption.Values[1].Description);
            Assert.Equal("*C.hello+world-_*Movie-", assumption.Values[1].Input);

            Assert.Equal("MusicWork", assumption.Values[2].Name);
            Assert.Equal("a music work", assumption.Values[2].Description);
            Assert.Equal("*C.hello+world-_*MusicWork-", assumption.Values[2].Input);

            Warning warning = Assert.Single(res.Warnings);

            Assert.Equal("Bonjour Monde", warning.Translation.Phrase);
            Assert.Equal("hello world", warning.Translation.TranslatedText);
            Assert.Equal("French", warning.Translation.Language);
            Assert.Equal("Translating from French to \"hello world\"", warning.Translation.Text);
        }
Exemplo n.º 24
0
        public async Task FullQueryTest2()
        {
            FullResultRequest req = new FullResultRequest("Pi");

            FullResultResponse resp = await Client.FullResultAsync(req).ConfigureAwait(false);

            Assert.True(resp.IsSuccess);
            Assert.False(resp.IsError);

            Pod    inputPod    = resp.Pods.Single(x => x.Title == "Input");
            SubPod inputSubPod = Assert.Single(inputPod.SubPods);

            //Check if we can represent symbols correctly
            Assert.Equal("π", inputSubPod.Plaintext);

            Pod altRepresent = resp.Pods.Single(x => x.Title == "Alternative representations");

            Assert.Equal(4, altRepresent.Infos.Count);

            State state = Assert.Single(altRepresent.States);

            Assert.Equal("More", state.Name);
            Assert.Equal("AlternativeRepresentations:MathematicalFunctionIdentityData__More", state.Input);
        }
Exemplo n.º 25
0
        public async Task ReinterpretTest()
        {
            FullResultRequest req = new FullResultRequest("cantalope duck");

            req.Reinterpret = true;

            FullResultResponse res = await Client.FullResultAsync(req).ConfigureAwait(false);

            Assert.True(res.IsSuccess);
            Assert.False(res.IsError);

            Warning warning = Assert.Single(res.Warnings);

            Assert.Equal("Using closest Wolfram|Alpha interpretation:", warning.Reinterpret.Text);
            Assert.Equal("cantalope", warning.Reinterpret.New);
            Assert.NotEqual(0, warning.Reinterpret.Score);
            Assert.Equal(Level.Medium, warning.Reinterpret.Level);

            Alternative alternative = Assert.Single(warning.Reinterpret.Alternatives);

            Assert.NotEqual(0, alternative.Score);
            Assert.Equal(Level.Low, alternative.Level);
            Assert.Equal("duck", alternative.Value);
        }
Exemplo n.º 26
0
        public async Task FullQueryTest()
        {
            FullResultRequest req = new FullResultRequest("Bill Gates");

            req.IgnoreCase = true;

            req.GeoLocation = new GeoCoordinate(40, -19);

            FullResultResponse resp = await Client.FullResultAsync(req).ConfigureAwait(false);

            Assert.True(resp.IsSuccess);
            Assert.False(resp.IsError);
            Assert.Equal(12, resp.Pods.Count);
            Assert.Equal("Book,Movie,Person", resp.DataTypes);
            Assert.Empty(resp.TimedOut);
            Assert.Empty(resp.TimedOutPods);
            Assert.NotEqual(0, resp.Timing);
            Assert.NotEqual(0, resp.ParseTiming);
            Assert.False(resp.ParseTimedOut);
            Assert.Null(resp.RecalculateUrl);
            Assert.NotEmpty(resp.Id);
            Assert.NotNull(resp.Host);
            Assert.NotEqual(0, resp.Server);
            Assert.NotNull(resp.Related);
            Assert.Equal(Version.Parse("2.6"), resp.Version);

            Assert.Equal(3, resp.Sources.Count);

            Source firstSource = resp.Sources[0];

            Assert.NotEmpty(firstSource.Url.ToString());
            Assert.Equal("Book data", firstSource.Text);

            Source secondSource = resp.Sources[1];

            Assert.NotEmpty(secondSource.Url.ToString());
            Assert.Equal("Movie data", secondSource.Text);

            Source thirdSource = resp.Sources[2];

            Assert.NotEmpty(thirdSource.Url.ToString());
            Assert.Equal("People data", thirdSource.Text);

            Pod inputInter = resp.Pods[0];

            Assert.Equal("Input interpretation", inputInter.Title);
            Assert.Equal("Identity", inputInter.Scanner);
            Assert.Equal("Input", inputInter.Id);
            Assert.Equal(100, inputInter.Position);
            Assert.False(inputInter.IsError);
            Assert.False(inputInter.IsPrimary);

            SubPod inputInterSub = Assert.Single(inputInter.SubPods);

            Assert.Equal("Bill Gates (businessperson)", inputInterSub.Plaintext);
            Assert.NotEmpty(inputInterSub.Image.Src.ToString());
            Assert.Equal("Bill Gates (businessperson)", inputInterSub.Image.Alt);
            Assert.Equal("Bill Gates (businessperson)", inputInterSub.Image.Title);
            Assert.Equal(178, inputInterSub.Image.Width);
            Assert.Equal(18, inputInterSub.Image.Height);
            Assert.Equal("Default", inputInterSub.Image.Type);
            Assert.Equal("1,2,3,4,5,6,7,8,9,10,11,12", inputInterSub.Image.Themes);
            Assert.True(inputInterSub.Image.ColorInvertible);

            Pod basicInfo = resp.Pods[1];

            Assert.Equal("Basic information", basicInfo.Title);
            Assert.Equal("Data", basicInfo.Scanner);
            Assert.Equal("BasicInformation:PeopleData", basicInfo.Id);
            Assert.Equal(200, basicInfo.Position);
            Assert.False(basicInfo.IsError);
            Assert.False(basicInfo.IsPrimary);

            SubPod basicInfoSub = Assert.Single(basicInfo.SubPods);
            string microSource  = Assert.Single(basicInfoSub.MicroSources);

            Assert.Equal("PeopleData", microSource);

            Expressiontype expressionType = Assert.Single(basicInfo.ExpressionTypes);

            Assert.Equal("Grid", expressionType.Name);

            Pod    notableFacts   = resp.Pods[4];
            SubPod notableFactSub = Assert.Single(notableFacts.SubPods);
            string dataSource     = Assert.Single(notableFactSub.DataSources);

            Assert.Equal("TheWikimediaFoundationIncWikipedia", dataSource);

            Pod famRelation = resp.Pods[6];

            Assert.Equal(4, famRelation.ExpressionTypes.Count);
            Assert.Equal(4, famRelation.SubPods.Count);

            State state = Assert.Single(famRelation.States);

            Assert.Equal("Show full dates", state.Name);
            Assert.Equal("FamilialRelationships:PeopleData__Show full dates", state.Input);

            Pod        notableFilms = resp.Pods[7];
            Definition definition   = Assert.Single(notableFilms.Definitions);

            Assert.Equal("Appeared in", definition.Word);
            Assert.Equal("Includes films where an individual appeared as him or herself, or in historical or archival footage.", definition.Description);

            SubPod notableFilmsSub = Assert.Single(notableFilms.SubPods);

            Assert.Equal(2, notableFilmsSub.MicroSources.Count);

            Pod    wikipediaSummary    = resp.Pods[10];
            SubPod wikipediaSummarySub = Assert.Single(wikipediaSummary.SubPods);
            Info   info = Assert.Single(wikipediaSummarySub.Infos);
            Link   link = Assert.Single(info.Links);

            Assert.Equal("http://en.wikipedia.org/wiki?curid=3747", link.Url.ToString());
            Assert.Equal("Full entry", link.Text);
        }