gfsage: a natural language interface for Sage
The goal of this work is to develop a commandline tool able to take commands in natural language and have them executed by Sage, a collection of Computer Algebra packages presented in a uniform way. We present here instructions on how to build the interface and examples of its intended use.
Building the executable
You'll need:
 ghc with
cabal
, as in Haskell platform  curl
 a way to call Sage on a terminal (usually
sage
command. It assumes it's in your PATH)  A POSIX system
 The source version of GF.
You can get this source version by:
cabal install gf
We can install the other dependencies too by:
cabal install json curl
Checkout the mathematics grammar library from:
svn co svn://moltoproject.eu/mgl
This is the active branch. For the fixed one use:
svn co svn://moltoproject.eu/tags/D6.2
Go into the mgl/sage directory (D6.2/sage if you're using the fixed branch) and make it:
cd mgl/sage
make
The first time you make it will fail, asking you to make modifications in the Sage installation. Please refer to the installation page.
Now try to build gfsage
again. All these build operations will ask Sage to "rebuild" itself. Be warned that the first rebuild takes some time:
make
The system as been tested in Mac (OS X 10.7) and Linux (Ubuntu).
Usage
Run the tool as:
./gfsage english
giving the input language as argument. It will take some seconds to start the server. After that it will reply with some server information and will show the prompt:
sage>
You can then enter your query:
sage> compute the product of the octal number 12 and the binary number 100. (3) 40 answer: it is 40 .
To show that a CAS is actually behind the scene, let's try something symbolic:
sage> compute the greatest common divisor of x and the product of x and y. (4) x answer: it is x .
and compare it with:
sage> compute the greatest common divisor of x and the sum of x and y. (5) 1 answer: it is 1 .
Sage does the right thing in both cases, x and y being unbound numeric variables.
sage> compute the second iterated derivative of the cosine at pi. (6) 1 answer: it is 1 .
Exiting
Exit the session by issuing CRTL+D: This way the server exits cleanly.
Just another example in a different language:
./gfsage spanish Login into localhost at port 9000 Session ID is c1ef10dfd49e4fdb3214fa6d3a3b9c92 waiting... EmptyBlock 2 finished handshake. Session is c1ef10dfd49e4fdb3214fa6d3a3b9c92 sage> calcula la parte imaginaria de la derivada de la exponencial en pi. (4) 0 answer: es 0 .
More recent examples involving integer literals and integration:
sage> compute the sum of 1, 2, 3, 4 and 5. (3) 15 answer: it is 15 . sage> compute the summation of x when x ranges from 1 to 100. (4) 5050 answer: it is 5050 . sage> compute the integral of the cosine from 0 to the quotient of pi and 2. waiting... (5) 1 answer: it is 1 . sage> compute the integral of the function mapping x to the square root of x from 1 to 2. (6) 4/3*sqrt(2)  2/3 answer: it is 4 over 3 times the square root of 2 minus the quotient of 2 and 3 .
Other invocation options
Use english:
gfsage
Use LANGUAGE:
gfsage LANGUAGE
General invocation:
gfsage [OPTIONS]
where OPTIONS are:
short form  long form  description  

h 
help 
Print usage page  
i LANGUAGE 
inputlang=LANGUAGE 
Make queries in LANGUAGE  
o LANGUAGE 
outputlang=LANGUAGE 
Give answers in LANGUAGE  
V LEVEL 
verbose=LEVEL 
Set the verbosity LEVEL  
t FILE 
test=FILE 
Test samples in FILE  
v[VOICE] 
voice[=VOICE] 
Use voice output. To list voices use ? as VOICE. 

F 
withfeedback 
Restate the query when answering. 
Limitations
 On Darwin (OS X 10.6 and 10.7) a bug in the Sage part makes the system unresponsive after some computations (between 7 and 10)
 On some machines, it takes time for the Sage server to respond.
This condition is signaled by the message:
gfsage: Connecting CurlCouldntConnect
I used a Linux virtual machine to reproduce this condition and find that, sometimes, it takes about 10 retries for the server to catch, but then it stays running ok for hours. My guess is that is related to some timeout limit in the server. Killing the orphaned python processes from the previous retries might help too (killall python
).
 Printerfriendly version
 Login to post comments
 Slides
What links here
No backlinks found.