agentile / PHP-Stanford-NLP

PHP interface to Stanford NLP tools (POS Tagger, NER, Parser)
168 stars 51 forks source link

Empty Array #7

Open gupul2k opened 9 years ago

gupul2k commented 9 years ago

Here is the code and coming empty array.

<?php

require './PHP-Stanford-NLP-master/src/StanfordNLP/Base.php'; require './PHP-Stanford-NLP-master/src/StanfordNLP/Exception.php'; require './PHP-Stanford-NLP-master/src/StanfordNLP/Parser.php'; require './PHP-Stanford-NLP-master/src/StanfordNLP/StanfordTagger.php'; require './PHP-Stanford-NLP-master/src/StanfordNLP/NERTagger.php';

$pos = new \StanfordNLP\NERTagger('/Users/xxxx/Downloads/stanford-ner-2014-10-26/classifiers/english.all.3class.distsim.crf.ser.gz','/Users/xxxx/Downloads/stanford-ner-2014-10-26/stanford-ner.jar'); $result = $pos->tag(explode(' ', "The Federal Reserve Bank of New York led by Timothy R. Geithner.")); var_dump($result);

?>

O/P

array(0) { }

gupul2k commented 9 years ago

Solved. After upgrading JDK to build 1.8.0_25.

Hypoaristerolactotherapist commented 9 years ago

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
(
)
Hypoaristerolactotherapist commented 9 years ago

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);
?>
0ashu0 commented 9 years ago

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

schuettla commented 9 years ago

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

franciskim commented 9 years ago

Same issues too on Mac OS X.

sajidsheik commented 9 years ago

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

sajidsheik commented 9 years ago

not working when i add DIR. to the path

dennyshess commented 9 years ago

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

Any solutions?

Wmichaelsen commented 8 years ago

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

Anyone solved it yet?

NameIvan commented 8 years ago

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

Wmichaelsen commented 8 years ago

@NameIvan where can I find the previous versions?

NameIvan commented 8 years ago

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

Wmichaelsen commented 8 years ago

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

NameIvan commented 8 years ago

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

Wmichaelsen commented 8 years ago

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

Wmichaelsen commented 8 years ago

@NameIvan

mmnosek commented 8 years ago

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 commented 8 years ago

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();

back-kh commented 8 years ago

Mnosek : i trying this way but still not work .

users-name commented 8 years ago

Finally working for me;

Added the following code to test.php <?php error_reporting('E_ALL'); require_once 'autoload.php'; $pos = new \StanfordNLP\POSTagger( DIR.'\stanford-postagger-full-2014-08-27\models\english-left3words-distsim.tagger', DIR.'\stanford-postagger-full-2014-08-27\stanford-postagger.jar' ); $result = $pos->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) "." } }

back-kh commented 8 years ago

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

Arya314 commented 7 years ago

Does anyone have a solution for this yet?