コード例 #1
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);
        }
コード例 #2
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);
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: Ay007/WolframAlpha.Net
        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();
        }