Skip to content

Commit fd021ca

Browse files
Dennis de SwartDennis de Swart
authored andcommitted
Update to 5.0.0
1 parent 7c8aa0c commit fd021ca

File tree

13 files changed

+81
-590
lines changed

13 files changed

+81
-590
lines changed

README.md

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,31 @@ PHP adapter for use with Stanford CoreNLP
77
## Features
88
- Connect to Stanford University CoreNLP API online
99
- Connect to Stanford CoreNLP 3.7.0 server
10-
- The package gets the following annotator data: tokenize,ssplit,parse,regexner,pos,depparse,lemma,ner,natlog,openie,mention
10+
- Annotators available: tokenize,ssplit,pos, parse, depparse, ner, regexner,lemma, mention, natlog, coref, openie, kbp
1111
- The package creates Part-Of-Speech Trees with depth, parent- and child ID
1212

1313

14-
## OpenIE (adapter version 4.0.0+, only on the Java version)
15-
16-
OpenIE creates "subject-relation-object" tuples. This is similar (but not the same) as the "Subject-Verb-Object" concept of the English language.
17-
18-
Notes:
19-
- OpenIE is only available on the Java offline version, not with the "online" mode. See the installation walkthrough below
20-
- OpenIE data is not always available. Sometimes the result array might show empty, this is not an error.
21-
22-
```
23-
http://nlp.stanford.edu/software/openie.html
24-
https://en.wikipedia.org/wiki/Subject%E2%80%93verb%E2%80%93object
25-
```
26-
2714
## Requirements
28-
- PHP 5.3 or higher: it also works on PHP 7
15+
- PHP 5.5 or higher: it also works on PHP 7
2916
- Windows or Linux 64-bit, 8Gb memory or more recommended
30-
- Connection to Java server requires cURL.
31-
- Note: Connection to Stanford CoreNLP API online does NOT require cURL.
32-
17+
- Either Guzzle HTTP Client (installed by default) or only cURL.
18+
- Composer for PHP
3319
```
34-
https://en.wikipedia.org/wiki/CURL
20+
https://getcomposer.org/
3521
```
3622

3723

24+
## Installation using ZIP files
25+
26+
- Install Stanford CoreNLP Server. See the installation walkthrough below.
27+
- Download and unpack the files from this package.
28+
- Copy the files to your to your webserver directory. Usually "htdocs" or "var/www".
29+
- Run a Composer update
30+
31+
3832
## Installation using Composer
3933

40-
You can install the adapter by putting the following line into your composer.json and running a composer update
34+
- Insert the following line into the "require" of your "composer.json" file.
4135

4236
```
4337
{
@@ -47,20 +41,32 @@ You can install the adapter by putting the following line into your composer.jso
4741
}
4842
```
4943

44+
- Run a composer update
5045

5146

5247
# Using the Stanford CoreNLP online API service
5348

5449

55-
5650
The adapter by default uses Stanford's online API service. This should work right after the composer update.
5751
Note that the online API is a public service. If you want to analyze large volumes of text or sensitive data,
5852
please install the Java server version.
5953

6054

55+
## OpenIE
6156

62-
# Installation / Walkthrough for Java server version
57+
OpenIE creates "subject-relation-object" tuples. This is similar (but not the same) as the "Subject-Verb-Object" concept of the English language.
58+
59+
Notes:
60+
- OpenIE is only available on the Java offline version, not with the "online" mode. See the installation walkthrough below
61+
- OpenIE data is not always available. Sometimes the result array might show empty, this is not an error.
6362

63+
```
64+
http://nlp.stanford.edu/software/openie.html
65+
https://en.wikipedia.org/wiki/Subject-verb-object
66+
```
67+
68+
69+
# Installation / Walkthrough for Java server version
6470

6571

6672

bootstrap.php

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,36 @@
88

99
/**
1010
* Use the online API?
11+
*
12+
* TRUE : Connect to the Stanford CoreNLP server online
13+
* FALSE: Uses Java version
1114
*/
12-
define('ONLINE_API', TRUE); // Set to FALSE if you want to use the offline Java version
15+
define('ONLINE_API', FALSE); // since Adapter version 5.0.0 FALSE by default.
1316

14-
/**
15-
* Stanford API URL configuration
16-
*/
17-
define('ONLINE_URL' , 'http://nlp.stanford.edu:8080/corenlp/process?outputFormat=json&Process=Submit&input='); // add url encoded text to the end
18-
17+
/**
18+
* Stanford API URL configuration
19+
*/
20+
define('ONLINE_URL' , 'http://nlp.stanford.edu:8080/corenlp/process?outputFormat=json&Process=Submit&input=');
21+
22+
/**
23+
* Guzzle is used to make HTTP calls to the CoreNLP server.
24+
*
25+
* If true: HTTP calls are used (recommended)
26+
* If false: cURL command line is used
27+
*/
28+
define('USE_GUZZLE', TRUE);
29+
1930
/**
2031
* Java version configuration
2132
*/
2233
define('CURLURL' , 'http://localhost:9000/');
23-
define('CURLPROPERTIES' , '%22annotators%22%3A%22tokenize%2Cregexner%2Cparse%2Cpos%2Clemma%2Copenie%2Cner%22%2C%22prettyPrint%22%3A%22true%22');
2434

25-
// Note: coref removed from properties since 4.0.0, because it seems to cause problems starting the server
26-
35+
// used for CoreNLP version 3.7.0
36+
define('CURLPROPERTIES' , '%22prettyPrint%22%3A%22true%22');
37+
38+
// if you want specific annotators, you can do it like this:
39+
// define('CURLPROPERTIES' , '%22annotators%22%3A%22tokenize%2Cregexner%2Cparse%2Cdepparse%2Cpos%2Clemma%2Cmention%2Copenie%2Cner%2Ccoref%2Ckbp%22%2C%22prettyPrint%22%3A%22true%22');
40+
2741
/**
2842
* Start composer autoloader
2943
*/

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
}
1515
],
1616
"require": {
17-
"php": ">=5.3.0"
17+
"php": ">=5.5",
18+
"guzzlehttp/guzzle": "^6.2.0"
1819
},
1920
"autoload": {
2021
"classmap": ["src/"]

src/CoreNLP/CorenlpAdapter.php

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,20 @@ class CorenlpAdapter {
88

99
/**
1010
*
11-
* COMMAND LINE FUNCTIONS
11+
* SERVER OUTPUT FUNCTIONS
1212
*
1313
*/
14-
1514
public $serverRawOutput = ''; // container for serveroutput
1615
public $serverOutput = ''; // container for decoded data
1716
public $serverMemory = ''; // keeps all the output
17+
public $trees = array(); // keeps parsed trees
1818

19+
1920
/**
20-
* function getOnlineOutput:
21+
* function getServerOutputOnline
2122
* - sends request to online CoreNLP API
2223
* - returns JSON reply
2324
*/
24-
25-
2625
public function getServerOutputOnline(string $text){
2726

2827
$doc = new DomDocument();
@@ -41,14 +40,22 @@ public function getServerOutputOnline(string $text){
4140

4241
/**
4342
* function getServerOutput:
44-
* - sends the server command
43+
* - sends a request
4544
* - returns server output
4645
*
4746
* @param string $text
4847
* @return type
4948
*/
5049
public function getServerOutput(string $text){
51-
50+
51+
if(USE_GUZZLE){
52+
$this->getOutputGuzzle($text);
53+
} else {
54+
$this->getOutputCurl($text);
55+
}
56+
}
57+
58+
public function getOutputCurl($text){
5259
// create a shell command
5360
$command = 'curl --data "'.$text.'" "'.CURLURL.'"?properties={"'.CURLPROPERTIES.'"}';
5461

@@ -61,19 +68,24 @@ public function getServerOutput(string $text){
6168
}
6269

6370
// get object with data
64-
$this->serverOutput = json_decode($this->serverRawOutput, true); // note: decodes into an array, not an object
71+
$this->serverOutput = json_decode($this->serverRawOutput, true); // note: decodes into an array, not an object
6572

6673
return;
6774
}
68-
69-
/**
70-
*
71-
* SERVER OUTPUT FUNCTIONS
72-
*
73-
*/
75+
76+
public function getOutputGuzzle($text){
77+
78+
$client = new \GuzzleHttp\Client();
79+
$res = $client->request('POST', CURLURL, [
80+
'body' => $text
81+
]);
7482

75-
// keeps parsed trees
76-
public $trees = array();
83+
$json = $res->getBody();
84+
$this->serverOutput = json_decode($json, true);
85+
86+
return;
87+
}
88+
7789

7890
/**
7991
* function getOutput

vendor/autoload.php

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)