spacy-nlp icon indicating copy to clipboard operation
spacy-nlp copied to clipboard

Unhandled rejection TypeError: Cannot read property 'output' of undefined

Open ajmal-shah opened this issue 7 years ago • 14 comments

Hello kengz,

Great work with the modules.

I am facing an error while following the steps in tutorial.

image

package json :

{ "name": "nlp-app", "version": "1.0.0", "description": "Sample app", "main": "app.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "Test", "license": "ISC", "dependencies": { "poly-socketio": "1.1.4", "spacy-nlp": "^1.0.7" } }

ajmal-shah avatar Mar 24 '17 09:03 ajmal-shah

Hmm input is likely missed. Pathing is likely incompatible on Windows. Do you have a unix system to test it out?

kengz avatar Apr 03 '17 04:04 kengz

I'm getting the same error on Ubuntu, so that's not it :/

skerit avatar Apr 03 '17 16:04 skerit

screen shot 2017-04-20 at 10 18 24 am same error on mac as well....

Any update on solving this ?

swsridhar avatar Apr 20 '17 04:04 swsridhar

I think you need to wait for the servers to be started. I had the same error, so I set a timeout:

setTimeout(() => {
	const nlp = spacyNLP.nlp
	nlp.parse('Bob Brought the pizza to Alice.')
	.then((output) => {
		console.log(output)
		console.log(JSON.stringify(output[0].parse_tree, null, 2))
	})
}, 5000)

Not very elegant.

However, I thought the spacyNLP.server should return a promise. I tried spacyNLP.server({ port: process.env.IOPORT }).then(...), but this does not work.

peterhuppertz avatar Apr 25 '17 09:04 peterhuppertz

try setting the environment variable USE_PY2 to true, in case your python version is 2. process.env.USE_PY2 = true

tnarek avatar Jun 19 '17 09:06 tnarek

After set the timeout its working fine for me with same error, but need to adjust the time based on own PC speed.

In my case time out I have set up to 8000.

@peterhuppertz Thank you so much.

pritesh-volansys avatar Aug 18 '17 06:08 pritesh-volansys

@peterhuppertz - I don't think that code is doing anything other than delaying the entire execution by 5 seconds. The const nlp = spacyNLP.nlp ought to be outside the setTimeout for this theory to make any sense, but I've tried that and am still receiving the Cannot read property 'output' of undefined error

TimHeckel avatar Dec 15 '17 04:12 TimHeckel

Let me share my README.md files which I am following to install and use on node js, for your reference.

pritesh-volansys avatar Dec 15 '17 09:12 pritesh-volansys

spacy-nlp

Expose Spacy nlp text parsing to Nodejs via socketIO

Installation

# install spacy in python3
python3 -m pip install -U socketIO-client
python3 -m pip install -U spacy
python3 -m spacy.en.download

# install this npm package
npm i --save spacy-nlp

Usage

Server :

const spacyNLP = require('spacy-nlp')
// default port 6466
// start the server with the python client that exposes spacyIO (or use an existing socketIO server at IOPORT)
var serverPromise = spacyNLP.server({ port: process.env.IOPORT })
// Loading spacy may take up to 15s

You'll see log like:

[Sun Oct 09 2016 16:53:33 GMT-0400 (EDT)] INFO Starting poly-socketio server on port: 6466, expecting 1 IO clients
[Sun Oct 09 2016 16:53:33 GMT-0400 (EDT)] INFO Starting socketIO client for python3 at 6466
[Sun Oct 09 2016 16:53:44 GMT-0400 (EDT)] DEBUG cgkb-py mXjDqupv852zUeMPAAAA joined, 0 remains
[Sun Oct 09 2016 16:53:44 GMT-0400 (EDT)] INFO All 1 IO clients have joined

Client :

Once server is ready, i.e. you can use the nodejs client nlp to parse texts:

const spacyNLP = require('spacy-nlp')
const nlp = spacyNLP.nlp

// Note you can pass multiple sentences concat in one string.
nlp.parse('Your text')
  .then((output) => {
    console.log(output)
    console.log(JSON.stringify(output[0].parse_tree, null, 2))
  })

Run the Node :

Input

node spacy.js "your text"

Example :

node spacy.js "what is the weather today in Ahmedabad"

output

[ { text: 'what is the weather today in Ahmedabad',
    len: 7,
    tokens: [ 'what', 'is', 'the', 'weather', 'today', 'in', 'Ahmedabad' ],
    noun_phrases: [ 'what', 'the weather', 'Ahmedabad' ],
    parse_tree: [ [Object] ],
    parse_list:
     [ [Object],
       [Object],
       [Object],
       [Object],
       [Object],
       [Object],
       [Object] ] } ]
[
  {
    "word": "is",
    "lemma": "be",
    "NE": "",
    "POS_fine": "VBZ",
    "POS_coarse": "VERB",
    "arc": "ROOT",
    "modifiers": [
      {
        "word": "what",
        "lemma": "what",
        "NE": "",
        "POS_fine": "WP",
        "POS_coarse": "NOUN",
        "arc": "attr",
        "modifiers": []
      },
      {
        "word": "weather",
        "lemma": "weather",
        "NE": "",
        "POS_fine": "NN",
        "POS_coarse": "NOUN",
        "arc": "nsubj",
        "modifiers": [
          {
            "word": "the",
            "lemma": "the",
            "NE": "",
            "POS_fine": "DT",
            "POS_coarse": "DET",
            "arc": "det",
            "modifiers": []
          },
          {
            "word": "today",
            "lemma": "today",
            "NE": "DATE",
            "POS_fine": "NN",
            "POS_coarse": "NOUN",
            "arc": "npadvmod",
            "modifiers": []
          },
          {
            "word": "in",
            "lemma": "in",
            "NE": "",
            "POS_fine": "IN",
            "POS_coarse": "ADP",
            "arc": "prep",
            "modifiers": [
              {
                "word": "Ahmedabad",
                "lemma": "Ahmedabad",
                "NE": "GPE",
                "POS_fine": "NNP",
                "POS_coarse": "PROPN",
                "arc": "pobj",
                "modifiers": []
              }
            ]
          }
        ]
      }
    ]
  }
]

pritesh-volansys avatar Dec 15 '17 09:12 pritesh-volansys

Has this error been resolved yet ? I am also facing this error

divesh987 avatar Jan 08 '18 13:01 divesh987

I have managed to fix it. However it is not creating the graphs , it is showing the json ...

python -m spacy download en First run this command then go into /src/py/ then nlp.py and change from spacy.en import English # NLP with spaCy https://spacy.io nlp = English() # will take some time to load into import spacy nlp = spacy.load('en')

Also change line 126 from doc = nlp(input, tag=False, entity=False) to doc=nlp(input) because it is not recognising entity and tag as arguments.

Then also make sure youre running start.io.js in the src dir with node start.io.js

before running node index.js

divesh987 avatar Jan 10 '18 12:01 divesh987

Specifically for logging issue: New fix from #10 published. Please bump version to 1.0.8 and give it a try.

The graph relies on nodejs getting the json from python (spacy part), then passing it to a neo4j db. The fixed logger should reveal some of these info that were suppressed before.

kengz avatar Jan 15 '18 06:01 kengz

For me I had to run python3 -m pip install socketIO_client_nexus to get rid of this error

chanind avatar Jun 21 '19 13:06 chanind

facing the same issue

rizwan92 avatar Jun 14 '21 11:06 rizwan92