PHP-Stanford-NLP icon indicating copy to clipboard operation
PHP-Stanford-NLP copied to clipboard

Undefined offset

Open nicozimmermann94 opened this issue 9 years ago • 11 comments

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.

nicozimmermann94 avatar Nov 30 '15 12:11 nicozimmermann94

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

cloudEdwards avatar Feb 13 '16 23:02 cloudEdwards

Does anyone have a resolution to this issue? I'm having the same problem in both Ubuntu and OSX environments.

eroltoker avatar Apr 17 '16 20:04 eroltoker

Experiencing the same issue in OSX running 3.4.1 models and PHP 5.5.26.

jasonlav avatar May 17 '16 16:05 jasonlav

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.

jasonlav avatar May 17 '16 16:05 jasonlav

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

DennisDeSwart avatar May 19 '16 22:05 DennisDeSwart

Experiencing the same issue in OSX. Did anyone solve the problem? Thank you in advanced

covaberjon avatar Jul 16 '16 13:07 covaberjon

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 avatar Aug 27 '16 12:08 DoUBiteYourThumbAtMeSir

@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.

DennisDeSwart avatar Aug 27 '16 16:08 DennisDeSwart

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.

DoUBiteYourThumbAtMeSir avatar Aug 28 '16 13:08 DoUBiteYourThumbAtMeSir

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.

covaberjon avatar Sep 03 '16 10:09 covaberjon

Thank you @DennisDeSwart, Now I see where the problem is and can solve it.

hoangsonnguyen avatar Oct 01 '17 11:10 hoangsonnguyen