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 9503adb

Browse files
committed
readme
1 parent 3df3e79 commit 9503adb

File tree

5 files changed

+75
-12
lines changed

5 files changed

+75
-12
lines changed

‎README.md

Lines changed: 63 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,7 @@ NLP Tasks Available through Microsoft Labs API:
2020
```bash
2121
composer require web64/php-nlp-client
2222
```
23-
### Core NLP (Java)
2423

25-
Download CoreNLP server here: https://stanfordnlp.github.io/CoreNLP/index.html#download
26-
27-
```bash
28-
# Run the server using all jars in the current directory (e.g., the CoreNLP home directory)
29-
java -mx4g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer -port 9000 -timeout 15000
30-
```
31-
More info about running the CoreNLP Server: https://stanfordnlp.github.io/CoreNLP/corenlp-server.html
3224
## Usage
3325

3426
### Language detection:
@@ -213,4 +205,67 @@ Array
213205
*/
214206
```
215207

208+
## CoreNLP - Entity Extraction (NER)
209+
CoreNLP har much better quality for NER that Polyglot, but only supports a few languages including English, French, German and Spanish.
210+
211+
Download CoreNLP server (Java) here: https://stanfordnlp.github.io/CoreNLP/index.html#download
212+
213+
```bash
214+
# Run the server using all jars in the current directory (e.g., the CoreNLP home directory)
215+
java -mx4g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer -port 9000 -timeout 15000
216+
```
217+
More info about running the CoreNLP Server: https://stanfordnlp.github.io/CoreNLP/corenlp-server.html
218+
219+
```php
220+
$corenlp = new \Web64\Nlp\CoreNlp('http://localhost:9000/');
221+
$entities = $corenlp->entities( $text );
222+
/*
223+
Array
224+
(
225+
[NATIONALITY] => Array
226+
(
227+
[0] => German
228+
[1] => Turkish
229+
)
230+
[ORGANIZATION] => Array
231+
(
232+
[0] => Foreign Ministry
233+
)
234+
[TITLE] => Array
235+
(
236+
[0] => reporter
237+
[1] => journalist
238+
[2] => correspondent
239+
)
240+
[COUNTRY] => Array
241+
(
242+
[0] => Turkey
243+
[1] => Germany
244+
)
245+
*/
246+
247+
```
248+
249+
## Concept Graph
250+
Microsoft Concept Graph For Short Text Understanding: https://concept.research.microsoft.com/
216251

252+
Find related concepts to provided keyword
253+
```php
254+
$concept = new \Web64\Nlp\MsConceptGraph;
255+
$res = $concept->get('php');
256+
/*
257+
Array
258+
(
259+
[language] => 0.40301612064483
260+
[technology] => 0.19656786271451
261+
[programming language] => 0.14456578263131
262+
[open source technology] => 0.057202288091524
263+
[scripting language] => 0.049921996879875
264+
[server side language] => 0.044201768070723
265+
[web technology] => 0.031201248049922
266+
[server-side language] => 0.027561102444098
267+
[server side scripting language] => 0.023920956838274
268+
[feature] => 0.021840873634945
269+
)
270+
*/
271+
```

‎src/CoreNlp.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class CoreNlp
1616

1717
public $properties = [];
1818
public $data;
19+
public $debug = false;
1920

2021
function __construct( $hosts, $debug = false )
2122
{
@@ -33,6 +34,14 @@ function __construct( $hosts, $debug = false )
3334
$this->api_url = $this->api_hosts[ array_rand( $this->api_hosts ) ];
3435
}
3536

37+
public function addHost( $host )
38+
{
39+
$host = rtrim( $host , '/');
40+
41+
if ( array_search($host, $this->api_hosts) === false)
42+
$this->api_hosts[] = $host;
43+
}
44+
3645
public function entities( $text )
3746
{
3847
$this->properties = [

‎src/NlpClient.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,6 @@ public function get_call($path, $params, $retry = 0)
204204
/**
205205
* Internals
206206
*/
207-
208207
public function addHost( $host )
209208
{
210209
$host = rtrim( $host , '/');

‎tests/Unit/ConceptTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public function get_concepts_for_words()
1111
{
1212
$concept = new \Web64\Nlp\MsConceptGraph;
1313
$res = $concept->get('php');
14-
14+
$this->msg( $res );
1515
$this->assertNotEmpty( $res );
1616

1717
$this->assertEquals( 'language', key($res) );

‎tests/Unit/CoreNlpTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class CoreNlpTest extends TestCase
1212
/** @test */
1313
public function test_core_nlp()
1414
{
15-
$corenlp = new \Web64\Nlp\CoreNlp('http://localhost:9000/');
15+
$corenlp = new \Web64\Nlp\CoreNlp('http://homestead:9000/');
1616

1717
//echo PHP_EOL. PHP_EOL;
1818
$text = "Catalonia: Ex-police chief Trapero charged with sedition. The former chief of Catalonia's police force, Josep Lluis Trapero, has been charged over events linked with last year's independence referendum.";
@@ -30,7 +30,7 @@ public function test_core_nlp()
3030
";
3131
//echo $text . PHP_EOL. PHP_EOL;
3232
$entities = $corenlp->entities( $text );
33-
print_r( $entities );
33+
$this->msg( $entities );
3434

3535

3636
$this->assertNotEmpty( $entities['COUNTRY'] );

0 commit comments

Comments
(0)

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