コード例 #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);
        }
コード例 #2
0
        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);
        }
コード例 #3
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);
        }
コード例 #4
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);
        }