PHP-Stanford-NLP
PHP-Stanford-NLP copied to clipboard
Undefined offset
Hello, I am trying to get the parser example working but getting this error:
Notice: Undefined offset: 1 in C:\xampp\htdocs\stanford\src\StanfordNLP\Parser.php on line 177 Notice: Undefined offset: 2 in C:\xampp\htdocs\stanford\src\StanfordNLP\Parser.php on line 182
Also, why can't I run the programm with apache? Only running in CLI gives me some data back.
I am having this same problem. My error response is this
Warning: proc_open(): CreateProcess failed, error code - 0 in C:\xampp\htdocs\what-to-draw\vendor\agentile\php-stanford-nlp\src\StanfordNLP\Parser.php on line 105
Notice: Undefined offset: 1 in C:\xampp\htdocs\what-to-draw\vendor\agentile\php-stanford-nlp\src\StanfordNLP\Parser.php on line 177
Notice: Undefined offset: 2 in C:\xampp\htdocs\what-to-draw\vendor\agentile\php-stanford-nlp\src\StanfordNLP\Parser.php on line 182
Does anyone have a resolution to this issue? I'm having the same problem in both Ubuntu and OSX environments.
Experiencing the same issue in OSX running 3.4.1 models and PHP 5.5.26.
Undefined offset indicates that the PHP was unable to obtain any output from Java. This PHP executes a Java command (via proc_open()
) to execute the JAR files. You can read the errors from the script by printing $parser->getErrors();
. Java needs to be installed and executed via command line (OSX, I believe, comes with it preinstalled). For me, I updated the .jar paths in the PHP to be absolute and it worked.
If you are on Windows or Mac, the problem might be caused by a wrong line break. The orginal code seems to be written for Linux.
Line 152 of Parser.php is: $output = explode("\n\n", trim($this->getOutput()));
For Windows, change to: $output = explode("\r\n\r\n", trim($this->getOutput()));
For Mac systems try: $output = explode("\r\r", trim($this->getOutput()));
More info: http://stackoverflow.com/questions/255511/php-echo-line-breaks
OR you could also try PHP's end-of-line constant, like this: $output = explode(PHP_EOL, trim($this->getOutput()));
Greetings Dennis
Experiencing the same issue in OSX. Did anyone solve the problem? Thank you in advanced
Hello, I'm having the same undefined offset error. I'm using Windows 8.1, PHP 5.5.12 and Java jdk 1.8.0_101.
I tried @DennisDeSwart advice to getOutput call but this has not changed my error. I used @jasonlav advice to getErrors and this is what it returns.
'C:/Program' is not recognized as an internal or external command,\r\noperable program or batch file.\r\n
My guess is that this is an error because there is a space (Program(space)Files in the Path variable to java. Has anyone else seen this?
Best wishes,
Eric
@DoUBiteYourThumbAtMeSir
Your guess is correct: Windows needs quotation marks to deal with empty spaces.:
http://stackoverflow.com/questions/378490/how-do-i-to-properly-handle-spaces-in-php-shell-exec http://stackoverflow.com/questions/16477878/exec-doesnt-execute-command-if-path-contains-whitespaces
So what you probably need to do is look at how the $cmd variable (around r.90 in Parser.php) calls the parser. Then add quotes where necessary.
Hi Dennis,
Thanks for the response it helped a great deal. I ended up changing program files to Progra~1 which seems to work fine. I tried the escapeshellarg and had no luck. I tried the other ways of escaping mentioned in the 2nd link without luck, but I didn't really give them a chance since I already had it working another way.
On to bigger and better errors. Thanks again.
Same problem here...
In localhost everything was working ok. However, in production I am receiving this error: EError: Could not find or load main class edu.stanford.nlp.parser.lexparser.LexicalizedParser
It is related with executing the jar files. I followed all your advices and didn't work. @jasonlav @DennisDeSwart
Any help would be appreciated.
Thank you @DennisDeSwart, Now I see where the problem is and can solve it.