Ejemplo n.º 1
0
        public void ValidateQueryTest()
        {
            WolframAlphaNET.WolframAlpha wolframAlpha = new WolframAlphaNET.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);
        }
Ejemplo n.º 2
0
 public void WolframAlphaConstructorTest()
 {
     WolframAlphaNET.WolframAlpha wolfram = new WolframAlphaNET.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);
 }
Ejemplo n.º 3
0
        public void SearchTest()
        {
            WolframAlphaNET.WolframAlpha wolframAlpha = new WolframAlphaNET.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);
        }
Ejemplo n.º 4
0
        public void EnableTranslateTest()
        {
            //First try without translation
            WolframAlphaNET.WolframAlpha wolframAlpha = new WolframAlphaNET.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);
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            //Create the Engine.
            WolframAlphaNET.WolframAlpha wolfram = new WolframAlphaNET.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();
        }