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

Empty Array

Open gupul2k opened this issue 10 years ago • 23 comments

Here is the code and coming empty array.

tag(explode(' ', "The Federal Reserve Bank of New York led by Timothy R. Geithner.")); var_dump($result); ?>
O/P

array(0) { }

gupul2k avatar Dec 22 '14 23:12 gupul2k

Solved. After upgrading JDK to build 1.8.0_25.

gupul2k avatar Dec 23 '14 01:12 gupul2k

I updated to 1.8.0_31 but

<?php
require(THIRD_PARTIES_DIRECTORY . "autoload.php");
echo "POS\n";
$pos = new StanfordNLP\POSTagger(
    './stanford-postagger-full-2015-01-30/models/english-left3words-distsim.tagger',
    './stanford-postagger-full-2015-01-30/stanford-postagger.jar'
);
$result = $pos->tag(explode(' ', "What does the fox say?"));
print_r($result);
?>

outputs

POS
Array
(
)

Solved with absolute path instead of relative path

<?php
require(THIRD_PARTIES_DIRECTORY . "autoload.php");
echo "POS\n";
$pos = new \StanfordNLP\POSTagger(
    __DIR__ . '/stanford-postagger-full-2015-01-30/models/english-left3words-distsim.tagger',
    __DIR__ . '/stanford-postagger-full-2015-01-30/stanford-postagger.jar'
);
$result = $pos->tag(explode(' ', "What does the fox say?"));
print_r($result);
?>

Does any one have a working setup of this POS tagger? I just can not get it set up properly for windows

0ashu0 avatar Mar 13 '15 04:03 0ashu0

facing same problems. have latest java version, all paths are correct and not working on a windows.

schuettla avatar Mar 13 '15 13:03 schuettla

Same issues too on Mac OS X.

franciskim avatar Apr 14 '15 13:04 franciskim

array(0) { } is my output what is (THIRD_PARTIES_DIRECTORY in the code please explain

sajidsheik avatar Apr 22 '15 14:04 sajidsheik

not working when i add DIR. to the path

sajidsheik avatar Apr 22 '15 14:04 sajidsheik

I've got the same issues, i always get array(0) { } but no other errors are thrown.

Any solutions?

dennyshess avatar Jun 28 '15 16:06 dennyshess

I have the exact same code but I also get array (size=0) empty

Anyone solved it yet?

Wmichaelsen avatar Feb 14 '16 21:02 Wmichaelsen

@Wmichaelsen
I had same issue. I took prev. version (stanford-ner 3.5.2 2015-04-20) and it is working.

NameIvan avatar Feb 15 '16 14:02 NameIvan

@NameIvan where can I find the previous versions?

Wmichaelsen avatar Feb 15 '16 15:02 Wmichaelsen

@Wmichaelsen Here http://nlp.stanford.edu/software/CRF-NER.shtml At the bottom of the page

NameIvan avatar Feb 15 '16 15:02 NameIvan

@NameIvan Oh sorry obviously i find them on stanford's site... Tried but unfortunately it didn't help, thanks anyways!

Wmichaelsen avatar Feb 15 '16 15:02 Wmichaelsen

@Wmichaelsen I have it is working on Linux (java version "1.8.0_45"). Do you work on the other OS?

NameIvan avatar Feb 15 '16 15:02 NameIvan

Im on OSX, but I actually work with the POS tagger, not the NER, so perhaps that's the problem

Wmichaelsen avatar Feb 15 '16 22:02 Wmichaelsen

@NameIvan

Wmichaelsen avatar Feb 15 '16 22:02 Wmichaelsen

There is an issue with a invalid java classpath if you use readme example. Adding a slf4j-api.jar to the second POSTagger constructor argument does work for me:

new POSTagger(
    $absolutePostaggerPath . '/models/english-left3words-distsim.tagger',
    $absolutePostaggerPath . '/stanford-postagger.jar:'. $absolutePostaggerPath . '/lib/slf4j-api.jar'
 );

mmnosek avatar Apr 21 '16 19:04 mmnosek

I found a solution for an empty array. If you have this issue try to change line 91 of StanfordTagger.php from: return isset($results[0]) ? $results[0] : array(); to: return isset($results[0]) ? $results : array();

mmnosek avatar Jun 26 '16 12:06 mmnosek

Mnosek : i trying this way but still not work .

back-kh avatar Jun 28 '16 09:06 back-kh

Finally working for me;

Added the following code to test.php

tag(explode(' ', "What does the fox say?")); var_dump($result); ?>

Download the 'Full' zip from here; http://nlp.stanford.edu/software/tagger.shtml#History 3.4.1 2014-08-27 Add Spanish model English / Full <<<<

Place the unzipped 'stanford-postagger-full-2014-08-27' folder in the same folder as the php code(above).

Output: array(6) { [0]=> array(2) { [0]=> string(4) "What" [1]=> string(2) "WP" } [1]=> array(2) { [0]=> string(4) "does" [1]=> string(3) "VBZ" } [2]=> array(2) { [0]=> string(3) "the" [1]=> string(2) "DT" } [3]=> array(2) { [0]=> string(3) "fox" [1]=> string(2) "NN" } [4]=> array(2) { [0]=> string(3) "say" [1]=> string(2) "VB" } [5]=> array(2) { [0]=> string(1) "?" [1]=> string(1) "." } }

users-name avatar Jul 04 '16 01:07 users-name

yes it's work for php but it not possible in laravel??

back-kh avatar Jul 06 '16 03:07 back-kh

Does anyone have a solution for this yet?

Arya314 avatar May 16 '17 17:05 Arya314