|
1 | 1 | # PHP NLP-Client
|
2 | 2 |
|
3 | | -This is a simple PHP library for performing Natural Language tasks using the Web64 NLP-Server [https://github.com/web64/nlpserver] |
| 3 | +This is a simple PHP library for performing Natural Language tasks using the Web64 NLP-Server https://github.com/web64/nlpserver |
4 | 4 |
|
5 | | -NLP Tasks Available: |
| 5 | +NLP Tasks Available through Web64's NLP Server: |
6 | 6 | * Language detection
|
| 7 | +* Entity Extraction (NER) - Multilingual |
| 8 | +* Sentiment Analysis - Multilingual |
| 9 | +* Embeddings / Neighbouring words - Multilingual |
| 10 | +* Article Extraction from HTML or URL |
| 11 | +* Summarization |
| 12 | + |
| 13 | +NLP Tasks Available through Stanford's CoreNLP Server: |
7 | 14 | * Entity Extraction (NER)
|
8 | | -* Sentiment Analysis |
9 | | -* Embeddings / Neighbouring words |
10 | | -* Article Extraction from HTML |
11 | 15 |
|
12 | | - |
| 16 | +NLP Tasks Available through Microsoft Labs API: |
| 17 | +* Related concepts |
| 18 | + |
| 19 | +## Installation |
| 20 | +```bash |
| 21 | +composer require web64/php-nlp-client |
| 22 | +``` |
| 23 | + |
| 24 | + |
| 25 | +## Usage |
| 26 | + |
| 27 | +### Language detection: |
| 28 | +```php |
| 29 | +$nlp = new \Web64\Nlp\NlpClient('http://localhost:6400/'); |
| 30 | +$detected_lang = $nlp->language( "The quick brown fox jumps over the lazy dog" ); |
| 31 | +// 'en' |
| 32 | +``` |
| 33 | + |
| 34 | +### Article Extraction |
| 35 | + |
| 36 | +```php |
| 37 | +// From URL |
| 38 | +$nlp = new \Web64\Nlp\NlpClient('http://localhost:6400/'); |
| 39 | +$newspaper = $nlp->newspaperUrl('https://github.com/web64/nlpserver'); |
| 40 | + |
| 41 | +// or from HTML |
| 42 | +$html = file_get_contents( 'https://github.com/web64/nlpserver' ); |
| 43 | +$newspaper = $nlp->newspaperHtml( $html ); |
| 44 | + |
| 45 | +Array |
| 46 | +( |
| 47 | + [article_html] => <div><h1><a id="user-content-nlp-server" class="anchor" href="#nlp-server"></a>NLP Server</h1> .... </div> |
| 48 | + [authors] => Array() |
| 49 | + [canonical_url] => https://github.com/web64/nlpserver |
| 50 | + [meta_data] => Array() |
| 51 | + [meta_description] => GitHub is where people build software. More than 27 million people use GitHub to discover, fork, and contribute to over 80 million projects. |
| 52 | + [meta_lang] => en |
| 53 | + [source_url] => :// |
| 54 | + [text] => NLP Server. Python Flask web service for easy access to multilingual NLP tasks such as language detection, article extraction... |
| 55 | + [title] => web64/nlpserver: NLP Web Service |
| 56 | + [top_image] => https://avatars2.githubusercontent.com/u/76733?s=400&v=4 |
| 57 | +) |
| 58 | +``` |
| 59 | + |
| 60 | +### Entity Extraction & Sentiment Analysis |
| 61 | +```php |
| 62 | +$nlp = new \Web64\Nlp\NlpClient('http://localhost:6400/'); |
| 63 | +$polyglot = $nlp->polyglot( $text, 'en' ); |
| 64 | + |
| 65 | +$entities = $polyglot->getEntities(); |
| 66 | +$sentiment = $polyglot->getSentiment(); |
| 67 | +``` |
| 68 | + |
| 69 | +### Embeddings - Neighbouring words |
| 70 | +```php |
| 71 | +$nlp = new \Web64\Nlp\NlpClient('http://localhost:6400/'); |
| 72 | +$neighbours = $nlp->embeddings('obama', 'en'); |
| 73 | +/* |
| 74 | +Array |
| 75 | +( |
| 76 | + [0] => Bush |
| 77 | + [1] => Reagan |
| 78 | + [2] => Clinton |
| 79 | + [3] => Ahmadinejad |
| 80 | + [4] => Nixon |
| 81 | + [5] => Karzai |
| 82 | + [6] => McCain |
| 83 | + [7] => Biden |
| 84 | + [8] => Huckabee |
| 85 | + [9] => Lula |
| 86 | +) |
| 87 | +*/ |
| 88 | +``` |
| 89 | + |
| 90 | + |
0 commit comments