Server Setup: Voice based query interface for database

For now, I have chosen packet for the trial server even though the cost is high. The specs are good (even for entry level containers) and I got some credits to work with initially.

Packet Server Config

So I setup the ssh keys for login and got to work.

The github repository for parsey mcparseface and syntaxnet is available here and it also lists out the steps required to setup syntaxnet and get it working. They also provide a demo shell script file which accepts the input at stdin and passes it to a python script named parser_eval. The output which is an ascii tree of the pos tagged statement is posted to stdout.

ASCII Tree of POS tagged statement

Moving on, lets create a bare bones node js express server. Express Generator setup the basic routing and layout things I wanted. However, the views are apparently written in Jade and not the age old HTML. This could be good if I write the layout myself, but I might have to cut some corners if I pick up a template from somewhere.

Welcome to Express

  • Now, lets connect the above two things. Express generator creates a route named users which executes the users.js in the routes directory when called. I made use of this to accept the user input and pass it to a js script
  • Next I imported some libraries required to execute scripts onto the host environment.

var util = require(‘util’);

var exec = require(‘child_process’).exec;

  • Then I wrote an exec command to send the user’s input to the demo.sh file and then send the stdout content back to the user.

exec(‘cd /root/models/syntaxnet && echo “‘+req.query.query+’” | syntaxnet/demo.sh’,

function(error, stdout, stderr){

console.log(‘stdout: ‘ + stdout);

console.log(‘stderr: ‘ + stderr);

if (error !== null) {

console.log(‘exec error: ‘ + error);

}

res.send(stdout);

});

  • Checking the execution of the script, I got the following result.

Input: What are the symptoms of cancer ? Parse: What WP ROOT +– are VBP cop +– symptoms NNS nsubj | +– the DT det | +– of IN prep | +– cancer NN pobj +– ? . punct

As expected, except the output is in a single line. But that doesn’t really matter since we have to parse this on the server side before we output the queries to the user.