dennisdeswart / php-stanford-corenlp-adapter Goto Github PK
View Code? Open in Web Editor NEWPHP adapter for Stanford CoreNLP
PHP adapter for Stanford CoreNLP
FYI, if you are using Guzzle, then the code needs to be changed to this if you want to add specific annotators:
define('CURLPROPERTIES' , '"annotators":"ner","prettyPrint":"true"');
$client = new \GuzzleHttp\Client();
$res = $client->request('POST', CURLURL.'?properties={'.CURLPROPERTIES.'}', [
'body' => $text
]);
Hello i'm working on coreNLP adapter and i'm facing a problem with the function getTreeWithTokens where $parse = $sentence['parse'];
is giving me Unidentified index.
I've made a var_dump
on $sentence with the text " What fox say Hi bob how you " to see whats the problem i got these:
array(7) { ["index"]=> int(0) ["basicDependencies"]=> array(7) { [0]=> array(5) { ["dep"]=> string(4) "ROOT" ["governor"]=> int(0) ["governorGloss"]=> string(4) "ROOT" ["dependent"]=> int(3) ["dependentGloss"]=> string(3) "say" } [1]=> array(5) { ["dep"]=> string(3) "det" ["governor"]=> int(2) ["governorGloss"]=> string(3) "fox" ["dependent"]=> int(1) ["dependentGloss"]=> string(4) "What" } [2]=> array(5) { ["dep"]=> string(5) "nsubj" ["governor"]=> int(3) ["governorGloss"]=> string(3) "say" ["dependent"]=> int(2) ["dependentGloss"]=> string(3) "fox" } [3]=> array(5) { ["dep"]=> string(9) "discourse" ["governor"]=> int(5) ["governorGloss"]=> string(3) "bob" ["dependent"]=> int(4) ["dependentGloss"]=> string(2) "Hi" } [4]=> array(5) { ["dep"]=> string(5) "ccomp" ["governor"]=> int(3) ["governorGloss"]=> string(3) "say" ["dependent"]=> int(5) ["dependentGloss"]=> string(3) "bob" } [5]=> array(5) { ["dep"]=> string(6) "advmod" ["governor"]=> int(7) ["governorGloss"]=> string(3) "you" ["dependent"]=> int(6) ["dependentGloss"]=> string(3) "how" } [6]=> array(5) { ["dep"]=> string(3) "dep" ["governor"]=> int(5) ["governorGloss"]=> string(3) "bob" ["dependent"]=> int(7) ["dependentGloss"]=> string(3) "you" } } ["enhancedDependencies"]=> array(7) { [0]=> array(5) { ["dep"]=> string(4) "ROOT" ["governor"]=> int(0) ["governorGloss"]=> string(4) "ROOT" ["dependent"]=> int(3) ["dependentGloss"]=> string(3) "say" } [1]=> array(5) { ["dep"]=> string(3) "det" ["governor"]=> int(2) ["governorGloss"]=> string(3) "fox" ["dependent"]=> int(1) ["dependentGloss"]=> string(4) "What" } [2]=> array(5) { ["dep"]=> string(5) "nsubj" ["governor"]=> int(3) ["governorGloss"]=> string(3) "say" ["dependent"]=> int(2) ["dependentGloss"]=> string(3) "fox" } [3]=> array(5) { ["dep"]=> string(9) "discourse" ["governor"]=> int(5) ["governorGloss"]=> string(3) "bob" ["dependent"]=> int(4) ["dependentGloss"]=> string(2) "Hi" } [4]=> array(5) { ["dep"]=> string(5) "ccomp" ["governor"]=> int(3) ["governorGloss"]=> string(3) "say" ["dependent"]=> int(5) ["dependentGloss"]=> string(3) "bob" } [5]=> array(5) { ["dep"]=> string(6) "advmod" ["governor"]=> int(7) ["governorGloss"]=> string(3) "you" ["dependent"]=> int(6) ["dependentGloss"]=> string(3) "how" } [6]=> array(5) { ["dep"]=> string(3) "dep" ["governor"]=> int(5) ["governorGloss"]=> string(3) "bob" ["dependent"]=> int(7) ["dependentGloss"]=> string(3) "you" } } ["enhancedPlusPlusDependencies"]=> array(7) { [0]=> array(5) { ["dep"]=> string(4) "ROOT" ["governor"]=> int(0) ["governorGloss"]=> string(4) "ROOT" ["dependent"]=> int(3) ["dependentGloss"]=> string(3) "say" } [1]=> array(5) { ["dep"]=> string(3) "det" ["governor"]=> int(2) ["governorGloss"]=> string(3) "fox" ["dependent"]=> int(1) ["dependentGloss"]=> string(4) "What" } [2]=> array(5) { ["dep"]=> string(5) "nsubj" ["governor"]=> int(3) ["governorGloss"]=> string(3) "say" ["dependent"]=> int(2) ["dependentGloss"]=> string(3) "fox" } [3]=> array(5) { ["dep"]=> string(9) "discourse" ["governor"]=> int(5) ["governorGloss"]=> string(3) "bob" ["dependent"]=> int(4) ["dependentGloss"]=> string(2) "Hi" } [4]=> array(5) { ["dep"]=> string(5) "ccomp" ["governor"]=> int(3) ["governorGloss"]=> string(3) "say" ["dependent"]=> int(5) ["dependentGloss"]=> string(3) "bob" } [5]=> array(5) { ["dep"]=> string(6) "advmod" ["governor"]=> int(7) ["governorGloss"]=> string(3) "you" ["dependent"]=> int(6) ["dependentGloss"]=> string(3) "how" } [6]=> array(5) { ["dep"]=> string(3) "dep" ["governor"]=> int(5) ["governorGloss"]=> string(3) "bob" ["dependent"]=> int(7) ["dependentGloss"]=> string(3) "you" } } ["kbp"]=> array(0) { } ["entitymentions"]=> array(0) { } ["tokens"]=> array(7) { [0]=> array(11) { ["index"]=> int(1) ["word"]=> string(4) "What" ["originalText"]=> string(4) "What" ["lemma"]=> string(4) "what" ["characterOffsetBegin"]=> int(0) ["characterOffsetEnd"]=> int(4) ["pos"]=> string(3) "WDT" ["ner"]=> string(1) "O" ["speaker"]=> string(4) "PER0" ["before"]=> string(0) "" ["after"]=> string(1) " " } [1]=> array(11) { ["index"]=> int(2) ["word"]=> string(3) "fox" ["originalText"]=> string(3) "fox" ["lemma"]=> string(3) "fox" ["characterOffsetBegin"]=> int(5) ["characterOffsetEnd"]=> int(8) ["pos"]=> string(2) "NN" ["ner"]=> string(1) "O" ["speaker"]=> string(4) "PER0" ["before"]=> string(1) " " ["after"]=> string(1) " " } [2]=> array(11) { ["index"]=> int(3) ["word"]=> string(3) "say" ["originalText"]=> string(3) "say" ["lemma"]=> string(3) "say" ["characterOffsetBegin"]=> int(9) ["characterOffsetEnd"]=> int(12) ["pos"]=> string(3) "VBP" ["ner"]=> string(1) "O" ["speaker"]=> string(4) "PER0" ["before"]=> string(1) " " ["after"]=> string(5) " " } [3]=> array(11) { ["index"]=> int(4) ["word"]=> string(2) "Hi" ["originalText"]=> string(2) "Hi" ["lemma"]=> string(2) "hi" ["characterOffsetBegin"]=> int(17) ["characterOffsetEnd"]=> int(19) ["pos"]=> string(2) "UH" ["ner"]=> string(1) "O" ["speaker"]=> string(4) "PER0" ["before"]=> string(5) " " ["after"]=> string(1) " " } [4]=> array(11) { ["index"]=> int(5) ["word"]=> string(3) "bob" ["originalText"]=> string(3) "bob" ["lemma"]=> string(3) "bob" ["characterOffsetBegin"]=> int(20) ["characterOffsetEnd"]=> int(23) ["pos"]=> string(2) "NN" ["ner"]=> string(1) "O" ["speaker"]=> string(4) "PER0" ["before"]=> string(1) " " ["after"]=> string(2) " " } [5]=> array(11) { ["index"]=> int(6) ["word"]=> string(3) "how" ["originalText"]=> string(3) "how" ["lemma"]=> string(3) "how" ["characterOffsetBegin"]=> int(25) ["characterOffsetEnd"]=> int(28) ["pos"]=> string(3) "WRB" ["ner"]=> string(1) "O" ["speaker"]=> string(4) "PER0" ["before"]=> string(2) " " ["after"]=> string(1) " " } [6]=> array(11) { ["index"]=> int(7) ["word"]=> string(3) "you" ["originalText"]=> string(3) "you" ["lemma"]=> string(3) "you" ["characterOffsetBegin"]=> int(29) ["characterOffsetEnd"]=> int(32) ["pos"]=> string(3) "PRP" ["ner"]=> string(1) "O" ["speaker"]=> string(4) "PER0" ["before"]=> string(1) " " ["after"]=> string(1) " " } } }
the problem is that there's no ["parse"] section in the sentence in there a way to fix it?
Hey there, great job this adapter!
for a first round, I'd like to simply use those parameters for OpenNLP:
-annotators tokenize,ssplit
How is it possible to make this happen via the CorenlpAdapter?
Online Url given in corenlp adapter is not showing the output as version .What is new online url for new release version of corenlp.
hello Mr. Swart,
I am using functional OpenIE for English from your adapter, but when I enter a long English article, the following error occurred:
Fatal error: Uncaught GuzzleHttp\Exception\ServerException: Server error:
POST http://localhost:9000/` resulted in a 500 Internal Server Error
response: CoreNLP request timed out. Your document may be too long. in D:\Apache24\htdocs\stanford1\vendor\guzzlehttp\guzzle\src\Exception\RequestException.php:113 Stack trace: #0 D:\Apache24\htdocs\stanford1\vendor\guzzlehttp\guzzle\src\Middleware.php(65): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Psr7\Request), Object(GuzzleHttp\Psr7\Response)) #1 D:\Apache24\htdocs\stanford1\vendor\guzzlehttp\promises\src\Promise.php(203): GuzzleHttp\Middleware::GuzzleHttp{closure}(Object(GuzzleHttp\Psr7\Response)) #2 D:\Apache24\htdocs\stanford1\vendor\guzzlehttp\promises\src\Promise.php(156): GuzzleHttp\Promise\Promise::callHandler(1, Object(GuzzleHttp\Psr7\Response), Array) #3 D:\Apache24\htdocs\stanford1\vendor\guzzlehttp\promises\src\TaskQueue.php(47): GuzzleHttp\Promise\Promise::GuzzleHttp\Promise{closure}() #4 D:\Apache24\htdocs\stanford1\vendor\guzzlehttp\prom in D:\Apache24\htdocs\stanford1\vendor\guzzlehttp\guzzle\src\Exception\RequestException.php on line 113`
so i have re-set the java server response time, like this:
java -mx8g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer -port 9000 -timeout 15000
the following error occurred:
Fatal error: Uncaught RuntimeException: Error creating resource: [message] fopen(http://localhost:9000/): failed to open stream: HTTP request failed! [file] D:\Apache24\htdocs\stanford1\vendor\guzzlehttp\guzzle\src\Handler\StreamHandler.php [line] 324 in D:\Apache24\htdocs\stanford1\vendor\guzzlehttp\guzzle\src\Handler\StreamHandler.php:252 Stack trace: #0 D:\Apache24\htdocs\stanford1\vendor\guzzlehttp\guzzle\src\Handler\StreamHandler.php(335): GuzzleHttp\Handler\StreamHandler->createResource(Object(Closure)) #1 D:\Apache24\htdocs\stanford1\vendor\guzzlehttp\guzzle\src\Handler\StreamHandler.php(52): GuzzleHttp\Handler\StreamHandler->createStream(Object(GuzzleHttp\Psr7\Request), Array) #2 D:\Apache24\htdocs\stanford1\vendor\guzzlehttp\guzzle\src\PrepareBodyMiddleware.php(66): GuzzleHttp\Handler\StreamHandler->__invoke(Object(GuzzleHttp\Psr7\Request), Array) #3 D:\Apache24\htdocs\stanford1\vendor\guzzlehttp\guzzle\src\Middleware.php(30): GuzzleHttp\PrepareBodyMiddleware->__invoke(Object(GuzzleHttp\Psr7\Request), Array) # in D:\Apache24\htdocs\stanford1\vendor\guzzlehttp\guzzle\src\Exception\RequestException.php on line 52
**how can i solve this problem?
Thank you and best regards**
Yao
Hello Mr. Swart
there ist a problem, wenn i enter "composer update",
Root package 'dennis-de-swart/php-stanford-corenlp-adapter' cannot require itself in its composer.json
Did you accidentally name your root package after an external package?
How can i Solve this problem.
thank you very much
yao
I am running
$coreNLP = new CorenlpAdapter();
$text1 = 'I will meet Mary in New York at 10pm';
$ouput = $coreNLP->getOutput($text1);
Uncaught Error: [] operator not supported for strings in /stanford/vendor/dennis-de-swart/php-stanford-corenlp-adapter/src/CoreNLP/CorenlpAdapter.php:106 Stack trace: #0 /home/solvecastmz/public_html/stanford/example.php(18): CorenlpAdapter->getOutput('I will meet Mar...') #1 {main} thrown in /home/solvecastmz/public_html/stanford/vendor/dennis-de-swart/php-stanford-corenlp-adapter/src/CoreNLP/CorenlpAdapter.php on line 106
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.