Site icon Embarcadero RAD Studio, Delphi, & C++Builder Blogs

Wolfram Alpha Adds An Enterprise-Grade Knowledge Base

wa

Do you want to add enterprise-grade Wolfram Alpha features to your applications? You can easily use Wolfram Alpha in our C++ Software and Delphi applications by using Wolfram|Alpha API from the Wolfram Alpha with free 2000 requests monthly. It is a RESTful server and very easy to set up and get data in JSON format, which means we can easily use the REST framework to connect this data.

What is Wolfram Alpha?

Summarizing Wolfram Research’s own description, Wolfram Alpha is an expert-level knowledge database and capabilities to the broadest possible range of people from all professions to education levels. They work to accept completely free-form input and to serve as a knowledge engine that generates powerful results and presents them with maximum clarity. Wolfram Alpha is an ambitious, long-term intellectual endeavor that is intended to improve over a long period of time.

The Wolfram Alpha API allows clients to submit free-form queries similar to the queries one might enter at the Wolfram|Alpha website, and for the computed results to be returned in a variety of formats. It is implemented in a standard REST protocol using HTTP GET requests. Each result is returned as a descriptive XML or JSON structure wrapping the requested content format.

Note that the Full Results API gives access to all capabilities and output formats. To display full results as a single image, use the Simple Results API.

Using REST to integrate Wolfram Alpha

REST (Representational State Transfer) is a connectivity method that allows to get and post data to create interactive applications that use Web Services. REST uses a subset of HTTP. A Web service that uses this REST data transfer architecture is called a RESTful. This web service must provide its web resources in a text form and this service also allows contents to be read and modified with a stateless protocol and a predefined set of operations. REST is a new modern data transfer architecture that allows interoperability between the computer systems on the Internet that provide these services. REST is Backend as a Service (BaaS) can be used in REST Server or REST Client applications, it is an alternative to SOAP to access a Web service. client tutorial shows how to use the REST Client Library for accessing REST-based web services (REST stands for Representational State Transfer).

In C++ and Delphi , the REST library is available for all platforms that are supported by both of them. The REST Library framework focuses on JSON as the representation format. XML is not explicitly supported.

C++ Builder has many connectivity options like FireDAC SQL Connections to InterBase, IB Express, MSSQL, MySQL, PostgreSQL, SQLite, …; or TCP/IP Connections and many other connectivity options. C++ Builder has also REST-based connectivity as a Client or as a Server that provides you to do REST connections by the REST components that come with RAD Studio officially.

Using the REST Debugger

We can easily set up the components by using REST Debugger Tool in RAD Studio (C++ Builder or Delphi). You can launch REST Debugger from the Tools menu of RAD StudioThe Embarcadero REST Debugger(The Latest version is 10.4.2) empowers developers to explore, test, and ultimately understand how a RESTful web service works. Dive right into REST data with filterable JSON blobs, streamlined OAuth 1.0/2.0 authentication, and configurable request/resource parameters. You can directly copy and paste REST components from the REST Debugger to the RAD Studio, Delphi, or C++Builder IDE. This enables the configuration and consumption of REST services in Delphi or C++Builder apps with just a few clicks.

REST Debugger allows you to test your connections easily, you can easily reach or transfer your data. There is also a free version that can be used by other REST tools and it can be downloaded from RESTdebugger.

In RAD Studio there is a good tool REST Debugger to test REST Requests (Gets, Posts, …) and it is very easy to automatically set up the REST components with their parameters.

Getting Wolfram Alpha API

Wolfram Alpha API is very simple, here are the steps,

  1. Read details about Wolfram Alpha API from their API Documentation
  2. Sign Up to Wolfram Alpha API by clicking Get Started button. To use Wolfram Alpha, you must have a Wolfram ID (appid), and you must register and sign in at the Wolfram|Alpha Developer Portal.
  3. Upon logging in, go to the My Apps tab to start creating your first app with App Name: Your APPID will be used to define APP NAME and USAGE TYPE etc. Get your APPID Access Key from this screen.

4. Integrate into your application
Now you can test your connection with REST Debugger or with your REST Client applications.

Connecting and Setting Components with the REST Debugger

  1. In Request Tab:
    Set Method GET and BaseURL to “http://api.wolframalpha.com/v2/query“, please check Wolfram Alpha API Documentation
    Set Content-Type: application/json
  2. In Parameters Tab: Add these parameters and values by clicking Add button in Request Parameters section:
    appid = YOUR_API_ID (add your api id key here)
    output = json
    input = YOUR QUERY HERE (add your query here)
    you must check their web page and examples for more query examples.

    Simply we can get Population of Madagascar by using “Population of Madagascar” input query below by changing DEMO to YOUR_API_ID
[crayon-6767e9fa86b6c003446101/]

To get any detailed information from the Wolfram Alpha, with REST Debugger, copy your URL with your API ID Key

One of the great feature of REST Debugger setups all components and features for your C++ Builder application. Just press to ‘Copy Components’, paste it to your form design.

Testing a REST connection to Wolfram Alpha by using REST Debugger settings

You can easily create a REST connection by using REST components and REST Debugger in C++ Builder.

  1. Create a new Multi-Device C++ Builder application, save all unit and project files to a folder (i.e WolframAlpha API )
  2. Set your WolframAlpha API Registration on their web page and use REST Debugger as described above.
    If you copied components by using REST Debugger as given above, paste them to your form, and arrange their positions to see their names.
  3. Add a Button (TButton) and a Memo (TMemo) component to see all JSON data.
  4. Double click to Button1, and modify as below,
[crayon-6767e9fa86b76260960265/]

If you run your application you will see that it gets all data about all results in JSON format.
If you don’t want to use components copied by the REST Debugger, you can also manually follow the Tutorial using the REST Client Library from here

How to communicate with the Wolfram Alpha API using REST components.

Follow these steps

  1. Create a new Multi-Device C++ Builder application, save all unit and project files to a folder (i.e WolframAlpha API )
  2. Add a Button (TButton) and a Memo (TMemo) component to see all JSON data.
  3. Drag RESTClient (TRESTClient , RESTRequest (TRESTRequest) and RESTResponse (TRESTResponse) and arrange their positions to see their names.
  4. Click to RESTClient1, and on the Object Inspector window,
    Set your WolframAlpha API Registration on their web page as described above
  5. Set BaseURL to “http://api.wolframalpha.com/v2/query“, please check Wolfram Alpha API Documentation
    Set Content-Type: application/json in As described Wolfram Alpha API Documentation
    Double click to its Params and add these parameters; 

appid = YOUR_API_ID (add your api id key here)
output = json
input = YOUR QUERY HERE (add your query here), here we will use Edit1->Text to get search text.

7. Add a Button, double click to add OnClick() event as below,

[crayon-6767e9fa86b79612048408/]

As you see, REST connection and APIs are very useful with all platforms, Wolfram Alpha API can be used with REST components it in C++ Builder, it is also possible in Delphi too. This is an example run when you query ” Copernicium”,


C++ Builder is the easiest and fastest C and C++ IDE for building simple or professional applications on the Windows, MacOS, iOS & Android operating systems. There is a free C++ Builder Community Edition for students, beginners and startups, it can be download from here and the professional developers can use the Professional, Architect or Enterprise versions of C++ Builder which has trial version and can be downloaded from here.

Exit mobile version