1. Go to this page and download the library: Download aflorea4/php-nlp-client library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
aflorea4 / php-nlp-client example snippets
$nlp = new \Web64\Nlp\NlpClient('http://localhost:6400/');
$detected_lang = $nlp->language( "The quick brown fox jumps over the lazy dog" );
// 'en'
// From URL
$nlp = new \Web64\Nlp\NlpClient('http://localhost:6400/');
$newspaper = $nlp->newspaper('https://github.com/web64/nlpserver');
// or from HTML
$html = file_get_contents( 'https://github.com/web64/nlpserver' );
$newspaper = $nlp->newspaper_html( $html );
Array
(
[article_html] => <div><h1><a id="user-content-nlp-server" class="anchor" href="#nlp-server"></a>NLP Server</h1> .... </div>
[authors] => Array()
[canonical_url] => https://github.com/web64/nlpserver
[meta_data] => Array()
[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.
[meta_lang] => en
[source_url] =>
[text] => NLP Server. Python Flask web service for easy access to multilingual NLP tasks such as language detection, article extraction...
[title] => web64/nlpserver: NLP Web Service
[top_image] => https://avatars2.githubusercontent.com/u/76733?s=400&v=4
)
$polyglot = $nlp->polyglot_entities( $text, 'en' );
$polyglot->getSentiment(); // -1
$polyglot->getEntityTypes();
/*
Array
(
[Locations] => Array
(
[0] => United Kingdom
)
[Organizations] =>
[Persons] => Array
(
[0] => Ben
[1] => Sir Benjamin Hall
[2] => Benjamin Caunt
)
)
*/
$polyglot->getLocations(); // Array of Locations
$polyglot->getOrganizations(); // Array of organisations
$polyglot->getPersons(); // Array of people
$polyglot->getEntities();
/*
Returns flat array of all entities
Array
(
[0] => Ben
[1] => United Kingdom
[2] => Sir Benjamin Hall
[3] => Benjamin Caunt
)
*/
$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.";
$nlp = new \Web64\Nlp\NlpClient('http://localhost:6400/');
$entities = $nlp->spacy_entities( $text );
/*
Array
(
[DATE] => Array
(
[0] => 1905
)
[NORP] => Array
(
[0] => Danish
)
[ORG] => Array
(
[0] => the Skagen Painters
)
[PERSON] => Array
(
[0] => Anna Ancher
)
)
*/
$nlp = new \Web64\Nlp\NlpClient( 'http://localhost:6400/' );
// From URL:
$article = $nlp->readability('https://github.com/web64/nlpserver');
// From HTML:
$html = file_get_contents( 'https://github.com/web64/nlpserver' );
$article = $nlp->readability_html( $html );
/*
Array
(
[article_html] => <div><h1>NLP Server</h1><p>Python 3 Flask web service for easy access to multilingual NLP tasks ...
[short_title] => web64/nlpserver: NLP Web Service
[text] => NLP Server Python 3 Flask web service for easy access to multilingual NLP tasks such as language detection ...
[title] => GitHub - web64/nlpserver: NLP Web Service
)
*/