Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit da2fb54

Browse files
committed
docs and testing
1 parent b2ef1e9 commit da2fb54

File tree

9 files changed

+1642
-105
lines changed

9 files changed

+1642
-105
lines changed

‎README.md

Lines changed: 79 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# PHP NLP-Client
22

3-
This is a simple PHP library for performing Natural Language tasks using Web64's NLP-Server https://github.com/web64/nlpserver.
3+
This is a simple PHP library for performing Natural Language tasks using Web64's NLP-Server https://github.com/web64/nlpserver.
44

55
NLP Tasks Available through Web64's NLP Server:
66
* Language detection
@@ -16,6 +16,9 @@ NLP Tasks Available through Stanford's CoreNLP Server:
1616
NLP Tasks Available through Microsoft Labs API:
1717
* Related concepts
1818

19+
### Laravel Package
20+
There is also a Laravel wrapper for this library available here: https://github.com/web64/laravel-nlp
21+
1922
## Installation
2023
```bash
2124
composer require web64/php-nlp-client
@@ -25,16 +28,16 @@ composer require web64/php-nlp-client
2528
Most NLP features in this package requires a running instance of the NLP-Server, which is a simple python flask app providing web service api access to common python NLP libraries.
2629
Installation documentation: https://github.com/web64/nlpserver
2730

28-
## Entity Extraction - Named Entity Recognition
31+
## Entity Extraction - Named Entity Recognition (NER)
2932
This package provides access to three different methods for entity extraction.
3033

3134
| First Header | Language Support | Programming Lang. | API Access |
3235
| ------------- | ------------- | ------------- | ------------- |
33-
| Polyglot | 40 languages | Python | NLP Server |
34-
| CoreNLP | 6 languages | Java | CoreNLP Standalone server |
35-
| Spacy.io | 7 languages | Python | NLP Server |
36+
| [Polyglot](https://polyglot.readthedocs.io/en/latest/) | 40 languages | Python | NLP Server |
37+
| [CoreNLP](https://stanfordnlp.github.io/CoreNLP/download.html) | 6 languages | Java | CoreNLP Standalone server |
38+
| [Spacy](https://spacy.io/) | 7 languages | Python | NLP Server |
3639

37-
If you are dealing with text in English or one of the major European language you will get the best results with CoreNLP or Spacy.io.
40+
If you are dealing with text in English or one of the major European language you will get the best results with CoreNLP or Spacy.
3841

3942
The quality of extracted entities with Polyglot is not great, but for many languages it is the only available option at the moment.
4043

@@ -76,36 +79,52 @@ Array
7679
)
7780
```
7881

79-
### Entity Extraction & Sentiment Analysis (Polyglot)
82+
83+
### Polyglot Entities & Sentiment Analysis
84+
This uses the Polyglot multilingual NLP library to return entities and a sentiment score for given text.Ensure the models for the required languages are downloaded for Polyglot.
85+
8086
```php
81-
$nlp = new \Web64\Nlp\NlpClient('http://localhost:6400/');
8287
$polyglot = $nlp->polyglot_entities( $text, 'en' );
8388

84-
$entities = $polyglot->getEntities();
85-
$sentiment = $polyglot->getSentiment();
86-
```
89+
$polyglot->getSentiment(); // -1
8790

88-
### Neighbouring words (Embeddings)
89-
```php
90-
$nlp = new \Web64\Nlp\NlpClient('http://localhost:6400/');
91-
$neighbours = $nlp->neighbours('obama', 'en');
91+
$polyglot->getEntityTypes();
9292
/*
9393
Array
9494
(
95-
[0] => Bush
96-
[1] => Reagan
97-
[2] => Clinton
98-
[3] => Ahmadinejad
99-
[4] => Nixon
100-
[5] => Karzai
101-
[6] => McCain
102-
[7] => Biden
103-
[8] => Huckabee
104-
[9] => Lula
95+
[Locations] => Array
96+
(
97+
[0] => United Kingdom
98+
)
99+
[Organizations] =>
100+
[Persons] => Array
101+
(
102+
[0] => Ben
103+
[1] => Sir Benjamin Hall
104+
[2] => Benjamin Caunt
105+
)
106+
)
107+
*/
108+
109+
$polyglot->getLocations(); // Array of Locations
110+
$polyglot->getOrganizations(); // Array of organisations
111+
$polyglot->getPersons(); // Array of people
112+
113+
$polyglot->getEntities();
114+
/*
115+
Returns combined array of all entities
116+
Array
117+
(
118+
[0] => Ben
119+
[1] => United Kingdom
120+
[2] => Sir Benjamin Hall
121+
[3] => Benjamin Caunt
105122
)
106123
*/
107124
```
108125

126+
127+
109128
### Spacy Entities
110129
```php
111130
$text = "Harvesters is a 1905 oil painting on canvas by the Danish artist Anna Ancher, a member of the artists' community known as the Skagen Painters.";
@@ -143,6 +162,26 @@ English is used by default. To use another language ensure Spacy language model
143162
$entities = $nlp->spacy_entities( $spanish_text, 'es' );
144163
```
145164

165+
### Neighbouring words (Embeddings)
166+
```php
167+
$nlp = new \Web64\Nlp\NlpClient('http://localhost:6400/');
168+
$neighbours = $nlp->neighbours('obama', 'en');
169+
/*
170+
Array
171+
(
172+
[0] => Bush
173+
[1] => Reagan
174+
[2] => Clinton
175+
[3] => Ahmadinejad
176+
[4] => Nixon
177+
[5] => Karzai
178+
[6] => McCain
179+
[7] => Biden
180+
[8] => Huckabee
181+
[9] => Lula
182+
)
183+
*/
184+
```
146185

147186
### Summarizer
148187
Extract short summary from a long text
@@ -176,52 +215,6 @@ Array
176215
```
177216

178217

179-
### Polyglot Entities & Sentiment Analysis
180-
This uses the Polyglot multilingual NLP library to return entities and a sentiment score for given text.
181-
Ensure the models for the required languages are downloaded for Polyglot.
182-
183-
```php
184-
$polyglot = $nlp->polyglot_entities( $text );
185-
186-
// Specify language
187-
$polyglot = $nlp->polyglot_entities( $text, 'no' );
188-
189-
$polyglot->getSentiment(); // -1
190-
191-
$polyglot->getEntityTypes();
192-
/*
193-
Array
194-
(
195-
[Locations] => Array
196-
(
197-
[0] => United Kingdom
198-
)
199-
[Organizations] =>
200-
[Persons] => Array
201-
(
202-
[0] => Ben
203-
[1] => Sir Benjamin Hall
204-
[2] => Benjamin Caunt
205-
)
206-
)
207-
*/
208-
209-
$polyglot->getLocations(); // Array of Locations
210-
$polyglot->getOrganizations(); // Array of organisations
211-
$polyglot->getPersons(); // Array of people
212-
213-
$polyglot->getEntities();
214-
/*
215-
Returns combined array of all entities
216-
Array
217-
(
218-
[0] => Ben
219-
[1] => United Kingdom
220-
[2] => Sir Benjamin Hall
221-
[3] => Benjamin Caunt
222-
)
223-
*/
224-
```
225218
### Sentiment Analysis
226219

227220
```php
@@ -240,13 +233,28 @@ CoreNLP har much better quality for NER that Polyglot, but only supports a few l
240233

241234
Download CoreNLP server (Java) here: https://stanfordnlp.github.io/CoreNLP/index.html#download
242235

236+
### Install CoreNLP
237+
```bash
238+
# Update download links with latest versions from the download page
239+
240+
wget http://nlp.stanford.edu/software/stanford-corenlp-full-2018年10月05日.zip
241+
unzip stanford-corenlp-full-2018年10月05日.zip
242+
cd stanford-corenlp-full-2018年02月27日
243+
244+
# Download English language model :
245+
wget http://nlp.stanford.edu/software/stanford-english-kbp-corenlp-2018年10月05日-models.jar
246+
```
247+
248+
### Running CoreNLP server
243249
```bash
244250
# Run the server using all jars in the current directory (e.g., the CoreNLP home directory)
245251
java -mx4g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer -port 9000 -timeout 15000
246252

247253
# To run server in as a background process
248254
nohup java -mx4g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer -port 9000 -timeout 15000 &
249255
```
256+
When the CoreNLP server is running you can access it on port 9000: http://localhost:9000/
257+
250258
More info about running the CoreNLP Server: https://stanfordnlp.github.io/CoreNLP/corenlp-server.html
251259

252260
```php
@@ -280,7 +288,6 @@ Array
280288
```
281289

282290
## Concept Graph
283-
WARNING: At the time of writing SSL certificate for concept.research.microsoft.com has expired and service might not work until they get that fixed.
284291
Microsoft Concept Graph For Short Text Understanding: https://concept.research.microsoft.com/
285292

286293
Find related concepts to provided keyword

‎composer.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,8 @@
2323
},
2424
"files":["tests/utilities/functions.php"]
2525
},
26-
"minimum-stability": "stable"
27-
}
26+
"minimum-stability": "stable",
27+
"require-dev": {
28+
"phpunit/phpunit": "7"
29+
}
30+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /