English 中文(简体)
C# Wolfram Aplha API 工作实例
原标题:C# Wolfram aplha API working example

我一直试图让Wolframalpha API (C/code>) 的 API 无效。 我一直在尝试使用这两种资源:

  1. Stack Question
  2. Wolfram API demos

文章中的答案是半有帮助的, 但我无法收集任何东西来编译。 我最近才到C#, 所以有点压倒性。 我真的很难让它接受输入, 然后输出结果 。

如果有人能帮助我 使这个代码运作起来 这样我就可以用一个有效的范例来工作 或者知道一个我可以用它来做模型的范例项目 我会感激不尽的.

这是我剪切并粘贴到 C#(视觉工作室)控制台项目的代码:

    namespace WolframAlpha {
    using System;
    using System.Collections.Generic;
    using System.Data.Services.Client;
    using System.Net;
    using System.IO;


    public partial class DefaultPodEntity {

        private String _PlainText;

        private String _Img;

        private String _Title;

        private String _ParentTitle;

        private Int16 _ParentPosition;

        private String _ParentId;

        public String PlainText {
            get {
                return this._PlainText;
            }
            set {
                this._PlainText = value;
            }
        }

        public String Img {
            get {
                return this._Img;
            }
            set {
                this._Img = value;
            }
        }

        public String Title {
            get {
                return this._Title;
            }
            set {
                this._Title = value;
            }
        }

        public String ParentTitle {
            get {
                return this._ParentTitle;
            }
            set {
                this._ParentTitle = value;
            }
        }

        public Int16 ParentPosition {
            get {
                return this._ParentPosition;
            }
            set {
                this._ParentPosition = value;
            }
        }

        public String ParentId {
            get {
                return this._ParentId;
            }
            set {
                this._ParentId = value;
            }
        }
    }

    public partial class HtmlPodEntity {

        private String _Markup;

        private String _Title;

        private Int16 _Position;

        private String _Id;

        private String _Css;

        private String _Scripts;

        public String Markup {
            get {
                return this._Markup;
            }
            set {
                this._Markup = value;
            }
        }

        public String Title {
            get {
                return this._Title;
            }
            set {
                this._Title = value;
            }
        }

        public Int16 Position {
            get {
                return this._Position;
            }
            set {
                this._Position = value;
            }
        }

        public String Id {
            get {
                return this._Id;
            }
            set {
                this._Id = value;
            }
        }

        public String Css {
            get {
                return this._Css;
            }
            set {
                this._Css = value;
            }
        }

        public String Scripts {
            get {
                return this._Scripts;
            }
            set {
                this._Scripts = value;
            }
        }
    }

    public partial class PlainTextPodEntity {

        private String _PlainText;

        private String _Title;

        private String _ParentTitle;

        private Int16 _ParentPosition;

        private String _ParentId;

        public String PlainText {
            get {
                return this._PlainText;
            }
            set {
                this._PlainText = value;
            }
        }

        public String Title {
            get {
                return this._Title;
            }
            set {
                this._Title = value;
            }
        }

        public String ParentTitle {
            get {
                return this._ParentTitle;
            }
            set {
                this._ParentTitle = value;
            }
        }

        public Int16 ParentPosition {
            get {
                return this._ParentPosition;
            }
            set {
                this._ParentPosition = value;
            }
        }

        public String ParentId {
            get {
                return this._ParentId;
            }
            set {
                this._ParentId = value;
            }
        }
    }

    public partial class WolframAlphaFactsContainer : System.Data.Services.Client.DataServiceContext {

        public WolframAlphaFactsContainer(Uri serviceRoot) : 
                base(serviceRoot) {
        }

        /// <summary>
        /// </summary>
        /// <param name="Input">Query string Sample Values : weather|msft|derivative of x^4 sin x|SAT scores</param>
        /// <param name="Location">Location used for computation Sample Values : Madrid|Springfield, IL</param>
        /// <param name="LatitudeLongitude">Latitude/Longitude used for computation Sample Values : 40.42,-3.71|-22.54,-43.12</param>
        /// <param name="Width">Width in pixels for images returned Sample Values : 300|500</param>
        public DataServiceQuery<DefaultPodEntity> GetImageResults(String Input, String Location, String LatitudeLongitude, Int16? Width) {
            if ((Input == null)) {
                throw new System.ArgumentNullException("Input", "Input value cannot be null");
            }
            DataServiceQuery<DefaultPodEntity> query;
            query = base.CreateQuery<DefaultPodEntity>("GetImageResults");
            if ((Input != null)) {
                query = query.AddQueryOption("Input", string.Concat(" ", Input, " "));
            }
            if ((Location != null)) {
                query = query.AddQueryOption("Location", string.Concat(" ", Location, " "));
            }
            if ((LatitudeLongitude != null)) {
                query = query.AddQueryOption("LatitudeLongitude", string.Concat(" ", LatitudeLongitude, " "));
            }
            if (((Width != null) 
                        && (Width.HasValue == true))) {
                query = query.AddQueryOption("Width", Width.Value);
            }
            return query;
        }

        /// <summary>
        /// </summary>
        /// <param name="Input">Query string Sample Values : weather|msft|derivative of x^4 sin x|SAT scores</param>
        /// <param name="Location">Location used for computation Sample Values : Madrid|Springfield, IL</param>
        /// <param name="LatitudeLongitude">Latitude/Longitude used for computation Sample Values : 40.42,-3.71|-22.54,-43.12</param>
        /// <param name="Width">Width in pixels for images returned Sample Values : 300|500</param>
        public DataServiceQuery<HtmlPodEntity> GetHtmlResults(String Input, String Location, String LatitudeLongitude, Int16? Width) {
            if ((Input == null)) {
                throw new System.ArgumentNullException("Input", "Input value cannot be null");
            }
            DataServiceQuery<HtmlPodEntity> query;
            query = base.CreateQuery<HtmlPodEntity>("GetHtmlResults");
            if ((Input != null)) {
                query = query.AddQueryOption("Input", string.Concat(" ", Input, " "));
            }
            if ((Location != null)) {
                query = query.AddQueryOption("Location", string.Concat(" ", Location, " "));
            }
            if ((LatitudeLongitude != null)) {
                query = query.AddQueryOption("LatitudeLongitude", string.Concat(" ", LatitudeLongitude, " "));
            }
            if (((Width != null) 
                        && (Width.HasValue == true))) {
                query = query.AddQueryOption("Width", Width.Value);
            }
            return query;
        }

        /// <summary>
        /// </summary>
        /// <param name="Input">Query string Sample Values : weather|msft|derivative of x^4 sin x|SAT scores</param>
        /// <param name="Location">Location used for computation Sample Values : Madrid|Springfield, IL</param>
        /// <param name="LatitudeLongitude">Latitude/Longitude used for computation Sample Values : 40.42,-3.71|-22.54,-43.12</param>
        /// <param name="Width">Width in pixels for images returned Sample Values : 300|500</param>
        public DataServiceQuery<PlainTextPodEntity> GetPlainTextResults(String Input, String Location, String LatitudeLongitude, Int16? Width) {
            if ((Input == null)) {
                throw new System.ArgumentNullException("Input", "Input value cannot be null");
            }
            DataServiceQuery<PlainTextPodEntity> query;
            query = base.CreateQuery<PlainTextPodEntity>("GetPlainTextResults");
            if ((Input != null)) {
                query = query.AddQueryOption("Input", string.Concat(" ", Input, " "));
            }
            if ((Location != null)) {
                query = query.AddQueryOption("Location", string.Concat(" ", Location, " "));
            }
            if ((LatitudeLongitude != null)) {
                query = query.AddQueryOption("LatitudeLongitude", string.Concat(" ", LatitudeLongitude, " "));
            }
            if (((Width != null) 
                        && (Width.HasValue == true))) {
                query = query.AddQueryOption("Width", Width.Value);
            }
            return query;
        }
    }
}
最佳回答

This codeplex project claims to cover the latest Wolfram Alpha API and includes a sample: http://wolframalphaapi20.codeplex.com/

控制台应用程序使用静态主方法作为切入点。 此例行程序通常可以在文件程序中找到。 当为控制台应用程序创建新的工程时, 文件程序 cs 会自动创建 。

如果编译者说它找不到 Main, 那么它可能已被删除或从未创建。 没有要查看的代码很难说 。 当主方法的问题解决时, 更多的错误会显示 。

问题回答

目前我正在玩一个叫WolframAlpha.NET的电话。代码源在>github上。有一个