Thursday, 16 March 2017

Stanford NLP and HTMl Webpage Node JS error

What I'm currently doing is allowing the user to submit text on a HTML webpage and I want to parse that using a Stanford nlp nodejs library.

I currently have the following:

I have this example script that allows me to parse text: example.js:

'use strict';
const corenlp = require("./index.js");

var text = corenlp("the quick brown fox jumped over the lazy dog",9000,"parse","json");
// var obj = JSON.parse(text);
var json1 = JSON.parse('{ "name":"John", "age":30, "city":"New York"}');
console.log(text);

This parses the text "the quick brown fox jumped over the lazy dog"

the required file ( index.js is the following):

'use strict';
const execSync = require(['child_process']).execSync;

module.exports = function(stringToProcess,portNumber,annotatorsString,outputFormatString) {
  let termOutput = execSync('output=$(wget --post-data '+"'"+stringToProcess+"' "+"'localhost:"+portNumber+'/?properties={"annotators": '+'"'+annotatorsString+'", "outputFormat": "'+outputFormatString+'"'+"}' -qO -) && echo $output",{ encoding: 'utf8' });
  return termOutput;
};

I want to integrate this into my webpage and I have An input field, I then modified the example code to the following(parse.js):

function displayParse(){
    'use strict';
    const corenlp = require(["node_modules/corenlp-js-interface/index.js"]);

    var sp= document.getElementById('spit')
    var parserText= document.getElementById('parseText');
    var text = corenlp(parseText.value,9000,"parse","json");

    console.log(text);

    sp.innerHTML= text;

}

And this is called onclick when a button is pressed.

The issue that I'm facing is that I get the following error:

When I load the page:

Error: Module name "child_process" has not been loaded yet for context: _. Use require([]) http://requirejs.org/docs/errors.html#notloaded

when I press the button I get the following two errors: enter image description here

I go to the link and it tells me to put these brackets around the the content I want loaded even though I have already done that.

What am I doing wrong? or is there a better way to do this?

The node js module that I am using is: https://www.npmjs.com/package/corenlp-js-interface



via 39fredy

No comments:

Post a Comment