If you don't know this famous tool, just go visit the main page: www.wolframalpha.com/.
Thanks to Romain Vernoux for introducing this tool to me!
- Wolfram|Alpha is © and ® of the Wolfram Research Company;
- wolf (ruby cli) is © Gabriel Horner;
- wolfram (ruby cli) is also © Gabril Horner.
- ruby and nokogiri are the property of their respective authors.
The advantage of this first tool is its simplicity: it is very tiny (47 lines of code, avec comments!), and does not have any dependency, except usual GNU tools grep, curl, tr and sed, already installed on any Linux distribution, and available on Mac OS X (with brew) and on Windows (with cygwin).
However, as this tool is quite simple and minimalist, it is much simpler than wolf (presented below), and does not offer any option.
The original version is here wa.sh (original).
My version, without any colors in the output, is available here wa_nocolor.sh. And an up-to-date version is available here wa.sh.
You have to save your application key in a file named ~/.wolfram_api_key (in your $HOME) with this form :
export API_KEY="3HHP2W-UUPQUT6997"For instance with this bash command:
mv ~/.wolfram_api_key /tmp/ # To not erase a file that should already be there! echo 'export API_KEY="3HHP2W-UUPQUT6997"' > ~/.wolfram_api_key # Then make sure the file has the good reading permission for the current user: chmod +r ~/.wolfram_api_key
Here are some examples, to compare the two cli tools (cf. below for examples with wolf) :
One could complain about the impressive slowness of this solution. Some requests can take up-to a few seconds, it's not that quick!
The main page is github.com/cldwalker/wolf.
It is also a command line client tool for the Wolfram|Alpha website.
To install wolf on Ubuntu 11.10 (or more recent), you have to install the packets ruby1.9.1 and ruby1.9.1-dev :
sudo apt-get install ruby1.9.1 ruby1.9.1-dev
Avis
Ruby 1.9.1 is not available anymore from Ubuntu 15.10 !
So I can no longer test for real the example of use of wolf, included below, sorry.
Then, Nokogiri is needed.
First, install its dependencies (a few ruby gems), and two librairies :
sudo apt-get install ri1.9.1 rdoc1.9.1 irb1.9.1 sudo apt-get install libreadline-ruby1.9.1 libruby1.9.1 libopenssl-ruby1.9.1 # nokogiri requirements sudo apt-get install libxslt-dev libxml2-dev
Warning, the last step changes from the official installation tutorial. Warning also, this step seems to be very long, as the gem apparently needs one highly-CPU consuming compilation step.
# Warning : here it changes from the official tutorial sudo gem1.9.1 install nokogiri
And then, FINALLY, you can install the wolf gem:
sudo gem1.9.1 install wolf
As it is explained on the GitHub page for wolf, you have to create an account, and then obtain a developer key by clicking on the button "Get an AppID".
For your information, this key is a small string of characters that looks like this:
3HHP2W-UUPQUT6997
Avis
Of course, this is NOT a valid key! You have to get yourse!
The simpler is to create a file .wolfrc (in your $HOME) with this content "Wolfram.appid=3HHP2W-UUPQUT6997" :
mv ~/.wolfrc /tmp/ # To not erase a file that should already be there! echo "Wolfram.appid=3HHP2W-UUPQUT6997" > ~/.wolfrc # Then make sure the file has the good reading permission for the current user: chmod +r ~/.wolfrc
A simple test can be to run wolf 0+0, to be sure that the wolf binary application was correctly installed.
Usually, the error messages returned by Ruby should be understandable, so if the first try yells at you and fails, it should gives you required information to fix the installation.
Avis
The most common problem in this installation process is the confusion between ruby1.8 and ruby1.9.1.
With the runblock plug-in for Sphinx, it is possible to embed the input and output of a call to the wolf tool, directly in this page !
A funny example that was famous when it first came out!
This file wolfram.example shows for instance the raw output of the request "distance Paris Montreal".
For more examples, consult the examples page on wolframalpha.com.
To embed a wolf command and its output, I use the following snippet or rST code:
.. runblock:: console $ wolf "my question"
A first weakness of this use of the rST command .. runblock:: console to run an example of wolf question ... is the limitation to pure ASCII character imposed by the runblock extension (this limitation was already noticed in this page, where I am forced to manually change the language of the terminal (export LANG=en) to ask gpg to be in English and not in French, in order to avoid accents).
We could imagine a Wolfram|Alpha plug-in for Sphinx, similar to the GNUplot plugin, allowing to embed graphs and arrays produced by Wolfram|Alpha. But I am not motivated enough to implement it myself!